Hi all,
I have a simple problem considering image rotation by using ImageProcessor rotate(double angle) method. Ill first try to describe what I want to do and in the end I have a piece of the code. Programming is a quite new thing for me, so there might be some large logical disasters in the code. In the beginning I have two 8-bit images, acquired at different time points. In the latter image the objects have rotated and I need to find an angle of this rotation. So, I have constructed a method what I call. In this method I rotate the second image in 1 deg increments (form 1 to 360 deg) and try to find the angle which gives maximum crosscorrelation between the images. The method then returns this angle as a double value. The next thing what I would like to do is just rotation of the original image by using this returned value. However this doesnt work, since the rotation method, which returns the angle, rotates the original data. Also, the second, rotated image looks quite weird. I would be interested to know if there is a better method for this rotation and also if there is a simple way to "clone" ImagePlus objects. I tried to go through the API but with poor results. code: . . . AlignImages align = new AlignImages(); ImagePlus openedImage1 = openImage(); ImagePlus openedImage2 = openImage(); /* Next Ill try to find the angle of the rotation by using findAngle method. In the findAngle I rotate the openedImage2 in 1 deg increments from 1-360 deg. The angle with maximum correlation between the images is returned. */ double angle = align.findAngle(openedImage1, openedImage2); /* Next I would like to rotate the original openedImage2 with an angle received from the findAngle-method */ openedImage2.getProcessor().rotate(angle); openedImage1.show(); openedImage2.show(); . . . Best Regards, Teemu Ihalainen, Ph.D. ------------------------------------------------- University of Jyväskylä Department of Biological and Environmental science Molecular Biology, room B 212.2 Survontie 9 B2, 40500 Jyväskylä, Finland Tel. +358-14-260 4158 Mobile +358-50-518 7422 ------------------------------------------------- |
Hi Teemu,
ImagePlus has no clone method that I am aware of. Anyhow, in a plugin I would rather operate on the ImageProcessor level, at least as long as you don't need the overhead of an ImagePlus (Composite images are an exception). ImageProcessor has a duplicate() method. In your case, it might be even more simple: do a 'snapshot' before rotating, and after trying out one rotation, do a reset() operation on the ImageProcessor; this should revert it to the state before the rotation operation. Make sure you set the desired interpolation method of your ImageProcessor. Apart from technical details: You need to know the rotation axis (unless you do a 2D correlation and find the maximum; but this will be quite slow unless you can do it in the fourier domain). Don't forget to restrict the comparison with the rotated image to the region where it contains valid data (no background that was rotated into view). If you don't care about the lack of sources and the restrictions of use, the TurboReg plugin might offer an alternative (type 'rigid body'). Depending on the type of image, you it might be good enough to try registration with a few starting values for the rotation (4 to 20); it will care about the translation as long as it is not too large. Michael ________________________________________________________________ On 29 Apr 2010, at 11:15, Teemu Ihalainen wrote: > Hi all, > > I have a simple problem considering image rotation by using > ImageProcessor rotate(double angle) method. Ill first try to > describe what I want to do and in the end I have a piece of the > code. Programming is a quite new thing for me, so there might be > some large “logical disasters” in the code. > > In the beginning I have two 8-bit images, acquired at different > time points. In the latter image the objects have rotated and I > need to find an angle of this rotation. So, I have constructed a > method what I call. In this method I rotate the second image in 1 > deg increments (form 1 to 360 deg) and try to find the angle which > gives maximum crosscorrelation between the images. The method then > returns this angle as a double value. > > The next thing what I would like to do is just rotation of the > original image by using this returned value. However this doesnt > work, since the rotation method, which returns the angle, rotates > the original data. Also, the second, rotated image looks quite weird. > > I would be interested to know if there is a better method for this > rotation and also if there is a simple way to "clone" ImagePlus > objects. I tried to go through the API but with poor results. > > > code: > . > . > . > AlignImages align = new AlignImages(); > > ImagePlus openedImage1 = openImage(); > ImagePlus openedImage2 = openImage(); > > /* > Next Ill try to find the angle of the rotation by using findAngle > method. In the findAngle I rotate the openedImage2 in 1 deg > increments from 1-360 deg. > The angle with maximum correlation between the images is returned. > */ > > double angle = align.findAngle(openedImage1, openedImage2); > > > /* > Next I would like to rotate the original openedImage2 with an angle > received from the findAngle-method > */ > > openedImage2.getProcessor().rotate(angle); > > openedImage1.show(); > openedImage2.show(); > > . > . > . > > > Best Regards, > Teemu Ihalainen, Ph.D. > ------------------------------------------------- > University of Jyväskylä > Department of Biological and Environmental science > Molecular Biology, room B 212.2 > Survontie 9 B2, 40500 Jyväskylä, Finland > Tel. +358-14-260 4158 > Mobile +358-50-518 7422 > ------------------------------------------------- |
Free forum by Nabble | Edit this page |