Login  Register

Problems in completing a plugin

Posted by kiran kumar-2-3 on Aug 30, 2005; 8:11pm
URL: http://imagej.273.s1.nabble.com/Re-automated-process-tp3704941p3704943.html

Hello Group,
 
    I am writing a plugin for analysis and resolution of scanning electron microscope and about to release it to the group but I have few problems in completing the work. I would really appreciate if someone can help me in fixing the following problems.
 
Firstly, I am using Roimanager class and its functions for drawing multiple ROI's over an image.I get a strange error of  "Active image doesnt have a selection" when run my code for first time but for the second and third times it doesnt show up......i have pasted my code at end of this message.
 
 Secondly, I used decimal format class for rounding the float results to three decimal places but i couldnt see clearly the third number when i used showMessage command to display results and the third decimal point appears blurred.....
 
 Thirdly, I am calling threshod window for allowing the user to adjust the threshold of an FFT image, I used the wait command to give user limited time to adjust but i need to provide them unlimited time........how can i do it???
 
  I have attached the code of my plugin end of this message.
 
Thanks,
 
Regards,
 
Kiran Kumar
 
 
Here is the code of my plugin................
 
import ij.*;      //1
import ij.plugin.PlugIn;
import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import java.awt.*;
import ij.gui.*;
import ij.gui.OvalRoi;
import java.lang.Math;
import java.util.Random;
import java.awt.Polygon;
import java.text.DecimalFormat;    //10
import ij.WindowManager;
import ij.IJ;
import ij.plugin.frame.RoiManager;
import ij.process.EllipseFitter;    
import ij.measure.*;
import ij.plugin.filter.*;
 
public class smart_ implements PlugInFilter {
 ImagePlus imp;     //20
 OvalRoi r1;
 
 DecimalFormat df = new DecimalFormat("0.###");
 public int setup(String arg, ImagePlus imp) {
  //this.imp = imp;
  if (arg.equals("about"))  //30
   {showAbout(); return DONE;}
  return DOES_8G+DOES_STACKS+SUPPORTS_MASKING;
 }
 public void run(ImageProcessor ip) {
 
  IJ.showMessage(" Scanning Microscope Analysis and Resolution Testing " );
 
  GenericDialog gd = new GenericDialog("Select one Method ");
  gd.addCheckbox("Manual Resolution Test ",true);
  gd.addCheckbox("Automeasure Resolution ",false);
  gd.addCheckbox("Resolution from Two Images ",false);
  gd.addCheckbox("S/N Ratio ",false);
  gd.showDialog();
  if(gd.wasCanceled()) {
   IJ.error("PlugIn canceled!");
   return;}
 
  boolean a,b,c,d;
  a = gd.getNextBoolean();
  b = gd.getNextBoolean();
  c = gd.getNextBoolean();
  d = gd.getNextBoolean();
 
  if(a== true & b == true | c == true & d == true | a== true & c == true | a== true & d == true | b== true & c == true | b== true & d == true ) {
  IJ.error("Select only one method ");
  return;}
  else if(a == true)
  Manual_Resolution(ip);
  else if(b == true)
  Automeasure_Resolution(ip);
  else if(c == true)
  TwoImage_Resolution(ip);
  else if(d == true)
  SNR_Calculation(ip);
 }
      //40
   
 
 
   public void Manual_Resolution(ImageProcessor ip) {
  Rectangle roi = ip.getRoi();
 
  //IJ.showMessage("width"+roi.width);
 
  if((roi!=null)&&(roi.width == roi.height))  {
  //RoiManager rm = new RoiManager();
  int PixCount = ip.getWidth();
  double widthum = IJ.getNumber("Enter Image width in um",1.0); /* get input from the user */
  IJ.showMessage("widthum="+widthum);
  double Pixperum = PixCount/widthum;
  IJ.showMessage("pixperum="+Pixperum);
  double Pixsize = 1000/Pixperum;
   
  int centerx = roi.x+roi.width/2;    /* setting center of ROI  */
  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();  //70
  ip = imp.getProcessor();
  IJ.showMessage("Adjust threshold in 18 msecs");
  IJ.run("Threshold...");
  IJ.wait(18000);       //80
  IJ.showMessage("Threshold is done");
  RoiManager rm = new RoiManager();
  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));  //90
  IJ.wait(100);
  rm.runCommand("Add");
  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);  //100
  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");
       IJ.selectWindow("Threshold");
               IJ.run("Close");
   }
 
  else {
        IJ.error("Select a square ROI of sizes 128,256,512 ");
   IJ.error("PlugIn canceled!");
   return;}
 
 }
 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com