Effacer les filtres
Effacer les filtres

How to save all the data after processing all the images

4 vues (au cours des 30 derniers jours)
Jialin Men
Jialin Men le 20 Avr 2023
Commenté : Jialin Men le 24 Avr 2023
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

Réponse acceptée

Image Analyst
Image Analyst le 20 Avr 2023
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 commentaires
Image Analyst
Image Analyst le 21 Avr 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.
Jialin Men
Jialin Men le 24 Avr 2023
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by