Convert tiff image to jpeg or JPEG or Png

20 views (last 30 days)
sheldon
sheldon on 8 Oct 2014
Answered: Sam on 15 Sep 2025
Hi there,
I am having an issue converting a tiff image file into a jpeg or png.
Pseudo: 1. Read in image with
img = imread();
2. Write the same file with
imwrite(img,'imgNew.jpg');
But it does not work.
Please can someone help me out with converting a tiff image to EITHER jpeg or .Png. Either one will be fine.
Thanks in advance!
  1 Comment
Ashish Uthama
Ashish Uthama on 8 Oct 2014
What does 'it does not work' mean? Does it error or the image saved not what you expected? If its the latter, how so?
Most likely the class of img is not uint8, since jpeg/png mostly need data to be in uint8, you would have to figure out how to convert the non-uint8 in the Tiff to uint8 for JPEG.

Sign in to comment.

Answers (2)

Mann Baidi
Mann Baidi on 17 Jan 2024
As per my understanding of the question, you are facing issue in reading the 'tiff' file and then converting it into JPEG.
Assuming that you might have multi-frames tiff image, when you read the tiff image using "imread()" function. This by defualt reads the first frame of the tiff image. For reading the other frames, you have to pass the frame number as parameter to the "imread" function as mentioned below:
imread("path/to/image",<frameNumber>);
Here is an example of how to read and civert multi-frame tiff images:
% Specify the path to your multiple frames TIFF file
tiffFilePath = 'multiframe_example.tif';
% Create a directory to save the JPEG images
outputDirectory = 'path/to/your/output/directory';
mkdir(outputDirectory);
% Read the multiple frames TIFF file
tiffInfo = imfinfo(tiffFilePath);
% Loop through each frame and save it as a JPEG image
for frame = 1:numel(tiffInfo)
% Read the current frame
imageData = imread(tiffFilePath, frame);
% Create a filename for the JPEG image (you can adjust the filename as needed)
jpegFileName = sprintf('frame_%03d.jpg', frame);
% Specify the full path for the output JPEG image
jpegFilePath = fullfile(outputDirectory, jpegFileName);
% Write the current frame to a JPEG file
imwrite(imageData, jpegFilePath);
end
Hope this works!

Sam
Sam on 15 Sep 2025
If you need to convert a TIFF image to JPEG or PNG quickly Softaken Image Converter is an excellent choice. This user-friendly tool allows you to batch convert multiple TIFF files at once saving a lot of time. You can choose the desired output format—JPEG for smaller file sizes or PNG for high-quality images with transparency support. The software maintains the original image quality and supports various additional features like compression and resolution settings. Even beginners will find it simple to use. For anyone looking for quick and reliable image conversion I highly recommended this software.

Community Treasure Hunt

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

Start Hunting!