Given a quadrilateral image, not necessarily a rectangle, how to find its top left point's x-y coordinate
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yuhong
el 2 de Feb. de 2023
Comentada: William Rose
el 2 de Feb. de 2023
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 comentarios
Respuesta aceptada
William Rose
el 2 de Feb. de 2023
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.
2 comentarios
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!