ROI manager help

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

ROI manager help

Kiran Kumar-13
Hi list,

  I wrote a small plugin that takes FFT of an imaged, followed by
thresholding and finally draws several circular ROI of different radius on
FFT image. But  I come across a problem with ROI manager that throws an
error "The active image does not have selection"....I couldnt figure
out.....could anyone please help me out....here is my routine

thanks

regards
kiran

public void Manual_Resolution(ImageProcessor ip) {

        Rectangle roi = ip.getRoi();
       
        rm = new RoiManager();
        int PixCount = ip.getWidth();
       
        /* get input from the user */

                double widthum = IJ.getNumber("Enter Image width in um",1.0);  
        double Pixperum = PixCount/widthum;
        double Pixsize = 1000/Pixperum;

        /* setting center of ROI  */  

        int centerx = roi.x+roi.width/2;              
        int centery = roi.y+roi.height/2;
        IJ.doCommand("FFT");
        IJ.wait(100);
        double rfactor = (1000*roi.width)/Pixperum;
        double rUser[] = { 0.1, 0.2, 0.3, 0.5, 0.7, 1, 1.5, 2, 2.5, 3, 4, 5,
7, 10, 20, 30, 50, 70, 100, 150 };        
        IJ.wait(100);
       
       
        /*  Draw the calibration rings */
       
        ImagePlus imp = WindowManager.getCurrentImage();      
        ip = imp.getProcessor();
       
        IJ.showMessage("Adjust threshold & to continue close the window ");
        IJ.runPlugIn("Threshold_2","");
        IJ.run("Unlock Image");
        IJ.run("Threshold", "thresholded remaining black");
       

        for( int m = 1; m<=20; m++) {
        int n = 20 - m;
        int radius = (int) Math.round((500*roi.width)/(Pixperum*rUser[n]));
        if((radius<roi.width/2) & (radius>roi.width/10)) {
        int x1 = (int) roi.width/2-radius;
        int y1 = (int) roi.height/2-radius;
        imp.setRoi( new OvalRoi(x1,y1,2*radius,2*radius,imp));      
        IJ.wait(100);      
        rm.runCommand("Add & Draw");
           
           
        /* Annotate the rings */
       
        double theta = 1.57*(1-Math.random());
        int radX = (int) Math.round(radius * Math.cos(theta)-1);
        int radY = (int) Math.round(radius * Math.sin(theta)-1);      
        ip.moveTo(roi.width/2+radX, roi.height/2-radY);
        ip.drawString(" "+rUser[n]);
             imp.updateAndDraw();
               
        }
             
         }    
             rm.runCommand("Draw");
             String Pixsize1 = df.format(Pixsize);  
             IJ.showMessage("Pixel size (nm) =   "+Pixsize1 );  
             IJ.selectWindow("ROI Manager");
                  IJ.run("Close");
           
         
    }