The document outlines a MATLAB script for processing images in a specified folder, extracting properties such as dimensions and channels, and saving both grayscale and individual RGB channel images to an output folder. It also generates a text file with image details, saves the properties in a MAT file, and converts the data to a CSV format. The script includes error handling for file saving and displays progress during processing.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views2 pages
problem-2
The document outlines a MATLAB script for processing images in a specified folder, extracting properties such as dimensions and channels, and saving both grayscale and individual RGB channel images to an output folder. It also generates a text file with image details, saves the properties in a MAT file, and converts the data to a CSV format. The script includes error handling for file saving and displays progress during processing.
if ~isempty(blueChannel) blueChannelImagePath = fullfile(outputFolder, ['BlueChannel_' imageFiles(i).name]); imwrite(blueChannel, blueChannelImagePath); end % Save red and green channel images if ~isempty(redChannel) redChannelImagePath = fullfile(outputFolder, ['RedChannel_' imageFiles(i).name]); imwrite(redChannel, redChannelImagePath); end
if ~isempty(greenChannel) greenChannelImagePath = fullfile(outputFolder, ['GreenChannel_' imageFiles(i).name]); imwrite(greenChannel, greenChannelImagePath); end
% Display progress (optional)
fprintf('Processing image %d/%d: %s\n', i, numImages, imageFiles(i).name);
matFilePath = fullfile(outputFolder, 'ImageProperties.mat'); save(matFilePath, 'imageProperties'); if exist(matFilePath, 'file') fprintf('MAT file saved successfully: %s\n', matFilePath); else warning('Failed to save MAT file: %s\n', matFilePath); end
% Convert structure array to table and write to CSV file
csvFilePath = fullfile(outputFolder, 'ImageProperties.csv'); propertiesTable = struct2table(imageProperties); writetable(propertiesTable, csvFilePath); if exist(csvFilePath, 'file') fprintf('CSV file saved successfully: %s\n', csvFilePath); else warning('Failed to save CSV file: %s\n', csvFilePath); end