How I can convert a tif grayscale image into other form without losing information

81 views (last 30 days)
Hello,
I want to convert tif grayscale image into other forms, such as jpeg, png, or others. I searched with Google but no useful solution was found. Anyone here can help me? Appreciate.
Y.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jun 2013
Not all TIFF files can be converted to other forms without loss of information. TIFF files are allowed to contain data that is complicated in ways that cannot be reproduced in the other file formats that you mention.
If you simply need to change a grayscale image to another form, and do not need any of the complications to be transferred with it, then:
in_name = 'xyz.tif'; %the name of your input image
out_name = 'xyz_converted.jpg'; %the name of the desired output
IM = imread(in_name); %read in the image
imwrite(IM, out_name); %write it out
  2 Comments
Walter Roberson
Walter Roberson on 6 Jun 2013
Ah... if the question is about how to invoke the "lossless" output format for the various file types, then you still use imwrite(), but you add parameters.
BMP, GIF, PGM, PPM, PCX, PNG, RAS, XWD - always lossless, no options needed
HDF4 - 'compression', 'none'
JPG, JP2 - 'mode', 'lossless'
PBM - cannot represent grayscale, do not use for this purpose
TIFF - 'Compression' with 'none' or 'packbits' or 'lzw' or 'deflate'
Note though that your original TIFF image might happen to be of higher depth than some of the formats can represent. If that is a concern, then read the imwrite() documentation.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 6 Jun 2013
If you want to save it to disk in another format, just save your array to a file where the filename has the extension of the desired format. Be aware that some formats are lossless compression, like PNG, while others are lossy, like jpeg. If you have no preference, I'd recommend PNG.

Community Treasure Hunt

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

Start Hunting!