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!