Preprocess to improve imfindcircles performance, and get pixel positions within the circles
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
AbioEngineer
el 6 de Nov. de 2022
I have an image with a bunch of circular objects as shown below, but imfindcircles doesn't seem to find the ROIs that I need. Are there preprocessing steps to improve performance? I've tried thresholding the original image to get a mask but the result has fuzzy edges or fused edges. Applying watershed to the masked image makes the circles look rigid and non-circular. I have also tried to apply some ft filters or tophat background removal but no luck. There are so many parameter combinations, I'm just hoping someone has found success with one or has some general tips on which direction to go in terms of filter parameters.
After I find the circles, I want to plot the intensity of the pixels within each circle to see if there is a trend that correlates with circle size. Therefore, if there are 100 circles, I want to have 100 data points, each of which corresponding to the mean pixel intensity within that circle.
1 comentario
Walter Roberson
el 6 de Nov. de 2022
When I look at the image, it looks to me as if you have illumination issues. It looks like you have an diffuse light source that is off to some side (top left, I think) -- that in particular there is a center depression that is in partial shadow. If I am right, you will need to repair the illumination to get the information you want.
Respuesta aceptada
Marcel
el 7 de Nov. de 2022
Editada: Marcel
el 7 de Nov. de 2022
In my case, i have to find specific circles in specific areas. They have to have a certain radius as well. When "scanning" the image for circles i realised it takes a lot of time to find the circles, somewhere 4 to 9 seconds. I then realised when cropping the image to the specific area where one of the circles should be, it was much faster. After adjusting the options for imfindcircles and cropping the images to the areas i need them, im taking about 0.2 to 0.4 seconds per picture im scanning for one circle.
Im cropping the images before looking for circles using the following code
[cropped, ~] = imcrop(image, crop);
crop is something like [1.02323 0.7878 1.30034 0.9845] (X Y Width Height i believe. something like that). So I proceeded with the cropped variable.
When i had issues detecting the circles, the options for imfindcircles "Sensitivity", "Method" and "EdgeThreshold" helped me fix this issue a lot! Also lighting is very important in my case at least!
After finding the circles i used a custom function i made to draw the cirlces onto the image
function results = addCircle(~, img, position, color)
% Adds a circle to the image and returns it
img = insertShape(img, "Circle", position, "Color", color, "LineWidth", 4);
results = img;
end
% Search for circles
% (was called in a function)
[centersBig, radiiBig, ~] = imfindcircles(croppedBig, radius, "Sensitivity", sensitivity, "Method", method, "EdgeThreshold", 0.2);
% Get data
% centersBigFound will contain the X and Y location of the circle
% and radiiBigFound will contain the radius of the circle
%
% I my case im only looking for one circle as im running it in a loop in my
% application but its just a example :p
centersBigFound = centersBig(1:1,:);
radiiBigFound = radiiBig(1:1);
% Update the cropped image
cropped = addCircle(app, cropped, [centersBigFound(1,1) centersBigFound(1,2) radiiBigFound(1)], color);
And after one hell of a mess i call code im adding the cropped image back to the original one
% crop was the value as mentioned above (example!)
frame(crop(2):crop(2)+size(cropped,1)-1, crop(1):crop(1)+size(cropped,2)-1, :) = cropped;
I dont know if this will help you but i wanna share my experience here with you in the hopes to give you some ideas on how to do certain stuff or inspire you
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!