Stretch quadrilateral ROI to pre-definded rectangle size

5 visualizaciones (últimos 30 días)
Lets say I have a quadrilateral ROI in my image roughly resembling a rectangle. I want to take this ROI and turn the corresponding pixels into lets say a 100x200 rect from that ROI. I am thinking I will probably need to use interp or imtransform for this, but this is something I have very little experience in so if anyone has a few suggestions (or sample code!), that would be great!
-Shaun

Respuesta aceptada

Jeff E
Jeff E el 1 de Abr. de 2013
When I started out learning about image transformations (a process still going on, BTW), using the manual control point selection tool, CPSELECT, was helpful. Take your raw image as one input, and a binary image with a rectangle of your desired dimensions, and pick some points by hand. Export those points to the workspace for use in CP2TFORM, then apply the results transform using IMTRANSFORM.
After you have that process down, then you can figure out how to programmatically replace the manually selected points (if necessary).
  2 comentarios
Shaun VanWeelden
Shaun VanWeelden el 2 de Abr. de 2013
Editada: Shaun VanWeelden el 2 de Abr. de 2013
Great places to look Jeff, thanks! It still took me quite awhile to figure out what I was doing, here is the partial solution I came up with:
imshow(origImg)
origImgVertex=ginput(4); %select in order: top left, bottom left, top right, bottom right
TFORM=cp2tform(origImgVertex,[1 1; height 1; 1 width; height width],'projective');
newImg=imtransform(origImg,TFORM);
Where height and width are the dimensions of your new rectangle. To avoid ginput when having a ROI, I am sure some simple bwmorph would fix this.
My final question is how would I go about calculating where the vertices I selected in my initial image ended up in my new image?
Thanks!
Shaun VanWeelden
Shaun VanWeelden el 2 de Abr. de 2013
And actually I figured it out, I just needed to specify additional arguments to imtransform, the results look GREAT now! Here is what I did:
A=imtransform(origImg,TFORM,'XData',[1 Width],'YData',[1 Height],'XYScale',[1 1]);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by