Reorganize a table of points based on their coodinates

1 visualización (últimos 30 días)
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

Respuesta aceptada

Turlough Hughes
Turlough Hughes el 13 de Nov. de 2019
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)
  1 comentario
Quentin Govignon
Quentin Govignon el 13 de Nov. de 2019
thanks,
I made a few tweaks but it works,
changed the index name because I had already another index idx;
I had to transpose the input_points due to the formatting of my input points, and also add the 'omitnan' flag otherwise it took the nan lines as max in the sum
indx = zeros(1,4);
ptstemp=input_points';
[~,indx(1)]=min(sum(ptstemp));
ptstemp(:,indx(1))=[nan;nan];
[~,indx(2)]=min(ptstemp(1,:));
ptstemp(:,indx(2))=[nan;nan];
[~,indx(4)]=max(sum(ptstemp,'omitnan'));
ptstemp(:,indx(4))=[nan;nan];
indx(3)=setdiff(1:4,indx);
input_points=input_points(indx,:);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by