Reorganize a table of points based on their coodinates
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi there,
I want to do a imwarp for an image based on the recognition of four markers in my image.
I can find the coordinates of those four points listed as input_points but depending on the angle of image acquisition my points are not always listed in the same order.
I define my base points for the imwrap as:
base_points = [0 0; 0 HEIGHT; WIDTH 0; WIDTH HEIGHT];
scale_calib = (pdist2(input_points(1,:), input_points(2,:)))/ HEIGHT; % %pixel/mm
base_points = base_points*scale_calib;
Tform = fitgeotrans(input_points,base_points,'projective');
I_full = imwarp(im1,Tform);
and do the imwarp
but my image points are not always ordered the same way,
I sometimes get it right sometimes get the first and second point inverted wich then completely mess my image correction.
How could I sort my input_points to ensure that the first one is always the one with a min (x+y), then second point the one with min(x) out of the three remaining points, the fourth point can be the one with max(x+y), and the third point is the last remaining one.
I know I could do it a dirty and not efficient way but I would like to find a more elegant (and perhaps lighter) way of doing it
Thanks for your help
댓글 수: 0
채택된 답변
Turlough Hughes
2019년 11월 13일
I put down an index here for sorting the points as you requested. It should do the job.
ptstemp=input_points
[~,idx(1)]=min(sum(ptstemp));
ptstemp(:,idx(1))=[nan;nan];
[~,idx(2)]=min(ptstemp(1,:))
ptstemp(:,idx(2))=[nan;nan];
[~,idx(3)]=max(sum(ptstemp));
ptstemp(:,idx(3))=[nan;nan];
idx(4)=setdiff(1:4,idx);
input_points=input_points(:,idx)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!