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.
