【问题标题】:Top, bottom, left, right x,y coordinates of a polyshape object- Matlabpolyshape对象的顶部,底部,左侧,右侧x,y坐标 - Matlab
【发布时间】:2021-02-15 05:07:51
【问题描述】:

我将图像转换为 polyshape,因此如何找到创建的 polyshape 对象的上、下、左、右 x,y 坐标?

代码:

clc;
clear;
close all; 

fileName= 'https://i.stack.imgur.com/AIJO3.jpg';
I = rgb2gray(imread(fileName));
I = imcomplement(I); 
 
imshow(I);
hold on;
 
%%%%%%Boundary
BW = imbinarize(I);
[B,L] = bwboundaries(BW,'noholes');
 
k=1;
stat = regionprops(I,'Centroid');
b = B{k};                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
yBoundary = b(:,2);
xBoundary = b(:,1);
plot(yBoundary, xBoundary, 'g', 'linewidth', 2);
 
%%%%%Polyshape object
pgon1 = polyshape(yBoundary, xBoundary); %flipped polyshape
plot(pgon1);

【问题讨论】:

    标签: matlab


    【解决方案1】:

    要获得 封闭 顶部 (y_max)、底部 (y_min)、左侧 (x_min) 和右侧 (x_max) 坐标(即边界框),您可以使用:

    [xlim,ylim] = boundingbox(pgon1);
    

    在两个行向量中,分别保存了 x 坐标和 y 坐标的下极值和上极值。 请参考:https://mathworks.com/help/matlab/ref/polyshape.boundingbox.html

    【讨论】: