Save uint16 tiff image as truecolor with Matlab

I am processing microscopy images (in Matlab) in tiff format, usually uint8 or uint16. Basically I read them, put them in a cell array for processing, and then export them in tiff format either as a sequence of images or on a stack (using imwrite and either the "overwrite" property or "add" the writemode property for imwrite respectively) ... Everything has been working very well so far.

The problem I am facing is the following:

When I open images with ImageJ, they are not in color mode with "RGB" color gamut, but in complex mode. For example, ImageJ reads the data as 8 bits, which is, but does not open the image as truecolor (Sorry for the poor choice of words, I don't know the correct terminology). Hence I need to manually merge 3 channels together, which is annoying for large datasets.

Here is an explanation of the screen. The left is what I would like, i.e. what i get if i open an image directly from ImageJ and on the right is what I have after saving images with Matlab and opening them with ImageJ, which is not what I want.

enter image description here

The code I am using to export a sequence of images is as follows. "FinalSequenceToExport" is a cell array containing images.

for i = 1:SliceNumber
    ExportedName = sprintf('%s%s%d.tiff',fileName,'Z',i);
  imwrite(FinalSequenceToExport{i},ExportedName,'tif','WriteMode','overwrite','Compression','none');

end

      

  • If I give Matlab the size of FinalSequenceToExport {1} for example it gives 512 x 512 x 3.
  • If I open the given image in a command window and then save it with the same code as above, it does what I want and the resulting image opens as I want in ImageJ. Hence, I am guessing that the problem is due to the use of a cell array, but I do not understand how to do this.

Hope I was clear enough. If not, ask for more details. Thanks for the help!

+3


source to share


2 answers


After revising this question, I found the following to work, thanks to @ Ashish's tip:

imwrite(uint8(FinalSequenceToExport{i}/255),...);

      



I just needed to divide by 255 after converting to uint8.

0


source


You need to specify "ColorSpace"

try it



imwrite(FinalSequenceToExport{i},ExportedName,...
       'tif','WriteMode','overwrite','Compression','none', ...
       'ColorSpace', 'rgb');

      

0


source







All Articles