Login  Register

Re: zooming on a region

Posted by audrey karperien-2 on Dec 05, 2007; 6:56pm
URL: http://imagej.273.s1.nabble.com/zooming-on-a-region-tp3697839p3697841.html

Hi.  Wayne recently helped me with the below plugin, which I used to make some animations for a presentation.  It zooms in until the selected area is the full screen size then you save the stack of images as an animation in ImageJ.  I have been saving the stack as avi or animated gif files, but in the code here I slipped in a line that will also save it as an avi into the ij path, which you can uncomment // IJ.saveAs("AVI... ", "myfileZoom.avi") and change to save where you want.  For animated gifs, I use the gif stack writer plugin.  This code zooms from the onscreen image down to the selection size, using a gradient set differently each time, which is what I needed, but Wayne wrote some code that zooms starting with the selection and the way he did it is smoother and faster, I just haven't fully implemented it in this yet; you can find it in the list a few weeks back or email me and I will find it for you. Hope this helps.

import ij.*;
import ij.gui.Roi;
import ij.gui.StackWindow;
import ij.plugin.*;
import ij.process.ImageProcessor;

public class zoomer_ implements PlugIn {

public int height = 100;
public int width = 100;
public int roiheight = 100;
public int roiwidth = 100;

String NAME;
    public void run(String arg)
        {
            ImagePlus img=IJ.getImage();
            height=img.getHeight();
            width=img.getWidth();
            Roi roi = img.getRoi();
            if (roi==null)
            {
                IJ.showMessage("Please select an roi then try again");
                return;
            }
                     
            String NAME=img.getTitle();
            double scale=80;
            scale=IJ.getNumber("Rate of Scaling (%)?", (double)scale);
            roiwidth=(int)roi.getBounds().getWidth();
            roiheight=(int)roi.getBounds().getHeight();
            int w =(int)( width*(scale/100f));
            int h = (int)( height*(scale/100f));
           
            int cx = (int)roi.getBounds().getCenterX();
            int cy = (int)roi.getBounds().getCenterY();
           //scale it each time by the same amount
            //the user determines the amount by
            //inputting a number for the rate of scaling
            //e.g., if the rate of scaling is 50,
            //then the roi is always 50% of the current size
                       
            ImageStack s= new ImageStack(width, height);  
           ImageProcessor ip = img.getProcessor();
           ip.snapshot();
           for (int i = w, j = h;
                (i > roiwidth)&&(j>roiheight);
                i=(int)( i*(scale/100f)), j=(int)( j*(scale/100f)))
                {
                    IJ.makeRectangle
                            (cx-i/2,cy-j/2, i, j);                      
                    IJ.run("Size...",
                            "width="+width+
                            " height="+height+
                            " constrain interpolate");
                    String name=NAME+i;
                    if(WindowManager.getCurrentImage().getHeight()!=height||
                            WindowManager.getCurrentImage().getWidth()!=width)
                    IJ.run("Canvas Size...", "width="+width+
                           " height="+height+" position=Center");    
                    s.addSlice(name, img.getProcessor().duplicate());
                               // WindowManager.getCurrentImage().getProcessor());
                    IJ.run("Revert");              
                }
            IJ.run("Revert");
            img.setRoi(roi);
            StackWindow sw=new StackWindow(new ImagePlus(NAME+"Zoom", s));
            sw.setVisible(true);
   // IJ.saveAs("AVI... ", "myfileZoom.avi");
   
        }    

   
}



----- Original Message ----
From: Younes Leysi Derilou <[hidden email]>
To: [hidden email]
Sent: Wednesday, December 5, 2007 7:11:28 AM
Subject: zooming on a region

Hello ImageJ Users,

I am wondering if there is a pluging to do zooming in/out in an image
 or
image stack and save this action as a movie.
any help is highly appreciated in advance.

Sincerely,
Younes