How to detect circles in polygonal images?

2 Ansichten (letzte 30 Tage)
인환
인환 am 13 Feb. 2024
Beantwortet: Jasvin am 19 Feb. 2024
This is an X-ray image of the weld. I'm using the imfindcircles function to find the pores in the middle area of this image. Since the area to detect the circle is not rectangular, I want to set the range of contrast and detect the circle only within that area. If you detect a circle in the area divided by the contrast area in the original image, the circle is detected only at the boundary of the area. Conversely, if you detect a circle in the entire original image and then leave only the corresponding part, the problem is that the desired circle is not detected. How can I solve this problem?
Below is the code I used.
img = imread("1113-1_자르기.png");
Error using imread>get_full_filename
File "1113-1_자르기.png" does not exist.

Error in imread (line 372)
fullname = get_full_filename(filename);
gray_img = rgb2gray(img);
[centers, radii, metric] = imfindcircles(img, [5 30], "ObjectPolarity", "bright", "Sensitivity", 0.94, "EdgeThreshold", 0.13, "Method", "PhaseCode");
disp(['검출된 원의 개수: ' num2str(length(centers))]);
bright_region = gray_img >= 80 & gray_img <= 160;
result_img = img;
selected_centers = [];
selected_radii = [];
for i = 1:length(centers)
center_x = round(centers(i, 1));
center_y = round(centers(i, 2));
radius = round(radii(i));
if bright_region(center_y, center_x)
result_img = insertShape(result_img, 'FilledCircle', [center_x, center_y, radius], 'Color', 'r');
selected_centers = [selected_centers; [center_x, center_y]];
selected_radii = [selected_radii; radius];
end
end
figure;
imshow(result_img);
title('밝은 부분에 해당되는 원만 표시된 결과 이미지');
fprintf('선택된 원의 개수: %d\n', length(selected_centers));
fprintf('선택된 원의 정보:\n');
fprintf(' 반지름(px)\t크기(픽셀 제곱)\n');
disp([selected_radii, pi * selected_radii.^2]);

Antworten (1)

Jasvin
Jasvin am 19 Feb. 2024
Hi, the way I see it you, want to identify the pores (circles) in the middle area of the image (which is not necessarily a rectangular area or even an area of any particular shape). The way you have determined to distinguish this area is based on the contrast of the image, i.e. the pixel intensity as indicated by the "bright_region" variable.
I ran the code you shared, and it ended up marking circles for the entire image, although the "bright_region" filter does not account for the lower half of the image as well as the top edge of the image which contains many circles.
I feel like there is no straight forward way of accomplishing what you are trying to do without having a very clear idea on the definition of what your area of interest is. If you can pin it down to pixel coordinates and/or a shape, then the job would become much easier as you can just update the shared code to check whether the center of the circle falls in the area of interest:
if (region_of_interest(center_y, center_x))
% Mark a circle in the image
Also, I did not get the meaning of this sentence "If you detect a circle in the area divided by the contrast area in the original image, the circle is detected only at the boundary of the area", if you could clarify this statement further, then it would probably help out in getting you an answer from the community.

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by