1

I have an indexed image in matlab that I want to write it out as a 32 bit RGB or grayscale so that if I open it in Photoshop and color pick the values in Photoshop I get the exact values of the indexed image in Matlab.

I was not able to get a 32 bit image from ind2rgb.

Any way to do this?

Yasin
  • 609
  • 1
  • 10
  • 22
  • Have you already looked at `RGB = ind2rgb(X,map)`? If this solves your question you will probably want to remove it. If you already looked at this and it is insufficient you should mention this in the question. -- Just to help: I actually found this by googling for: matlab indexed image to rgb – Dennis Jaheruddin Aug 07 '15 at 16:21
  • Edited the post. I couldn't find a way to have it output a 32 bit image that its values could have a 1:1 match with the indexed image. – Yasin Aug 07 '15 at 16:26
  • 1
    What actual file format are you trying to write it in (extension)? Do you get anything readable at all in Photoshop? Or just junk? Or close values but wrong? Are you attaching an RGB colour profile? – Mark Setchell Aug 07 '15 at 16:37
  • I'm writing it to tif via `imwrite(ind2rgb(IND, gray), 'image.tif', 'tif')` It's readible but comes in as an 8bit image. – Yasin Aug 07 '15 at 17:02
  • 32 bit sounds more like RGBA? Standard RGB is 24 bit. – A. Donda Aug 07 '15 at 17:57
  • Well, 24 bit should do the trick for me too. Any idea how to get such output? – Yasin Aug 07 '15 at 17:59
  • 2
    If I use your command three comments above, using `IND = randi(256, 200, 200);` for the image data, a 24 bit tiff is exactly what I get. This is confirmed by Geeqie, a Linux image viewer, as well as the GIMP. A problem could be that your colormap `gray` does not match the indices used in `IND`. Without any further arguments, `gray` produces a 64-entry colormap, and values larger than 64 are clipped to 64 = white. – A. Donda Aug 07 '15 at 18:05
  • @Yasin: Could you give us a step by step instruction to reproduce your problem? – Daniel Aug 07 '15 at 19:09
  • What I'm trying to do is basically, read an image and instead of dealing with its tuple RGB, deal with its indecies which are single values. However, it now to seems like rgb2ind changes from image to image for a fixed color. Is that right? If that is, then it is useless for me. That said, in this case I was first trying to write out the indexed image as a 24 bit RGB so that I can color pick the real values of that indexed image. Matlab tells me the indexed image has values above 100, hence, the 24 bit RGB/Grayscale export. Is there any specific colormap I need to use with ind2rgb? – Yasin Aug 07 '15 at 19:36
  • 1
    Yes, you need to use a colormap with at least every color in your image; one entry for each distinct RGB value. This could, of course, be as many as 2^24 values. I think you should reconsider your approach. Dealing with RGB values is much, much easier. – beaker Aug 07 '15 at 20:12
  • Yes, that's what I'm trying to do now. I think I can get away with HSV too and more specifically only the Hue channel. It should work fine for me but I've got a quick question. rgb2hsv gives a double output whereas in Photoshop hue is based on angle from 0 to 359. How can I covert the hue that matlab gives me to its corresponding angle that can be equivalent to Photoshop? – Yasin Aug 07 '15 at 20:37
  • Actually I think I can just divide Photoshop hue by 360 and get the corresponding hue in matlab. – Yasin Aug 07 '15 at 20:45

0 Answers0