ThreeB 1.1
Public Member Functions | Package Attributes

ImageJ plugin class. More...

Inherits PlugInFilter.

List of all members.

Public Member Functions

int setup (String arg_, ImagePlus img)
void run (ImageProcessor ip)

Package Attributes

ImagePlus window
ByteProcessor mask
String arg

Detailed Description

ImageJ plugin class.

Definition at line 132 of file three_B.java.


Member Function Documentation

int three_B::setup ( String  arg_,
ImagePlus  img 
) [inline]

Definition at line 138 of file three_B.java.

References arg, and window.

                                                 {
        window = img;
        arg=arg_;

        return ROI_REQUIRED + SUPPORTS_MASKING + STACK_REQUIRED +NO_CHANGES + DOES_16 + DOES_32 + DOES_8G;
    }
void three_B::run ( ImageProcessor  ip) [inline]

Definition at line 145 of file three_B.java.

References SPair::a, arg, SPair::b, Util::getFileName(), mask, Util::read(), and window.

                                       {



        //Load the config file contents
        Reader cfgstream = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("multispot5.cfg"));
        String cfg = Util.read(cfgstream);

        try{
            cfgstream.close();
        }
        catch(IOException close_err){
            Toolkit.getDefaultToolkit().beep();
            ij.IJ.showStatus("Error reading config file.");
            return;
        }

        //Some basic error checking if reading of the config file from
        //the JAR archive fails.
        if(cfg == "")
        {
            Toolkit.getDefaultToolkit().beep();
            ij.IJ.showStatus("Error reading config file.");
            return;
        }


        //The image from getMask() is only the size of the ROI
        //We need it to be congruent with the original image, in order
        //to work with the C++ code.
        mask = new ByteProcessor(ip.getWidth(), ip.getHeight());

        int x = ip.getRoi().x;
        int y = ip.getRoi().y;
        
        //Rectangular selections do not have a mask set, so we get
        //a null pointer exception when we try to copy.
        //So, we have to manually set the pixels, rather than just
        //copy them
        try{
            mask.copyBits(ip.getMask(), x, y, Blitter.COPY);
        }
        catch(NullPointerException e)
        {
            for(int r=0; r < ip.getRoi().height; r++)
                for(int c=0; c < ip.getRoi().width; c++)
                    mask.set(c+x, r+y, 255);
        }
        
        //Count the number of set pixels in the mask. This is used to 
        //warn the user if the number is not within a reasonable range.
        int count=0;
        for(int r=0; r < mask.getHeight(); r++)
            for(int c=0; c < mask.getWidth(); c++)
                if(mask.get(c, r) != 0)
                    count ++;


        //The non-config file parameters are the range of frames to  operate on
        //and the pixel size in nm (the config works in terms of FWHM in pixels).
        //These have to be sepficied whether the basic or advanced dialog is used.
        int  firstfr;
        int lastfr;
        double pixel_size_in_nm;

        ImageStack s = window.getStack();

        if(arg.equals("advanced"))
        {
            AdvancedDialog ad = new AdvancedDialog(cfg, s.getSize());
            if(!ad.wasOKed())
                return;
            cfg = ad.getTextArea1().getText();
            

            /*pixel_size_in_nm = ad.getPixelSize();
            firstfr = ad.getFirstFrame();
            lastfr = ad.getLastFrame();*/


            pixel_size_in_nm = ad.getNextNumber();
            firstfr = (int)ad.getNextNumber();
            lastfr = (int)ad.getNextNumber();
        }
        else
        {
            ThreeBDialog gd = new ThreeBDialog(count, mask.getWidth()*mask.getHeight(), s.getSize());

            gd.showDialog();
        
            if(!gd.wasOKed())
                return;

            /*final double fwhm = gd.getFWHM();
            pixel_size_in_nm = gd.getPixelSize();
            final int initial_spots = gd.getSpots();
            firstfr = gd.getFirstFrame();
            lastfr = gd.getLastFrame();*/

            //We have to use getNextNumber, otherwise macro recording does not work.
            final double fwhm = gd.getNextNumber();
            pixel_size_in_nm = gd.getNextNumber();
            final int initial_spots = (int)gd.getNextNumber();
            firstfr = (int)gd.getNextNumber();
            lastfr = (int)gd.getNextNumber();


            //Compute the parameters of the log-normal prior such that the mode
            //matches the size of the spots.
            final double sigma = (fwhm / pixel_size_in_nm) / (2*Math.sqrt(2*Math.log(2)));
            final double blur_sigma=0.1;

            //s = exp(mu-sig^2)
            //ln s = mu - sig^2
            //mu = ln s + sig^2

            final double blur_mu = Math.log(sigma) + blur_sigma*blur_sigma;
            
            //Initialized from the current time.
            Random rng = new Random();
            //


            //Append stuff to the config file now. This will be parsed later in C++.
            cfg = cfg + "placement.uniform.num_spots=" + Integer.toString(initial_spots) + "\n"
                      + "blur.mu="    + Double.toString(blur_mu) + "\n" 
                      + "blur.sigma=" + Double.toString(blur_sigma) + "\n"
                      + "seed=" + Integer.toString(rng.nextInt(16777216)) + "\n";

        }
        
        //Acquire a filename to save moderately safely.
        SPair f = Util.getFileName(window.getTitle());
        final String fname = f.a;
        final String fullname = f.b;

        if(fname!= null)
        {
            //Create the 3B runner and the control panel, then execute the control panel in the
            //GUI thread.
            final Rectangle roi = ip.getRoi();
            final double pixel_size_in_nm_ = pixel_size_in_nm;
            final ThreeBRunner tbr = new ThreeBRunner(mask, s, cfg, fullname, firstfr, lastfr);

            SwingUtilities.invokeLater(
                    new Runnable() {
                            public void run() {
                                    new EControlPanel(roi, pixel_size_in_nm_, fname, tbr);
                            }
                    }
            );

        }
    }

Member Data Documentation

ImagePlus three_B::window [package]

Definition at line 134 of file three_B.java.

Referenced by run(), and setup().

ByteProcessor three_B::mask [package]

Definition at line 135 of file three_B.java.

Referenced by run().

String three_B::arg [package]

Definition at line 136 of file three_B.java.

Referenced by run(), and setup().


The documentation for this class was generated from the following file: