How to rotate, transform an Roi

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to rotate, transform an Roi

Paul Johnston
I'm just getting into the ImageProcessor API.

I have a source image 'src' and destination image 'dst'.  I want to
take pixels from src (using a ShapeRoi), rotate it, and move it to a
different location to dst.  Said another way, imagine a picture of a
someone's face that's rotated over to one side: I want to copy the
head, make it upright, and then paste it to another image.

What is the strategy to do this?  Is there a code sample that you
recommend?  Currently I can copy a rectangular Roi from src and copy
it to dst with the following (shown below).  But I'm getting stuck as
I think the solution probably involves masking, but I don't understand
how to use and apply this technique.

Thanks,
Paul

           ImagePlus src = image; // a reference obtained from a different
part of my application
           int ht = src.getHeight();
           int wd = src.getWidth();

           ImagePlus dst = NewImage.createRGBImage("test", wd, ht, 1,
NewImage.FILL_BLACK);

           ImageProcessor srcp = src.getProcessor();
           ImageProcessor dstp = dst.getProcessor();
           int[] srcpix = (int[])srcp.getPixels();
           int[] dstpix = (int[])dstp.getPixels();

           Rectangle r = srcp.getRoi();
           debug("roi bounds: "+r);

           for (int y=r.y; y<(r.y+r.height); y++) {
               for (int x=r.x; x<(r.x+r.width); x++) {
                   int i = x + y*wd;
                   dstpix[i] = srcpix[i];
               }
           }

           dst.updateAndDraw();
           dst.show();
Reply | Threaded
Open this post in threaded view
|

Re: How to rotate, transform an Roi

dscho
Hi,

On Wed, 15 Apr 2009, Paul Johnston wrote:

> I'm just getting into the ImageProcessor API.
>
> I have a source image 'src' and destination image 'dst'.  I want to
> take pixels from src (using a ShapeRoi), rotate it, and move it to a
> different location to dst.  Said another way, imagine a picture of a
> someone's face that's rotated over to one side: I want to copy the
> head, make it upright, and then paste it to another image.

You can do it in a macro by using Edit>Selection>Rotate, and then using
Image>Rotate>Arbitrarily... with the same angle.

So, just have a look at said two plugins and imitate what you see there.

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: How to rotate, transform an Roi

Antoinette
This is an image rotating method programmed using vb.net, I use it to guide my image processing tool development recently:



Public Shared Function ApplyRotate(img As REImage, deg As Integer) As Integer
End Function