How to save all the data after processing all the images
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2023-4-20
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 个评论
Image Analyst
2023-4-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!