Reputation: 313
I converted an image to a polyshape and therefore how can I find the top, bottom, left, right x,y coordinates of a polyshape object that was created ?
Code:
clc;
clear;
close all;
fileName= 'https://i.sstatic.net/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);
Upvotes: 1
Views: 179
Reputation: 75
To get the enclosing top (y_max), bottom (y_min), left (x_min), and right (x_max) coordinates (i.e. the bounding box), you can use:
[xlim,ylim] = boundingbox(pgon1);
In the two row-vectors, the lower and upper extremes of the x- and y-coordinates are saved respectively. Please refer to: https://mathworks.com/help/matlab/ref/polyshape.boundingbox.html
Upvotes: 2