Extract RGB values, shape and size of many objects in all images inside a folder.
3 ビュー (過去 30 日間)
古いコメントを表示
Maria Pauline Capiroso
2023 年 5 月 9 日
コメント済み: Image Analyst
2023 年 5 月 9 日
Hi! May I know how to extract RGB values, major and minor diameter, and area of many seeds from different images in a folder using a single script? Please see attached sample images. Any help will be appreciated. Thank you so much!
1 件のコメント
Rik
2023 年 5 月 9 日
Start writing the code to do each task separately and then put those together. I would discourage the use of scripts for actual work. Use scripts only for debugging and use functions for code you plan to use next week or later.
採用された回答
Antoni Garcia-Herreros
2023 年 5 月 9 日
編集済み: Antoni Garcia-Herreros
2023 年 5 月 9 日
Hello Maria,
But the general idea would be to:
- Read an image
- Make the appropiate transformations to input it to regionprops
- Filter the data from regionprops to avoid capturing small particles
- Store those results.
Something like this:
clear all
close all
%% Input parameters
filefolder='C:\Users\...'; % Folder where your images are stored
Area_thr=1000; % Area threshold, only seed larger than this value [pixels] will be considered
plot_options=1; % 1 If plot is to be shown, 0 otherwise
%% Code
files=dir([filefolder '*.jpg']); % Structure containing all the .jpg images
MinD=[]; % Array with Min diameters values
MaxD=[]; % Array with Max diameters values
Area=[]; % Array with Area values
for i=1:numel(files) % Loop through the images in the folder
I=imread(fullfile(files(i).folder,files(i).name)); % read image
if size(I,3)>1 % Convert to grayscale
I=rgb2gray(I);
end
BW=imbinarize(I); % Convert to binary
BW=imcomplement(BW); % Make the seeds white instead of black
se = strel('disk',20);
closeBW = imclose(BW,se);
r=regionprops('table',closeBW,'Area','Centroid','MajorAxisLength','MinorAxisLength'); % Find all regions
M=table2array(r);
M=M(M(:,1)>Area_thr,:); % Filter rgions based on Area threshold
MinD=[MinD;M(:,5)]; % Store data
MaxD=[MaxD;M(:,4)];
Area=[Area;M(:,1)];
if plot_options==1
imshow(closeBW)
hold on
plot(M(:,2),M(:,3),'*')
hold off
end
end
2 件のコメント
Stephen23
2023 年 5 月 9 日
More robust using FULLFILE:
files=dir(fullfile(filefolder,'*.jpg'));
その他の回答 (1 件)
Image Analyst
2023 年 5 月 9 日
See the FAQ: Process a sequence of files
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.
2 件のコメント
Image Analyst
2023 年 5 月 9 日
If you want diameter (Equivalent Circular Diameter) then you'd want to ask regionprops for "EquivDiameter".
I would not use MajorAxisLength because it's the length of an ellipse fitted to the seed, not the length of the actual seed itself. For that you'd need to call bwferet
help bwferet
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!