Bounding box width and Y coordinate in image processing

5 ビュー (過去 30 日間)
Soul Keeper
Soul Keeper 2016 年 3 月 14 日
コメント済み: Soul Keeper 2016 年 3 月 14 日
Hi there can someone help with something...
I need to dete
ct the width of an object surrounded by a bounding box. I have the centroid for it and i need to calculate at first the distance between the centroid and the left side of the box(and put this in a variable); and then the width between the centroid and the right hand side of the box(a new variable). after that i can calculate the width of the whole object buy doing a sum between both variables. i need to do it this way - don't ask why cuz I don't know either. I have attached a photo maybe you will understand better
this is what i have so far in terms of coding
prop = regionprops(imgFill);
hold on
for n=1:length(prop)
rectangle('Position',prop(n).BoundingBox,'EdgeColor','b','LineWidth',2);
x = prop(n).Centroid(1);
y = prop(n).Centroid(2);
plot(x,y);
end
hold off

採用された回答

Image Analyst
Image Analyst 2016 年 3 月 14 日
Try this:
props = regionprops(imgFill, 'Centroid', 'BoundingBox');
hold on
for k=1:length(props)
thisCentroid = props(k).Centroid;
thisBoundingBox = props(k).BoundingBox;
rectangle('Position',props(k).BoundingBox,'EdgeColor','b','LineWidth',2);
x = prop(k).Centroid(1);
y = prop(k).Centroid(2);
plot(x, y, 'r+', 'MarkerSize', 13, 'LineWidth', 2);
% Find the left edge and right edge of the bounding box.
leftColumn = thisBoundingBox(1) + 0.5;
rightColumn = thisBoundingBox(1) - 0.5;
% Find the distance of them to the centroid.
leftDistance(k) = x - leftColumn
rightDistance(k) = rightColumn - x
% Plot a line between them
line([leftColumn, rightColumn], [y, y], 'Color', 'g');
end
hold off
  6 件のコメント
Soul Keeper
Soul Keeper 2016 年 3 月 14 日
sorry my bad this is what i did
topDistance(k) = y - topRow;
botDistance(k) = -(bottomRow - y);
[max_num_top, max_idx_top]=max(topDistance(:));
[max_num_bot, max_idx_bot]=max(botDistance(:));
max_num_top
max_num_bot
it gives me the right value. i've got confused with something - don't know what either :-/
Soul Keeper
Soul Keeper 2016 年 3 月 14 日
anyway.. i wanted to say .. sir.. you are a star! thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurfaces, Volumes, and Polygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by