Identifying blobs and area filtering
Show older comments
Hello, Im trying to identify the centres of the drops in the image below. Although in each drop there is a bright area, I dont care about this.
My analysis fails when the drop in the middle picture (binary) touches the large white circle (at the green line).
1: How can I get that last drop included thats touching the boundary

Here is my code.
IM=getimage(app.UIAxes);
pos=myfigure(app,1450,520); %my own function
figA=figure('position',pos);
m = uimenu(figA,Label="My Save As");
m.MenuSelectedFcn = @app.mysavefunc;
ax1=subplot(1,3,1);
myImagesc(app,ax1,IM); %My version of ImageSc
title(ax1,'Raw Image');
%Use adaptive thresholding as varying background
BW = imbinarize(IM,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);
BW = imcomplement(BW);
ax2=subplot(1,3,2);
myImagesc(app,ax2,BW);
title(ax2,'Imbinarise');
ax3=subplot(1,3,3);
BW=imclearborder(BW); %Clear up borders
BW = bwareafilt(BW,[5000 100000]); % Make sure no small areas are passed
keep = bwareafilt(BW,10); % Allow upto 10 largest objects to be kept
keep = imfill(keep,"holes"); % Fill any holes
myImagesc(app,ax3,keep);
title(ax3,'bwareafilt');
S = regionprops(keep, 'Area','Centroid')
[sy,~]=size(S)
centroids=S.Centroid
hold(ax2,'on');
% cl = {'r+','b+','m+','r*','b*','m*','c+','c*'};
for i=1:sy
xc=S(i).Centroid(:,1); yc=S(i).Centroid(:,2);
ReportMessage(app,['Area ',num2str(i),' = ',num2str(S(i).Area),', xc=',num2str(xc,'%.1f'), ', yc=',num2str(yc,'%.1f')])
plot(ax2,xc,yc,'r+'); % plot(ax2,xc,yc,cl{i});
end
Thanks for any help
2 Comments
Matt J
on 23 Jan 2023
I suggest attaching the input image IM in a .mat file, so that we can play with it.
Accepted Answer
More Answers (1)
Image Analyst
on 23 Jan 2023
0 votes
I would try to get an image with no drops in it and then do a background correction by dividing by it. Then your global threshold will work better. See attached background correction demo.
If you need more help, attach your droplets image and your background image without any droplets in it with the paperclip icon.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
