Given a quadrilateral image, not necessarily a rectangle, how to find its top left point's x-y coordinate

조회 수: 9 (최근 30일)
Hello,
Given a quadrilateral image, not necessarily a rectangle, how to find its top left point's x-y coordinate? white spaces are NaN values and (x,y) is about (93,122) in this image.How to return it? Thanks!

채택된 답변

William Rose
William Rose 2023년 2월 2일
Since you did not include an image, I will make one. Then I search along the diagonals for a Non-NaN pixel, starting at the top left corner: (1,1). When I find a non-NaN pixel, I stop and display the pixel coordinates.
%% make image with a NaN border along top and left sides
Nr=300; Nc=400;
im1=ones(Nr,Nc); % red layer
im1(:,:,2)=0.8*ones(Nr,Nc); % green layer
im1(:,:,3)=0.2*ones(Nr,Nc); % blue layer
im1(1:15,:,:)=NaN; % NaNs for rows 1-15
im1(:,1:25,:)=NaN; % NaNs for columns 1-25
imshow(im1) % display image
%% search for top left corner pixel that is not NaN
row=1; col=1; % start point
while isnan(im1(row,col,1))
if row==1
row=col+1; col=1; % reset to lower left corner of a new diagonal
else
row=row-1; col=col+1; % move up and right along the diagonal
end
end
fprintf('Top left non-NaN pixel at row %d, column %d.\n',row,col)
Top left non-NaN pixel at row 16, column 26.
Try it. Good luck.

추가 답변 (1개)

Matt J
Matt J 2023년 2월 2일

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by