How can I count these particles that are in the vignette?

2 views (last 30 days)
I am creating an algorithm that can count in-focus pieces of sand. My major issue has been counting in-focus pieces of sand in the vignette. I was able to divide the grayImage from the background but I am still failing to count pieces of sand that are deep in the vignette (as seen in the provided pictures). I use imgradient and then a threshold to select for shapr edges. I tried to create a mask of the vignette region where the threshold is lower, but the lower threshold allows for out of focus particles to be counted. Does anyone have any ideas?
In the correctedImage, white circles were counted by algorithm and red circles were left out.
%Code above reads in image
correctedImage = double(grayImage) ./ double(backgroundImage);
%gradient
figure
G= imgradient(correctedImage);
J= (G>1.05);
imagesc(J)
axis image
colormap gray
[JV, JU]= find(J);
hold on
plot(JU,JV,'.')
%cleans up small isolated groups of pixels
sizeThreshold = 15;
J_clean = bwareaopen(J, sizeThreshold);
cleanedImage= bwmorph(J_clean, 'clean');
%closes connected pixels
se = strel('disk',30);
closeJ = imclose(cleanedImage,se);
[JVC, JUC]= find(closeJ);
plot(JUC,JVC,'.')
plot(JU,JV,'.')
labeledImage = bwlabel(closeJ);
%filters closed objects by size
minSize = 300;
filteredImage = bwareaopen(labeledImage, minSize);
%fills remaining objects
BW2 = imfill(filteredImage, 'holes');

Answers (1)

Moksh
Moksh on 22 Aug 2023
Edited: Moksh on 22 Aug 2023
Hi Samuel,
As per my understanding the particles that are missed by your algorithm are mainly in the corners of images. They might be missed due to the lack of clear separation between in-focus particles and the background in these dark regions.
You can use the "imflatfield" function of MATLAB for the flat-field correction which can help rectify this.
You can add the code before the implementation of your algorithm and use this output as the "grayImage" in your algorithm. This can be implemented as follows:
% Read the raw image
I = imread('RawImage1.png');
% Applying the flat-field correction using imflatfield function
sigma = 20;
Iflatfield = imflatfield(I, sigma);
Iflatfield = rgb2gray(Iflatfield);
% Displaying Output
figure;
imshow(Iflatfield);
Please use the following documentation for a better understanding of the "imflatfield" function.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!