# How do I create a minimum bounding box from locations in cornerPoints object?

28 visualizzazioni (ultimi 30 giorni)
Chica_chic il 6 Giu 2016
Risposto: karim botros il 8 Apr 2022
I am trying to create a minimum bounding box(rectangle) from the corner locations obtained by selecting 75 strongest points after using detectMinEigenFeatures(the example given in the documentation). Here is my code:
I = imread('F:\8th sem\programs\proc_8\001.jpg'); corners = detectMinEigenFeatures(I); strong = corners.selectStrongest(70); figure, imshow(I); hold on plot(strong);
I want to know how to create a rectangle that encloses my region on interest with these corner point locations. Can someone help me in writing the code?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

KSSV il 6 Giu 2016
Are you expecting rectangle like below?
I = imread('F:\8th sem\programs\proc_8\001.jpg');
corners = detectMinEigenFeatures(I);
strong = corners.selectStrongest(70);
figure,
imshow(I);
hold on
plot(strong);
coor = strong.Location ;
xmin = min(coor(:,1)) ; xmax = max(coor(:,1));
ymin = min(coor(:,2)) ; ymax = max(coor(:,2));
% Rectangle coordinates
O = [xmin,ymin ; xmax ymin ; xmax ymax ; xmin ymax ; xmin ymin] ;
plot(O(:,1),O(:,2),'k')
##### 2 CommentiMostra NessunoNascondi Nessuno
Chica_chic il 6 Giu 2016
This is what I was looking for. Thank you for your help :)
Chica_chic il 8 Giu 2016
What if I wanted a polygon out of the coordinates, in such a way that the points get connected clockwise? I've posted a separate question regarding it. It would be great if you could check it.

Accedi per commentare.

### Più risposte (3)

Nut il 6 Giu 2016
Hi,
I think this code should be ok for you:
x_coordinates = strong.Location(:,1);
y_coordinates = strong.Location(:,2);
left_edge = floor(min(x_coordinates));
right_edge = ceil(max(x_coordinates));
up_edge = floor(min(y_coordinates));
down_edge = ceil(max(y_coordinates));
new_I = I(up_edge:down_edge,left_edge:right_edge);
imshow(new_I)
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Chica_chic il 6 Giu 2016
Although this code is working well, it wasn't what I was looking for. But thank you for your help :)

Accedi per commentare.

Amir Barkhordary il 13 Lug 2018
I am trying to create a rectangular bounding box of coordinates (latitude and longitude) to find out about the SST in Great Barrier Reef. For example the coordinates of Lizard Island in Queensland are: -14.667997328 145.455664844. In order to create a SST file using seaDAS Program I would would at least to have more coordinates (such left right top bottom) for this region but I do not know how create such a box containing the region's geographical characteristics in Matlab. I appreciate any help :)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

karim botros il 8 Apr 2022
you can plot a rectangle or anyshape around the matched feature points using the following code:
minx = min(matchedPoints.Location(:,1));
miny = min(matchedPoints.Location(:,2));
maxx = max(matchedPoints.Location(:,1));
maxy = max(matchedPoints.Location(:,2));
rectangle('Position', [minx, miny, (maxx-minx),(maxy-miny)],...
'EdgeColor','g', 'LineWidth', 2)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Feature Detection and Extraction in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by