Reorganize a table of points based on their coodinates
1 回表示 (過去 30 日間)
古いコメントを表示
Quentin Govignon
2019 年 11 月 13 日
コメント済み: Quentin Govignon
2019 年 11 月 13 日
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!