Login  Register

Re: Rotate an image with given angle

Posted by Kenton Arkill on Oct 26, 2012; 1:39pm
URL: http://imagej.273.s1.nabble.com/Rotate-an-image-with-given-angle-tp5000544p5000546.html

Why not use the rotate function on the image/transform/rotate drop down and tick the box fit window to size?
Or did I miss something?
Kenton

Kenton Arkill
GB U23 Ladies'
Underwater Hockey Coach
GB Masters
Underwater Hockey Manager




On 26 Oct 2012, at 13:06, Veeranjaneyulu TOka wrote:

> Hi All,
>
> I am trying to rotate an image with given angle but  really could not
> manage to work this properly... Below is the piece of code i have ported
> from ImageJ to rotate arbitrarly.
>
> for example here
>
> destWidth = 464 and destHeight = 464
>
> source size is uWidth = 405 and uHeight = 227.
>
>
>  double centerX, centerY, angleRadians, ca, sa, tmp1, tmp2, tmp3, tmp4,
> xs, ys, dwidth, dheight;
>  int index, x, y;
>  centerX = destWidth /2.0;
>  centerY = destHeight / 2.0;
>
>  angleRadians = -angle/(180.0/3.14159265358979323846);
>  ca = cos(angleRadians);
>  sa = sin(angleRadians);
>  tmp1 = centerY*sa-centerX*ca;
>  tmp2 = -centerX*sa-centerY*ca;
>  dwidth = uWidth, dheight= uHeight;
>
>  for (y=0; y<destHeight; y++)
>  {
>   index = y*destWidth*4;
>   tmp3 = tmp1 - y*sa + centerX;
>   tmp4 = tmp2 + y*ca + centerY;
>   for (x=0; x<destHeight; x++)
>   {
>    xs = x*ca + tmp3;
>    ys = x*sa + tmp4;
>    if ((xs>=-0.01) && (xs<dwidth) && (ys>=-0.01) && (ys<dheight))
>    {
>     pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 0];
>     pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 1];
>     pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 2];
>     pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 3];
>    }
>    else
>    {
>     pbOut[index++] = 0xff; pbOut[index++] = 0xff; pbOut[index++] = 0xff;
> pbOut[index++] = 0xff;
>    }
>   }
>
> With the above code, the output that i get is cropping of top-right,
> right-bottom corners. I think something problem with my output buffer
> filling procedure though am not sure.
>
> Could you plz help me to figure the issue plz? I really do not have clue
> and need your help on this.
>
>
> thanks,
> Veeru.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html