Save TIFF with Look Up Table

5 views (last 30 days)
Hello,
I'm trying to save my images as 16-bits tiff files using the imwrite function. I can create this file but I didn't find the option to save it with a desired LUT.
begin of my code
imwrite(channel1, fullname_tif_output,output_format,'WriteMode','overwrite','Compression','none');
imwrite(channel4,fullname_tif_output,output_format,'WriteMode','append', 'Compression','none');
imwrite(channel3, fullname_tif_output,output_format,'WriteMode','append', 'Compression','none');
imwrite(channel4, fullname_tif_output,output_format,'WriteMode','append', 'Compression','none');
end of my code

Accepted Answer

Matt Cohen
Matt Cohen on 29 Jul 2015
Hi Sébastien,
I assume that by lookup tables you mean Red-Green-Blue (RGB) color maps associated with the TIFF image. The function "imwrite" allows you to save the images as TIFF files; unfortunately, this function does not support writing the associated lookup tables with the files. You may want to explore MATLAB's Tiff class, which provides access to many of the capabilities of the LibTIFF library.
I hope this helps.
Matt
  1 Comment
Sébastien MAILFERT
Sébastien MAILFERT on 30 Jul 2015
Hello Matt, It was exactly what I would expect: a clear answer! I followed your link and find this solution using the tiff class: Creating a New TIFF File
1.Create some image data. This example reads image data from a JPEG file included with MATLAB:
imgdata = imread('ngc6543a.jpg');
2.Create a new TIFF file by constructing a Tiff object, specifying the name of the new file as an argument. To create a file you must specify either write mode ('w') or append mode ('a'):
t = Tiff('myfile.tif','w');
When you create a new TIFF file, the Tiff constructor creates a file containing an image file directory (IFD). A TIFF file uses this IFD to organize all the data and metadata associated with a particular image. A TIFF file can contain multiple IFDs. The Tiff object makes the IFD it creates the current IFD. Tiff object methods operate on the current IFD. You can navigate among IFDs in a TIFF file and specify which IFD is the current IFD using Tiff object methods.
3.Set required TIFF tags using the setTag method of the Tiff object. These required tags specify information about the image, such as its length and width. To break the image data into strips, specify a value for the RowsPerStrip tag. To break the image data into tiles, specify values for the TileWidth and TileLength tags. The example creates a structure that contains tag names and values and passes that to setTag. You also can set each tag individually.
tagstruct.ImageLength = size(imgdata,1) tagstruct.ImageWidth = size(imgdata,2) tagstruct.Photometric = Tiff.Photometric.RGB tagstruct.BitsPerSample = 8 tagstruct.SamplesPerPixel = 3 tagstruct.RowsPerStrip = 16 tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky tagstruct.Software = 'MATLAB' t.setTag(tagstruct)
For information about supported TIFF tags and how to set their values, see Setting Tag Values. For example, the Tiff object supports properties that you can use to set the values of certain properties. This example uses the Tiff object PlanarConfiguration property to specify the correct value for the chunky configuration: Tiff.PlanarConfiguration.Chunky.
4.Write the image data and metadata to the current directory using the write method of the Tiff object.
t.write(imgdata);
If you wanted to put multiple images into your file, call the writeDirectory method right after performing this write operation. The writeDirectory method sets up a new image file directory in the file and makes this new directory the current directory.
5.Close your connection to the file by closing the Tiff object:
t.close();
Thanks for your precise help and I'm sure this will help many people. Séb

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!