Convert tiff image to jpeg or JPEG or Png
60 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Ashish Uthama
il 8 Ott 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.
Risposte (1)
Mann Baidi
il 17 Gen 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!
0 Commenti
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!