필터 지우기
필터 지우기

Number of Objects in image

조회 수: 2 (최근 30일)
Diogo Costa
Diogo Costa 2021년 6월 10일
답변: Image Analyst 2021년 6월 10일
So I have this code that determines the number of pollen grains in the image. Is it possible to be able to separate the types of grains and obtain the total number for each type?
clear all;
close all;
clc;
I1 = imread ('Pollen1.tif');
ix = 3; iy = 800 * 3 / 1000;
I2 = rgb2gray(I1);
Ibw = im2bw(I2, graythresh(I2));
Ibw = ~Ibw;
I3 = bwareaopen(Ibw,10);
I4 = im2bw(I3,0.2);
I5 = imclearborder(I4);
himage1 = imshow(I4,'XData',[0 ix],'YData',[0 iy]); hold on
set(himage1,'AlphaData',0.4);
himage2 = imshow (imsubtract(I4,I5),'XData',[0 ix],'YData',[0 iy]);
set(himage2,'AlphaData',0.7);
title ('Image Border'), hold off
figure,
[B,L] = bwboundaries(I4,'noholes');
[labeled,numObjects]=bwlabeln(I5,4);
numObjects
graindata=regionprops(labeled,'basic');
grainareas=[graindata(:).Area];
objectareas=3^2*grainareas * 1000^(-2);
max_area = max (objectareas)
min_area = min (objectareas)
mean_area = mean (objectareas)
clf
e =0:0.0005:0.15;
histogram(objectareas,e)
xlabel('Grain Size in Millimeters^2')
ylabel('Number of Grains')
axis([0 0.1 0 30])
D = bwdist(~I5,'cityblock');
D=-D;
D(~I5)=-Inf;
L2 = watershed(D);
figure
subplot (3,2,1);
imshow(I1,'XData',[0 ix],'YData',[0 iy]), title ('Original Image')
subplot (3,2,2);
imshow(I2,'XData',[0 ix],'YData',[0 iy]), title ('Grayscale Image')
subplot (3,2,3);
imshow(I3), title ('Black Background')
subplot (3,2,4);
imshow(I4,'XData',[0 ix],'YData',[0 iy]), title ('Binarize Image')
subplot (3,2,5);
imshow(label2rgb(L,@jet,'w','shuffle'),'XData',[0 ix],'YData',[0 iy]), title ('Define Objects')
subplot (3,2,6);
imshow(label2rgb(L2,@jet,'w','shuffle'),'XData',[0 ix],'YData',[0 iy]), title('Watershed Segmentation')
  댓글 수: 3
Diogo Costa
Diogo Costa 2021년 6월 10일
편집: Diogo Costa 2021년 6월 10일
Then give me your email because the files have more then 5 MB each and does not let me put in here
Adam Danz
Adam Danz 2021년 6월 10일
I saved the PDF as a TIF file which is lower resolution than your image but is still large enough to get very similar results. The steps of downloading the file and converting it is often enough hastle for contributers to select a different question to answer. Just a tip to maximize your chances of getting help: make it very easy for people to run the code. And thanks for providing the code!
I played around with this for a bit but ran out of time and couldn't separate some of the clusters of pollen.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2021년 6월 10일
The watershed returns a labeled image so you should just be able to get the max value of it to count the regions:
numberOfRegions = max(L2(:))
I'm not sure what you mean by "each type". If each region has a different looking object in it then you're going to have to classify them somehow, like by their color, size, shape, or whatever.

Community Treasure Hunt

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

Start Hunting!

Translated by