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

8 ビュー (過去 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 Center および File ExchangeImages についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by