Benoit_11
Benoit_11

Reputation: 13945

Save uint16 tiff image as truecolor with Matlab

I am processing microscopy images (in Matlab) in the tiff format, normally uint8 or uint16. Basically I read them, put them in a cell array for processing and then export them in the tiff format either as an image sequence or a stack (using imwrite and either the 'overwrite' or 'append' writemode property of imwrite, respectively). Up to now everything works very well.

The problem I'm having is the following:

When I open the images with ImageJ, they are not in truecolor "RGB" color mode, but rather in composite mode. For example ImageJ reads the data as 8 bit, which it is, but does not open the image as a truecolor (Sorry for the bad choice of words I don't know the right terminology). Hence I have to manually combine the 3 channels together, which is bothersome for large datasets.

Here is a screen shot explaining. On the left is what I would like,i.e. what I obtain if I open the image directly with ImageJ, and on the right is what I currently have after saving images with Matlab and opening them with ImageJ, which I don't want.

enter image description here

The code I'm using to export the image sequence is the following. "FinalSequenceToExport" is the cell array containing the images.

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

end

I hope I've been clear enough. If not please ask for more details. Thanks for the help!

Upvotes: 3

Views: 1626

Answers (2)

Benoit_11
Benoit_11

Reputation: 13945

After revisiting this question I found the following to work, thanks to the hint from @Ashish:

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

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

Upvotes: 0

bendervader
bendervader

Reputation: 2660

You need to specify the the 'ColorSpace'

Try this

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

Upvotes: 0

Related Questions