MATLAB Answers

how to get the (x,y) coordinate values of points touching bounding box

조회 수: 5(최근 30일)
Elysi Cochin
Elysi Cochin 22 Mar 2018
편집: Elysi Cochin 22 Mar 2018
I have a binary object
How can i get the (x,y) co-ordinate value of the points touching the bounding box.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 22 Mar 2018
I = imread('16.png') ;
[m,n] = size(I) ;
[y,x] = find(I) ;
% GEt mean
mx = mean(x) ; my = mean(y) ;
% Line 1
L1 = [repmat(mx,m,1) (1:m)'] ;
L2 = [(1:n)' repmat(my,n,1) ] ;
P = [L1(1,1) L1(1,2) ; L1(end,1) L1(end,2) ;L2(1,1) L2(1,2) ; L2(end,1) L2(end,2) ] ;
idx = knnsearch([x y],P) ;
imshow(I) ;
hold on
plot(x(idx),y(idx),'*r')

  댓글 수: 0

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Stalin Samuel
Stalin Samuel 22 Mar 2018
편집: Stalin Samuel 22 Mar 2018
Let us assume that, you have the image(from bounding box) in variable "Elysi". Then you can get the co-ordinate values using below code
[x1 y1]=find( Elysi(1,:)==1)
[x2 y2]=find( Elysi(:,end)==1)
[x3 y3]=find( Elysi(end,:)==1)
[x4 y4]=find( Elysi(:,1)==1)

  댓글 수: 0

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by