How to access tiff files

6 visualizzazioni (ultimi 30 giorni)
Daphne PARLIARI
Daphne PARLIARI il 30 Ott 2019
Risposto: Deepak il 10 Gen 2025 alle 6:26
Hello MatLab world.
I have several .tiif files in my hands that I need to access, read and extract certain data from. As it is the first time that I'm handlind .tiff, I need your lights.
I have 102 folders (daily data from 01/07/2019 to 10/10/2019: 102 days=102 folders) . Each folder contains a zipped file with 73 .tiff files. These .tiff files contain hourly temperature data.
First thing I must extract only the first 24 of the 73 as they represent the 24 hourly values of the first day. Second thing, I must access the data these 24 .tiff contain and locate the temperature values I need.
I am copying the few lines of code I have written and please enlighten me:
cd 'C:\Projects\LIFE ASTI\C.3\THESSTemperature'
t = Tiff('THESSTemperature_20190701T0000Z.tiff','r');
filename = 'THESSTemperature_20190701T0000Z.tiff';
imageData = read(t);
imshow(imageData);
info = imfinfo(filename)
Thank you in advance!

Risposte (1)

Deepak
Deepak il 10 Gen 2025 alle 6:26
We can automate the extraction of temperature data from ".tiff" files by first navigating through each folder containing daily data, unzipping any ".zip" files to access the ".tiff" files, and then reading the first 24 ".tiff" files in each folder, which represent hourly temperature data for the first day. By using "Tiff" and "imfinfo" functions in MATLAB, we can read and process these files to extract the necessary temperature data, ensuring that the script handles each folder and file systematically.
Below is the sample MATLAB code to achieve the same:
% Set the base directory where your folders are located
baseDir = 'C:\Projects\LIFE ASTI\C.3\THESSTemperature';
% Get a list of all folders in the base directory
folders = dir(baseDir);
folders = folders([folders.isdir]); % Keep only directories
% Loop through each folder
for i = 1:length(folders)
folderName = folders(i).name;
% Skip the '.' and '..' directories
if strcmp(folderName, '.') || strcmp(folderName, '..')
continue;
end
% Construct the full path to the current folder
currentFolder = fullfile(baseDir, folderName);
% Unzip the files in the current folder
zipFiles = dir(fullfile(currentFolder, '*.zip'));
for j = 1:length(zipFiles)
unzip(fullfile(currentFolder, zipFiles(j).name), currentFolder);
end
% Get a list of all .tiff files in the current folder
tiffFiles = dir(fullfile(currentFolder, '*.tiff'));
% Ensure there are at least 24 .tiff files
if length(tiffFiles) < 24
warning('Folder %s does not contain enough .tiff files.', folderName);
continue;
end
% Loop through and process the first 24 .tiff files
for k = 1:24
tiffFileName = tiffFiles(k).name;
tiffFilePath = fullfile(currentFolder, tiffFileName);
% Read the .tiff file
t = Tiff(tiffFilePath, 'r');
imageData = read(t);
close(t);
% Display the image (optional)
% imshow(imageData);
% Extract temperature data (example: assuming imageData contains temperature)
% You will need to adjust this part based on your specific data format
% temperatureData = processImageData(imageData);
% Display some information about the image
info = imfinfo(tiffFilePath);
fprintf('Processing %s: %d x %d pixels\n', tiffFileName, info.Width, info.Height);
end
end
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.

Categorie

Scopri di più su Data Import and Analysis 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!

Translated by