Posted by
Jon Harman-3 on
URL: http://imagej.273.s1.nabble.com/Different-behavior-of-plugin-called-from-macro-tp5014701p5014704.html
Hi,
Thanks for the advice. I now see that my problem stems from the
following code:
iw = trans.getWindow();
WindowManager.setCurrentWindow(iw);
IJ.run("Scale...", "x=- y=- width=" + rotatew + " height=" + newh +"
interpolation=Bilinear average create title=Transformed1");
ImagePlus trans1 = WindowManager.getCurrentImage();
I want to use the scale command in a mode that creates a new image.
(Otherwise the old image is cropped after scaling.) I think my problem
is in getting the new imagePlus.
Jon
On 10/21/2015 10:27 AM, Michael Schmid wrote:
> Hi Jon,
>
> when selecting an image, use the WindowManager.setCurrentWindow function, instead of bringing an image to the foreground (which depends on the gui).
> Even better, it should be possible to address the ImagePlus directly:
>
> IJ.run(imp, "Crop", null);
>
> where imp is your ImagePlus (named 'trans'?)
>
> Michael
> ________________________________________________________________
> On Oct 21, 2015, at 19:12, Jon Harman wrote:
>
>> Hi,
>> I have a plugin that as part of a long sequence of image manipulations crops an image. This works fine when run from the plugins menu. When I run the plugin from a macro the crop fails, saying an area selection is required. When it fails it displays the image with a rectangle ROI which is the wrong size.
>> The plugin is then permanently broken until I restart ImageJ. Then it works fine again.
>>
>> This is a mystery to me. Hope someone can help. my code is:
>>
>> Polygon corners = new Polygon();
>> for(int i = 0; i < 4; i++) corners.addPoint(cor[i].x,cor[i].y);
>> corners.addPoint(cor[0].x, cor[0].y);// close the polygon
>> PolygonRoi corroi = new PolygonRoi(corners, Roi.POLYGON);
>>
>> iw = trans.getWindow();
>> iw.toFront();
>> trans.setRoi(corroi);
>> trans.show();
>> IJ.run("Crop");
>>
>> Jon
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html