フィルターのクリア

How to save all the data after processing all the images

4 ビュー (過去 30 日間)
Jialin Men
Jialin Men 2023 年 4 月 20 日
コメント済み: Jialin Men 2023 年 4 月 24 日
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.
Jialin Men
Jialin Men 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 Center および File ExchangeImage Data Workflows についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by