hello, I have attach my image. I want to use imshow. However, it shows as white and nothing appears when I use imshow. I want to see a coloured image. This array is the output of a pixel-based classification. Please advise.
EDIT: I added output example pic that I am looking to get. It will not be the same exact pic but should have the same color scheme and look similar.
thanks Aud

 Réponse acceptée

jonas
jonas le 25 Oct 2018
Modifié(e) : jonas le 25 Oct 2018
It's not imshow but you could use imagesc instead
imagesc(out_map)
If you really want to use imshow, then
B = mat2gray(out_map)
imshow(B)
in which case you have to apply a colormap, because your matrix is not an RGB image.

7 commentaires

madhan ravi
madhan ravi le 25 Oct 2018
+1 learning a lot about image processing from you :)
audley james
audley james le 25 Oct 2018
how to apply colormap after this:
B = mat2gray(out_map) imshow(B)
jonas
jonas le 25 Oct 2018
Modifié(e) : jonas le 25 Oct 2018
@madhan, thanks :)
@audlay,
To change colormap
colormap(jet(10))
'jet' is the name of a colormap and the number is the number of segments.
The image youve uploaded appear to be segmented by something other than color?
audley james
audley james le 25 Oct 2018
Modifié(e) : audley james le 25 Oct 2018
@jonas my array (uploaded) has numbers (integers) where each number is a class(category). I simply want to assign a color for each number (i.e., each pixel). I am looking for a solution to colourize the image where it is invariant to the number of classes i may have for other images (i.e., a global solution to this problem). -thanks
Guillaume
Guillaume le 25 Oct 2018
Modifié(e) : Guillaume le 25 Oct 2018
You don't have to apply a colour map or use mat2gray to see the image with imshow if all you want to see the raw grayscale image:
imshow(out_map, [])
The [] tells imshow to map the minimum and maximum intensity in the image to black and white respectively, instead of using the default range of [0 1] = [black white]
You can of course apply a colour map after that:
colormap(parula)
With regards to colour maps, I would avoid jet or similar rainbow maps. A search for 'rainbow color map harmful' in your favorite search engine will find lots of sites explaining why including this paper by Mathworks
You can also create your own colourmap with defined colours or just random as
cmap = rand( 10, 3 )
if you have 10 classes and provided the caxis scaling is appropriate to map 1 per class.
Obviously if choosing your own 10 colours you would just put them into a 10 by 3 array like the one randomly created, e.g.
cmap = [1 0 0; 0 1 0; 0 0 1; 1 0 1;...];
where you put all your colours in instead of the ... of course.
jonas
jonas le 25 Oct 2018
Modifié(e) : jonas le 25 Oct 2018
I agree with guilliame that 'jet' is a poor colormap for visualizing intensity and completely useless if you print in grayscale. If the purpose is to show a number of distinct regions in different colors, then it is quite OK because it covers a wide range of colors (still useless in grayscale though).
Just set the number of segments to the number of unique values and pick another colormap. Personally I like the magma and inferno colormaps but they are not part of the default ones.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by