Beanshell Basics

Hi all,
I have a very basic questions about beanshell. I would like to process some images, and to do this I have to first crop them. I tried IJ.run, but this only works if I first open the image by hand.
IJ.run( name of image, “Specify…”, “width=1024 height =1024 x=512 y=512”);
etc doesn’t work, and just putting IJ.open( name of image) before doesn’t work either, because bsh closes the image before processing the next line.

Here is a small example which opens an example image, makes a copy, a ROI selection and then crops the image:

imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
imp.show();
imp2 = imp.duplicate();
imp2.setRoi(61,51,157,119);
IJ.run(imp2, "Crop", "");
imp2.show();
1 Like

Thanks so much! It really helped :slight_smile: