Grayscale to Jet image

17 visualizzazioni (ultimi 30 giorni)
Rahul Thakur
Rahul Thakur il 18 Set 2017
Commentato: Walter Roberson il 19 Set 2017
I wrote a simple program where I stacked and put 1024 images in a matrix variable. Now, after some signal processing(hilbert transform) done on them when I am seeing those images, they are shown in grayscale. I need to convert those images to jet colormap to see some different perspective.
What I tried:
  1. I went to Edit>Colormap but there I see only one option of RGB which is already selected.
  2. Looked through MATLAB forums and found rgbImage = ind2rgb(grayImage, jet(256)); but when I tried implementing this in my code to show "bz" it gives me error like this:
??? Subscript indices must either be real positive integers or logicals.
Error in ==> ind2rgb at 27
r = zeros(size(a)); r(:) = cm(a,1);
Please help and let me know what can I do to show the image in some different colors like blue and other or preferably JET. I am using MATLAB 2010. Thanks in advance,
Cheers!
  1 Commento
Walter Roberson
Walter Roberson il 18 Set 2017
Is grayimage in the range 0 to 1 or is it double precision used to store integers 0, 1, etc., or is it double precision used to store integers 1, 2, etc. with 0 not being possible? Or is it uint8() data?

Accedi per commentare.

Risposte (2)

Cam Salzberger
Cam Salzberger il 18 Set 2017
Modificato: Cam Salzberger il 18 Set 2017
Hello Rahul,
The reason "ind2rgb" probably failed is that it's likely a double image. That means that all the values are between 0 and 1, rather than being the necessary integer values as an indexed image would be. You could possibly use "ind2rgb" after first doing im2uint8, if you wanted to go that route.
However, this situation is kind of what imagesc is for, at least in terms of displaying it. If you call imagesc on the image, then set the colormap of the figure to jet, you may get the view you're looking for.
If you're looking to write it out to another image file, you might try my first suggestion.
-Cam
EDIT:
Walter makes a good point. You'd probably want to do im2uint8(I)+1 to put it in the range of [1 256], rather than [0 255], to allow for indexing.
  1 Commento
Walter Roberson
Walter Roberson il 18 Set 2017
ind2rgb knows about data types to know whether to add 1 automatically

Accedi per commentare.


Rahul Thakur
Rahul Thakur il 18 Set 2017
Thanks Cam and Walter.
@Cam: It worked, first turning it into uint8 and I also realized that it also worked with imshow as well just by going into Edit>Standard colormaps and changing it from there. The option suddenly came enabled.
Anyway, another thing while using uint8, it gave me a warning: Complex values are ignored. So, what's the best way nt to ignore, as my data has complex values as well and moreover, which command to use directly rather than going into Tab commands everytime I need to change the colormap.
:) :)
  1 Commento
Walter Roberson
Walter Roberson il 19 Set 2017
colormap() to change color maps.
How were you thinking that you would like to convey the complex component as color information?

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by