Given a quadrilateral image, not necessarily a rectangle, how to find its top left point's x-y coordinate
4 ビュー (過去 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!
0 件のコメント
採用された回答
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)
Try it. Good luck.
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!