Filter löschen
Filter löschen

How to convert dataset of .mat to .tif files?

8 Ansichten (letzte 30 Tage)
Ronak
Ronak am 1 Mär. 2021
Beantwortet: Walter Roberson am 2 Mär. 2021
I have 100 hyperspectral images (501x502x38) in .mat format, and I want to convert them to .tif files, but my code does not work. Here is the code. I do appreciate your help.
fileList = dir(fullfile(inputFolder,'*.mat'));
for kk = 1:numel(fileList)
S = load(fullfile(fileList(kk).folder,fileList(kk).name));
I = S.cjdata.image;
fileName = replace(fileList(kk).name,'.mat','.tiff');
imwrite(I,fullfile(outputFolder,fileName));
end
  3 Kommentare
Ronak
Ronak am 1 Mär. 2021
Thank you, but unfortunetaly, the size is about 75 MB.
Simon Allosserie
Simon Allosserie am 2 Mär. 2021
It's difficult to assess without seeing the original files. Can you do
imshow(I)
Just to check if that is an actual image? If that already doesn't work, you first have to fix the way you form I.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 2 Mär. 2021
You need to use the Tiff() class https://www.mathworks.com/help/matlab/ref/tiff.html
Use SamplesPerPixel = 38, and use ExtraSamples https://www.awaresystems.be/imaging/tiff/tifftags/extrasamples.html as a vector of (38-3)=35 EXTRASAMPLE_UNSPECIFIED values.
However, you need to know more about what you are going to do with the TIFF files. If you were planning to use them as an "Image Stack" in ImageJ then you need a different arrangement, as ImageJ implements Image Stacks through a private tag. If you were planning to use them as GeoTiff, then you should probably use the geotiff routines in MATLAB.

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by