0
votes

I am trying to figure out why my black and white image, with values from 0-1.0 won't be scaled correctly by an image(my_img) call.

I have tried the following:

  • Setting colormap([0:0.0039:1; 0:0.0039:1; 0:0.0039:1]')
  • Setting clim for the gca to [0 1]
  • Setting DataAspectRatio to [1 1 1]
  • Changing ClimMode and DataAspectRatioMode to manual

What am I doing wrong? Matlab documentation states that images can be from [0 1.0]... Why won't image() display it correctly?

Imshow works great BUT I am trying to achieve the same image as imshow for my own personal reasons using the image function.

Constantin

2

2 Answers

1
votes
h=image(rand(250, 250));
set(h, 'CDataMapping', 'scaled');

imagesc() does this automatically, and in fact it was the source code of imagesc that gave me the correct property name to use.

0
votes

From the image documentation (see the table under the heading "Tips") you can either call image with an array of RGB values or an indexed colourmap, the later seems to be what you are doing. From this same table it states that an indexed colourmap:

is stored as a two-dimensional (m-by-n) array of integers in the range [1, length(colormap)]; colormap is an m-by-3 array of floating-point values in the range [0, 1].

The key point here is that the values in your image array, my_img, should be in the range 1 to 256 (I have guessed this from the line "Setting colormap([0:0.0039:1; 0:0.0039:1; 0:0.0039:1]'", you may need to change this). However, you have values in the range 0 to 1, which are all being mapped to the first colour in you colourmap, which I presume is (0, 0, 0) or black.