Login  Register

Re: Get Calibration from DICOM stack

Posted by Andreas Jahnen on Jul 07, 2008; 6:08am
URL: http://imagej.273.s1.nabble.com/Get-Calibration-from-DICOM-stack-tp3695656p3695657.html

> I've just made the leap from macros to plugins, having got to a point
> where my macros were getting a bit unmanageable.  The learning curve is
> has been steep for the last couple of days!  Could someone please show
> me how to get the calibration (voxel dimensions and greyscale->HU) from
> my DICOM stacks to use in this simple plugin?

Dear Mike,

I think you use the ij.measure.Calibration class to do that. There are
methods like:

// to find out if a image is calibrated:
myImagePlus.getCalibration().calibrated()

// get the Calibration Coefficient:
myImagePlus.getCalibration().getCoefficients()

and so on....

Best Regards,
Andreas

-----------------------------------------------------------------
ImageJ User and Developer Conference 2008
6-7. November 2008
http://imagejconf.tudor.lu
-----------------------------------------------------------------
Andreas Jahnen  -  Ingenieur de Recherche
[hidden email]
-----------------------------------------------------------------
CRP Henri Tudor  -  http://santec.tudor.lu
2A, rue Kalchesbrück
L-1852 Luxembourg
-----------------------------------------------------------------


>
> Many thanks
>
> Mike
>
> ----------------------------------------------------
> /** Work out the centroid of a whole stack
> and each of its slices, restricted to thresholded
> pixels within an ROI */
> import java.awt.Rectangle;
> import ij.IJ;
> import ij.ImagePlus;
> import ij.ImageStack;
> import ij.process.ImageProcessor;
> import ij.plugin.filter.PlugInFilter;
> import ij.measure.Calibration;
>
> public class Stack_Centroids implements PlugInFilter {
>     protected ImageStack stack;
>
>     public int setup(String arg, ImagePlus imp) {
>         stack = imp.getStack();
>         return DOES_16 + STACK_REQUIRED + SUPPORTS_MASKING;
>     }
>
>     public void run(ImageProcessor ip) {
>         int minT = (int)ip.getMinThreshold();
>         int maxT = (int)ip.getMaxThreshold();
>         //2D centroids
>         double xc = 0; double yc = 0;
>         //3D centroids
>         double xcent = 0; double ycent = 0; double zcent = 0;
>         //pixel counters
>         double cstack = 0;
>         Rectangle r = ip.getRoi();
>         int offset, i;
>         short[] pixels;
>         int w = stack.getWidth();
>         for (int s=1;s<=stack.getSize();s++) {
>             double sumx = 0;
>             double sumy = 0;
>             double cslice = 0;
>             pixels = (short[])stack.getPixels(s);
>             for (int y=r.y; y<(r.y+r.height); y++) {
>                 offset = y*w;
>                 for (int x=r.x; x<(r.x+r.width); x++) {
>                     i = offset + x;
>                     if (pixels[i] >= minT && pixels[i] <= maxT){
>                         cslice++;
>                         sumx += x;
>                         sumy += y;
>                     }
>                 }
>             }
>             if (cslice > 0){
>                 xc = sumx/cslice;
>                 yc = sumy/cslice;
>                 xcent += xc*cslice;
>                 ycent += yc*cslice;
>                 zcent += cslice*s;
>                 cstack += cslice;
>                 IJ.write("Slice "+s+" centroid is at ("+xc+","+yc+"),
> "+cslice+" pixels contributed.");
>             } else {
>                 IJ.write("Slice "+s+": No pixels available to make a
> calculation");
>             }
>         }
>         if (cstack > 0){
>             IJ.write("3D centroid is at
> ("+xcent/cstack+","+ycent/cstack+","+zcent/cstack+")");
>         } else {
>             IJ.write("No voxels available to make a calculation");
>         }
>     }
> }