How to find the center of 4 points on an image?

15 ビュー (過去 30 日間)
Milad Zarei
Milad Zarei 2020 年 4 月 14 日
コメント済み: Ameer Hamza 2020 年 4 月 16 日
I have an image of the foot that was devided into different cells. I need to find the center of each cell. I was wondering if the best way to do so is to pick the 4 points on the vertices of the cell and let Matlab find the center?
Attache is the image. Let me know if you have any ideas. Thanks.
  2 件のコメント
Tommy
Tommy 2020 年 4 月 14 日
You could create a polyshape based on the four vertices and then use centroid.
Milad Zarei
Milad Zarei 2020 年 4 月 15 日
Yes, I think that would work. I'll give it a shot. Thanks!

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 15 日
編集済み: Ameer Hamza 2020 年 4 月 15 日
try this code. It requires functions from image preocessing toolbox.
im = im2double(imread('image.jpeg'));
%% remove red text
im_gray = rgb2gray(im);
im_gray(~(im_gray < 0.2)) = 1;
im_gray = double(imbinarize(im_gray));
%% find the polygons
regions = bwconncomp(im_gray);
pxlList = regions.PixelIdxList;
outlier = isoutlier(cellfun(@(x) numel(x), pxlList));
pxlList(outlier) = [];
%% find centers
centers = zeros(numel(pxlList), 2);
for i=1:numel(pxlList)
im_zeros = zeros(size(im_gray));
im_zeros(pxlList{i}) = 1;
rp = regionprops(im_zeros);
centers(i, :) = rp.Centroid;
end
%%
imshow(im);
hold on
plot(centers(:,1), centers(:,2), 'r+', 'LineWidth', 2, 'MarkerSize', 10);
  8 件のコメント
Milad Zarei
Milad Zarei 2020 年 4 月 16 日
Ameer, I am honestly impressed. This is so neat. Good job.
Just a quick question. The first code, it finds the centers in pixles (not mm), right?
Ameer Hamza
Ameer Hamza 2020 年 4 月 16 日
I am glad to be of help.
Yes, It finds centers in pixel coordinates. You can convert it to mm according to your scale.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by