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

采纳的回答

Image Analyst
Image Analyst 2023-4-20
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
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.
JM
JM 2023-4-24
Hallo Image Analyst,
I am extremely grateful for your help.
That means a lot to me.
I hope one day to become an expert in image processing like you.
Have a nice day
JL

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by