How to save all the data after processing all the images
7 views (last 30 days)
Show older comments
Hallo everyone,
I would like to ask you a question about how to save all the datas after processing all the images.
The code is shown as follow,
% Specify the folder where the files live.
myFolder = '';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.bmp'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
figure
drawnow; % Force display to update immediately.
end
Use this code to process all the images, however the data will get overwritten each time, in the workspace only show the last image data. there are totally 8 images, I would like to save all the datas of 8 images, and make histogram of the datas(such as, area, premieter....)
Thanks in advance
JL
0 Comments
Accepted Answer
Image Analyst
on 20 Apr 2023
Didn't I answer that in your duplicate question? https://www.mathworks.com/matlabcentral/answers/1938859-how-to-save-all-the-images-data-in-workplace-after-processing-all-the-images#answer_1206859
You have to get the values and index them, for example:
% Specify the folder where the files live.
myFolder = pwd;
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.bmp'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
allAreas = []; % Array to store all the areas from all the images.
allMeans = [];
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Read in grayscale image
grayImage = imread(fullFileName);
% Threshold image
mask = imbinarize(grayImage);
% Compute areas for k'th image
props = regionprops(mask);
% Get all areas.
theseAreas = [props.Area]; % Areas of blobs in only this particular image.
% Append to our growing list of areas for all images.
allAreas = [allAreas, theseAreas];
% Get the mean for this image.
allMeans(k) = mean(thisImage, 'all');
end
% Show histogram of all the areas for all the images.
figure;
subplot(1, 2, 1);
histogram(allAreas);
title('Area Histogram')
grid on;
% Show histogram of all the means for all the images.
subplot(1, 2, 2);
histogram(allMeans);
title('Mean Gray Level Histogram')
grid on;
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
7 Comments
Image Analyst
on 21 Apr 2023
Steve Eddins has one, with Gonzales I think, on image processing using MATLAB. Also a book by John Russ "The Image Processing Handbook" is a very good book. Wide variety of examples and not heavy on math.
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!