フィルターのクリア

Choosing the centroid of an specific shape

1 回表示 (過去 30 日間)
Danny Guana
Danny Guana 2023 年 2 月 7 日
編集済み: DGM 2023 年 2 月 7 日
I am trying to get the centre of a metallic cylinder ( see picture) using "regionprops" function. However, I get 100+ results. How can I choose the point closest to the centre? . Is there any way to focus on the metallic shape only ?
  3 件のコメント
Danny Guana
Danny Guana 2023 年 2 月 7 日
Sure, this is my code:
I = imread('Test 3.jpg');
imshow(I)
A= rgb2gray (I)
imshow (A)
J = imadjust(A,stretchlim(A),[]);
imshow(J)
stat2 = regionprops(J,'centroid');
imshow(I); hold on;
for x = 1: numel(stat2)
plot(stat2(x).Centroid(1),stat2(x).Centroid(2),'ro');
end
Danny Guana
Danny Guana 2023 年 2 月 7 日

サインインしてコメントする。

採用された回答

DGM
DGM 2023 年 2 月 7 日
編集済み: DGM 2023 年 2 月 7 日
Here. I tried to clean up the screenshot so that it's at least usable for a demo. Instead of using imadjust(), and trying to isolate the object by gray level alone, use the available color information to make the selection. You can try using the Color Thresholder App to get an idea of where to set the thresholds.
inpict = imread('clean.png');
% create simple mask in HSV
hsvpict = rgb2hsv(inpict);
mask = hsvpict(:,:,2)>0.375;
% clean up mask
mask = bwareafilt(mask,1); % select largest object
mask = bwconvhull(mask); % fill the blob by taking the convex hull
imshow(mask)
S = regionprops(mask,'centroid')
S = struct with fields:
Centroid: [711.5535 400.6236]
Note that the poor subject-background contrast and the uneven illumination are causing a lot of the problems here. If the script needs to handle many images, the variations are likely to require adjusting the thresholds unless you improve the physical setup.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by