set scale without IJ.run

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

set scale without IJ.run

Mohamed Tleis
Dear folks,

With your help I have wrote the following code which is working
successfully, Now I want to set the scale to use pixel units instead of
original calibrated image, previously I used:

IJ.run(imp, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");


My new code (without using IJ.run :

        int options = ParticleAnalyzer.SHOW_OUTLINES;

        int measurements = Analyzer.AREA + Analyzer.MEAN +
                           Analyzer.PERIMETER
                            + Analyzer.CIRCULARITY
                            + Analyzer.INTEGRATED_DENSITY
                            + Analyzer.STD_DEV;


        ResultsTable rt2 = new ResultsTable();
        ParticleAnalyzer pa = new ParticleAnalyzer(options, measurements,
rt2, 5, Double.MAX_VALUE);
        pa.analyze(finIm);

        ImagePlus drawIm = pa.getOutputImage();
        finIm.show();
        finIm.setTitle("Fin Im");
        drawIm.show();
        IJ.save(finIm, imDir + "_" + "segmentation\\Drawing Of "+ title
+".tif" );

Best Regards,
Mohamed Tleis
Reply | Threaded
Open this post in threaded view
|

Re: set scale without IJ.run

Michael Schmid
Hi Mohamed,

the image calibration is stored in a Calibration object. If you don't have calibration of the image values (brightness) or you don't care about it, simply set it to null for your ImagePlus (I assume here that it has the name imp; it might be named finIm in your case):

  imp.setCalibration(null);

If you want to modify only a few items of the Calibration, use imp.getCalibration() and modify its fields; this will affect the ImagePlus (the fields of Calibration are public, so you can write to them directly). In your case you need to set pixelWidth & pixelHeight to 1 and unit to "pixel". See the source code:

  http://rsbweb.nih.gov/ij/source/ij/measure/Calibration.java
  http://fiji.sc/cgi-bin/gitweb.cgi?p=imagej.git;a=blob;f=ij/measure/Calibration.java

Michael
________________________________________________________________
On Jan 23, 2012, at 16:07, Mohammed Tlais wrote:

> Dear folks,
>
> With your help I have wrote the following code which is working
> successfully, Now I want to set the scale to use pixel units instead of
> original calibrated image, previously I used:
>
> IJ.run(imp, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
>
>
> My new code (without using IJ.run :
>
>        int options = ParticleAnalyzer.SHOW_OUTLINES;
>
>        int measurements = Analyzer.AREA + Analyzer.MEAN +
>                           Analyzer.PERIMETER
>                            + Analyzer.CIRCULARITY
>                            + Analyzer.INTEGRATED_DENSITY
>                            + Analyzer.STD_DEV;
>
>
>        ResultsTable rt2 = new ResultsTable();
>        ParticleAnalyzer pa = new ParticleAnalyzer(options, measurements,
> rt2, 5, Double.MAX_VALUE);
>        pa.analyze(finIm);
>
>        ImagePlus drawIm = pa.getOutputImage();
>        finIm.show();
>        finIm.setTitle("Fin Im");
>        drawIm.show();
>        IJ.save(finIm, imDir + "_" + "segmentation\\Drawing Of "+ title
> +".tif" );
>
> Best Regards,
> Mohamed Tleis