Rotation in a Macro

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

Rotation in a Macro

Flopi
Dear all,
I'm a facing a recurrent problem in my macro. I am trying to rotate an image with the following code :

function Rotation(settings)
{
        rotationOK = false;
        print("Initial value of rotation angle ="+settings[21]);
       
        while(rotationOK == false)
        {
                ChosenAngle = getNumber("Enter the angle of the desired rotation (in degrees)",0);
                run("Rotate...", "angle = "+ChosenAngle+" grid = 1 interpolation = Bilinear");

                rotationOK = getBoolean("Are you satisfied with the rotation ?");
               
                if(rotationOK == false)
                {
                        BackAngle = 360 - ChosenAngle;
                        run("Rotate...","angle = "+BackAngle+" grid = 1 interpolation = Bilinear");//On retourne à l'image précédente
                }
        }
        //If the user is satisfied with the results, the rotation angle is recorded in settings 21
        settings[21] = ChosenAngle;
}

My problem is the following. It actually worked once. But now that I am trying to do it again, it doesnt work. Both run("Rotate..."  are not taking any of the angle but a constant one depending on what was the last used. For example, the default angle in my ImageJ is 15. So if I open ImageJ, start the macro, and enter any angle, the image will be rotated by 15 no matter what I entered. And if I choose 'not statisfied', instead of going back to the previous image, it rotates again of 15...

Any ideas ?

Thanks a lot
Reply | Threaded
Open this post in threaded view
|

Re: Rotation in a Macro

Herbie
Flopi,

there appear to be several flaws in your macro code.

What about something like the following (be aware of line breaks!):

s = newArray(22);
s[21] = 15;
Rotation(s);
print("Initial value of rotation angle ="+s[21]);

function Rotation(settings)
{
rotationOK = false;
print("Initial value of rotation angle ="+settings[21]);
snapshot();
do {
ChosenAngle = getNumber("Enter the rotataion angle in degrees",0);
print( "Angle = " + ChosenAngle);
run("Rotate...", "angle="+ChosenAngle+" grid=1 interpolation=Bilinear");
rotationOK = getBoolean("Are you satisfied with the rotation ?");
if(rotationOK == false) {
run("Undo");
} while (rotationOK == false);
settings[21] = ChosenAngle;
}

HTH

Herbie

:::::::::::::::::::::::::::::::::::
Am 02.11.15 um 13:58 schrieb Flopi:

> Dear all,
> I'm a facing a recurrent problem in my macro. I am trying to rotate an image
> with the following code :
>
> function Rotation(settings)
> {
> rotationOK = false;
> print("Initial value of rotation angle ="+settings[21]);
>
> while(rotationOK == false)
> {
> ChosenAngle = getNumber("Enter the angle of the desired rotation (in
> degrees)",0);
> run("Rotate...", "angle = "+ChosenAngle+" grid = 1 interpolation =
> Bilinear");
>
> rotationOK = getBoolean("Are you satisfied with the rotation ?");
>
> if(rotationOK == false)
> {
> BackAngle = 360 - ChosenAngle;
> run("Rotate...","angle = "+BackAngle+" grid = 1 interpolation =
> Bilinear");//On retourne à l'image précédente
> }
> }
> //If the user is satisfied with the results, the rotation angle is recorded
> in settings 21
> settings[21] = ChosenAngle;
> }
>
> My problem is the following. It actually worked once. But now that I am
> trying to do it again, it doesnt work. Both run("Rotate..."  are not taking
> any of the angle but a constant one depending on what was the last used. For
> example, the default angle in my ImageJ is 15. So if I open ImageJ, start
> the macro, and enter any angle, the image will be rotated by 15 no matter
> what I entered. And if I choose 'not statisfied', instead of going back to
> the previous image, it rotates again of 15...
>
> Any ideas ?
>
> Thanks a lot

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Rotation in a Macro

Flopi
Hi,
Thanks a lot for your answer. The "undo" is indeed much better than the rotation back. However it did not solve my problem. Whatever the angle I enter while the macro is running, the system uses the default one. And the output of the print are giving what I expect... I am at a loss....
Reply | Threaded
Open this post in threaded view
|

Re: Rotation in a Macro

Herbie
Flopi,

did you really copy my code?

My code does what I think you would expect.

Best

Herbie

:::::::::::::::::::::::::::::::::::
Am 03.11.15 um 15:14 schrieb Flopi:

> Hi,
> Thanks a lot for your answer. The "undo" is indeed much better than the
> rotation back. However it did not solve my problem. Whatever the angle I
> enter while the macro is running, the system uses the default one. And the
> output of the print are giving what I expect... I am at a loss....
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Rotation-in-a-Macro-tp5014810p5014830.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Rotation in a Macro

Flopi
Ok, now it works. I actually overlooked your initialization of the rotation angle which is probably the reason.
Thank you very much for your help.