Class AlgorithmIHN3Correction

java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmIHN3Correction
All Implemented Interfaces:
ActionListener, WindowListener, Runnable, EventListener

public class AlgorithmIHN3Correction extends AlgorithmBase

N3 Inhomogeneity correction This is based on code by John G. Sled, McConnell Brain Imaging Centre, Montreal Neurological Institute, McGill University Information may be found at: http://www.bic.mni.mcgill.ca/software/N3/ Bibliography:

1. J.G. Sled, A.P. Zijdenbos, and A.C. Evans, "A non-parametric method for automatic correction of intensity non-uniformity in MRI data," IEEE Transactions on Medical Imaging, vol. 17, pp. 87-97, February, 1998.

2. J.G. Sled, A.P. Zijdenbos, and A.C. Evans, "A comparison of retrospective intensity non-uniformity correction methods for MRI," in Information Processing in Medical Imaging, pp. 459-464, 1997.

3. J.G. Sled, "A non-parametric method for automatic correction of intensity non-uniformity in MRI data," Master's thesis, McGill University, Montreal, QC, May, 1997.

The N3 method should work with any MR volume including raw (non-stereotaxic) data.

An artifact often seen in MRI is for the signal intensity to vary smoothly across an image. Variously referred to as RF inhomogeneity, shading artifact, or intensity non-uniformity, it is usually attributed to such factors as poor radio frequency(RF) field uniformity, eddy currents driven by switching of field gradients, and patient anatomy both inside and outside the field of view.

This code corrects intensity non-uniformity in MR data without requiring supervision. This method can be applied without a tissue intensity or geometric model. Described as Non-parametric Non_uniform intensity Normalization (N3), the method is independent of pulse sequence and insensitive to pathological data that might otherwise violate model assumptions. To eliminate the dependence of the field estimate on anatomy, an iterative approach is employed to estimate both the multiplicative bias field and the distribution of true tissue intensities. Preprocessing of MR data using N3 has been shown to substantially improve the accuracy of anatomical analysis techniques such as tissue classification and cortical surface extraction.


From John G. Sled's original N3 code:

 Copyright 1996, John G. Sled
 McConnell Brain Imaging Centre,
 Montreal Neurological Institute, McGill University.
 
 Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee
 is hereby granted, provided that the above copyright notice appear in all copies. The author and McGill University
 make no representations about the suitability of this software for any purpose. It is provided "as is" without
 express or implied warranty.
 

  • Field Details

    • INVERSE

      public static final int INVERSE
      inverse FFT
      See Also:
    • FORWARD

      public static final int FORWARD
      forward FFT
      See Also:
    • spline

      public static final int spline
      DOCUMENT ME!
      See Also:
    • AtA

      private float[][] AtA
      DOCUMENT ME!
    • AtAP

      private int AtAP
      DOCUMENT ME!
    • AtFP

      private int AtFP
      DOCUMENT ME!
    • UP

      private int UP
      DOCUMENT ME!
    • DP

      private int DP
      DOCUMENT ME!
    • FP

      private int FP
      DOCUMENT ME!
    • AtF

      private double[][] AtF
      DOCUMENT ME!
    • autoThreshold

      private boolean autoThreshold
      If true determines the threshold by histogram analysis. If true a VOI cannot be used and the input threshold is ignored.
    • bendingMatrix

      private float[][][][] bendingMatrix
      DOCUMENT ME!
    • binNumber

      private final int binNumber
      DOCUMENT ME!
      See Also:
    • binWidth

      private float binWidth
      Histogram bin width.
    • blockInt

      private int blockInt
      DOCUMENT ME!
    • currentOffset

      private int currentOffset
      DOCUMENT ME!
    • blurI

      private float[] blurI
      DOCUMENT ME!
    • blurR

      private float[] blurR
      DOCUMENT ME!
    • buffer

      private float[] buffer
      Buffer for original source image.
    • bW

      private final float[][] bW
      DOCUMENT ME!
    • CArray

      private float[] CArray
      DOCUMENT ME!
    • class_max

      private float class_max
      DOCUMENT ME!
    • class_min

      private float class_min
      DOCUMENT ME!
    • coef

      private double[][] coef
      DOCUMENT ME!
    • correctedBuffer

      private float[] correctedBuffer
      DOCUMENT ME!
    • d1Spline

      private float[][] d1Spline
      DOCUMENT ME!
    • DArray

      private float[][] DArray
      DOCUMENT ME!
    • denom

      private float denom
      DOCUMENT ME!
    • derivative

      private int[] derivative
      DOCUMENT ME!
    • dloc_i

      private int[] dloc_i
      DOCUMENT ME!
    • dloc_j

      private int[] dloc_j
      DOCUMENT ME!
    • domain

      private float[][] domain
      DOCUMENT ME!
    • endTol

      private float endTol
      The measure used to terminate the iterations is the coefficient of variation of change in field estimates between successive iterations.
    • entireImage

      private boolean entireImage
      Ideally the Weiner filter noise equals the white noise of the image. The performance of the N3 method is enhanced by supplying a mask for the region of interest. If true, the N3 method is applied to the entire image.
    • estimateBuffer

      private float[] estimateBuffer
      DOCUMENT ME!
    • estimateOffset

      private float estimateOffset
      DOCUMENT ME!
    • estimateScale

      private float estimateScale
      DOCUMENT ME!
    • estimateSlope

      private float estimateSlope
      DOCUMENT ME!
    • fHist

      private float[] fHist
      DOCUMENT ME!
    • fHistPaddedI

      private float[] fHistPaddedI
      DOCUMENT ME!
    • fHistPaddedR

      private float[] fHistPaddedR
      DOCUMENT ME!
    • field_floor

      private final float field_floor
      Lowest allowable field value.
      See Also:
    • fieldBuffer

      private float[] fieldBuffer
      DOCUMENT ME!
    • fieldDistance

      private float fieldDistance
      Characteristic distance over which the field varies. The distance between adjacent knots in bspline fitting with at least 4 knots going in every dimension. The default in the dialog is one third the distance (resolution * extents) of the smallest dimension.
    • fieldImage

      private ModelImage fieldImage
      DOCUMENT ME!
    • filterI

      private float[] filterI
      DOCUMENT ME!
    • filterR

      private float[] filterR
      DOCUMENT ME!
    • fIndex

      private float fIndex
      DOCUMENT ME!
    • firstMoment0

      private double firstMoment0
      DOCUMENT ME!
    • firstMoment1

      private double firstMoment1
      DOCUMENT ME!
    • fOffset

      private float fOffset
      DOCUMENT ME!
    • fwhm

      private double fwhm
      DOCUMENT ME!
    • fwhmFactor

      private double fwhmFactor
      DOCUMENT ME!
    • fwhmScale

      private double fwhmScale
      DOCUMENT ME!
    • halfBin

      private double halfBin
      DOCUMENT ME!
    • hist

      private int[] hist
      DOCUMENT ME!
    • histFactor

      private float histFactor
      DOCUMENT ME!
    • histMean

      private double histMean
      DOCUMENT ME!
    • histOffset

      private float histOffset
      DOCUMENT ME!
    • histSum

      private double histSum
      Sum of contents of hisotogram bins.
    • iLoc

      private int iLoc
      DOCUMENT ME!
    • incr

      private float incr
      DOCUMENT ME!
    • value_k

      private float value_k
      DOCUMENT ME!
    • index

      private int index
      DOCUMENT ME!
    • index1

      private int index1
      DOCUMENT ME!
    • integral

      private float[][] integral
      DOCUMENT ME!
    • interval

      private int interval
      DOCUMENT ME!
    • iters

      private int iters
      DOCUMENT ME!
    • JArray

      private double[][] JArray
      DOCUMENT ME!
    • kernelfwhm

      private float kernelfwhm
      Width of deconvolution kernel used to sharpen the histogram. Larger values give faster convergence while smaller values give greater accuracy.
    • knots

      private float[][] knots
      DOCUMENT ME!
    • lambda

      private float lambda
      DOCUMENT ME!
    • loc

      private float loc
      DOCUMENT ME!
    • locations

      private int[] locations
      DOCUMENT ME!
    • logBuffer

      private float[] logBuffer
      Log transformed data.
    • logOffset

      private float logOffset
      If minimum value of shrunken buffer invalid input: '<' 1.0f, amount that must be added to make it 1.0f. Otherwise == 0.0f.
    • lower

      private int[] lower
      DOCUMENT ME!
    • mask

      private BitSet mask
      DOCUMENT ME!
    • maxIters

      private int maxIters
      Maximum number of iterations.
    • momentI

      private float[] momentI
      DOCUMENT ME!
    • momentR

      private float[] momentR
      DOCUMENT ME!
    • nArray

      private int[] nArray
      Number of basis functions in each dimension.
    • nBins

      private int nBins
      Number of histogram bins for shrunken buffer.
    • nDimensions

      private int nDimensions
      DOCUMENT ME!
    • newDim

      private int[] newDim
      DOCUMENT ME!
    • newRes

      private float newRes
      DOCUMENT ME!
    • newResol

      private float[] newResol
      DOCUMENT ME!
    • newSliceSize

      private int newSliceSize
      DOCUMENT ME!
    • newVolSize

      private int newVolSize
      DOCUMENT ME!
    • nMax

      private int nMax
      DOCUMENT ME!
    • noise

      private float noise
      Noise used in Weiner filter.
    • nProduct

      private int nProduct
      DOCUMENT ME!
    • four

      private int four
      DOCUMENT ME!
    • offset

      private int offset
      DOCUMENT ME!
    • offset1

      private int offset1
      DOCUMENT ME!
    • offset2

      private int offset2
      DOCUMENT ME!
    • offsetSp

      private int[][] offsetSp
      DOCUMENT ME!
    • offsetStep

      private int offsetStep
      DOCUMENT ME!
    • first

      private int first
      DOCUMENT ME!
    • last

      private int last
      DOCUMENT ME!
    • order

      private int order
      DOCUMENT ME!
    • orgDim

      private int[] orgDim
      DOCUMENT ME!
    • orgResol

      private final float[] orgResol
      Distance per pixel in millimeters.
    • padded_size

      private int padded_size
      DOCUMENT ME!
    • pLocation

      private int pLocation
      DOCUMENT ME!
    • pLocation2

      private int pLocation2
      DOCUMENT ME!
    • pValue

      private int pValue
      DOCUMENT ME!
    • pDloc_i

      private int pDloc_i
      DOCUMENT ME!
    • pDloc_j

      private int pDloc_j
      DOCUMENT ME!
    • product

      private float product
      DOCUMENT ME!
    • pSpline

      private int pSpline
      DOCUMENT ME!
    • pOffset

      private int pOffset
      DOCUMENT ME!
    • region

      private int region
      DOCUMENT ME!
    • residueBuffer

      private float[] residueBuffer
      DOCUMENT ME!
    • sBuffer

      private float[] sBuffer
      Buffer for sampled image.
    • scale

      private float scale
      DOCUMENT ME!
    • shrink

      private float shrink
      The factor by which the data is subsampled to a lower resolution in estimating the slowly varying non-uniformity field. Reduce sampling in the finest sampling direction by the shrink factor. Reduce other sampling directions only if resolution is less than shrink times original minimum resolution. Uses nearest neighbor resampling.
    • sizeC

      private int sizeC
      DOCUMENT ME!
    • sliceSize

      private int sliceSize
      DOCUMENT ME!
    • slope

      private double slope
      DOCUMENT ME!
    • smallN

      private int[] smallN
      DOCUMENT ME!
    • sMask

      private BitSet sMask
      Mask for shrunken buffer.
    • sMax

      private float sMax
      Maximum value of shrunken buffer.
    • sMin

      private float sMin
      Minimum value of shrunken buffer.
    • sourceMin

      private float sourceMin
      DOCUMENT ME!
    • sourceMax

      private float sourceMax
      DOCUMENT ME!
    • spline_lambda

      private final float spline_lambda
      DOCUMENT ME!
      See Also:
    • spline_subsample

      private final float spline_subsample
      DOCUMENT ME!
      See Also:
    • sqrtNum

      private double sqrtNum
      DOCUMENT ME!
    • start

      private int start
      DOCUMENT ME!
    • length

      private int length
      DOCUMENT ME!
    • mid

      private int mid
      DOCUMENT ME!
    • startK

      private float startK
      DOCUMENT ME!
    • stddev

      private float stddev
      DOCUMENT ME!
    • mean

      private float mean
      DOCUMENT ME!
    • numVoxels

      private float numVoxels
      DOCUMENT ME!
    • sumValue

      private float sumValue
      DOCUMENT ME!
    • sum2Value

      private float sum2Value
      DOCUMENT ME!
    • step

      private int[] step
      DOCUMENT ME!
    • Sx

      private double Sx
      DOCUMENT ME!
    • Sy

      private double Sy
      DOCUMENT ME!
    • Sz

      private double Sz
      DOCUMENT ME!
    • temp

      private float temp
      DOCUMENT ME!
    • temp2

      private float temp2
      DOCUMENT ME!
    • threshold

      private float threshold
      Values at less than threshold are treated as part of the background.
    • tiflat

      private int tiflat
      DOCUMENT ME!
    • tiindex

      private int[] tiindex
      DOCUMENT ME!
    • tistep

      private int[] tistep
      DOCUMENT ME!
    • tjflat

      private int tjflat
      DOCUMENT ME!
    • tjindex

      private int[] tjindex
      DOCUMENT ME!
    • tjstep

      private int[] tjstep
      DOCUMENT ME!
    • tMask

      private BitSet tMask
      Mask that meets threshold and sMask requirements for shrunken volume.
    • transformDir

      private int transformDir
      FORWARD or INVERSE for FFT.
    • upper

      private int[] upper
      DOCUMENT ME!
    • useScript

      private boolean useScript
      If true, the program is run from a script.
    • value

      private float value
      DOCUMENT ME!
    • value1

      private float value1
      DOCUMENT ME!
    • value2

      private float value2
      DOCUMENT ME!
    • frac

      private float frac
      DOCUMENT ME!
    • rfrac

      private float rfrac
      DOCUMENT ME!
    • values

      private float[] values
      DOCUMENT ME!
    • vari

      private double vari
      DOCUMENT ME!
    • varMax

      private double varMax
      DOCUMENT ME!
    • volSize

      private int volSize
      DOCUMENT ME!
    • volumeFactor

      private float volumeFactor
      Factor by which to shrink volume.
    • workingBuffer

      private float[] workingBuffer
      DOCUMENT ME!
    • xf

      private float xf
      DOCUMENT ME!
    • xo

      private int xo
      DOCUMENT ME!
    • xyo

      private int xyo
      DOCUMENT ME!
    • xv

      private float xv
      DOCUMENT ME!
    • xyv

      private float xyv
      DOCUMENT ME!
    • yMat

      private float[] yMat
      DOCUMENT ME!
    • ys

      private float[] ys
      DOCUMENT ME!
    • zero

      private float[] zero
      DOCUMENT ME!
    • zeroMoment0

      private double zeroMoment0
      DOCUMENT ME!
    • zeroMoment1

      private double zeroMoment1
      DOCUMENT ME!
  • Constructor Details

    • AlgorithmIHN3Correction

      public AlgorithmIHN3Correction(ModelImage destImg, ModelImage fieldImg, ModelImage srcImg, float _threshold, int _maxIters, float _endTol, float _fieldDistance, float _shrink, float _kernelfwhm, float _noise, boolean _entireImage, boolean _autoThreshold, boolean useScript)
      Creates a new AlgorithmIHN3Correction object.
      Parameters:
      destImg - image model where result image is to stored
      fieldImg - image model where used field is stored
      srcImg - source image model
      _threshold - Values at less than _threshold are treated as part of the background
      _maxIters - Maximum number of iterations
      _endTol - The measure used to terminate the iterations is the coefficient of variation of change in field estimates between successive iterations.
      _fieldDistance - Characteristic distance over which the field varies. The distance between adjacent knots in bspline fitting with at least 4 knots going in every dimension. The default in the dialog is one third the distance (resolution * extents) of the smallest dimension.
      _shrink - The factor by which the data is subsampled to a lower resolution in estimating the slowly varying non-uniformity field. Reduce sampling in the finest sampling direction by the shrink factor.
      _kernelfwhm - Width of deconvolution kernel used to sharpen the histogram. Larger values give faster convergence while smaller values give greater accuracy.
      _noise - Noise used in Weiner filter
      _entireImage - If true, the N3 method is applied to the entire image. If false, the N3 method is applied only to the region of interest.
      _autoThreshold - If true determines the threshold by histogram analysis. If true a VOI cannot be used and the input threshold is ignored.
      useScript - If true, the program is run from a script
  • Method Details

    • finalize

      public void finalize()
      Prepares this class for destruction.
      Overrides:
      finalize in class AlgorithmBase
    • runAlgorithm

      public void runAlgorithm()
      Start algorithm.
      Specified by:
      runAlgorithm in class AlgorithmBase
    • cleanUp

      private void cleanUp()
      Prepares this class for destruction.
    • fft

      private void fft(float[] rData, float[] iData)
      This is the method that calculates the FFT.
      Parameters:
      rData - real data
      iData - imaginary data
    • fitSplinesToVolumeLookup2D

      private void fitSplinesToVolumeLookup2D()
      DOCUMENT ME!
    • fitSplinesToVolumeLookup3D

      private void fitSplinesToVolumeLookup3D()
      DOCUMENT ME!
    • IHN3Correction2

      private void IHN3Correction2()
      IHN3Correction2(). Derived from PERL file nu_estimate_np_and_em.in Iteratively estimates intensity non-uniformity artifacts in MRI areas.
    • IHN3Correction3

      private void IHN3Correction3()
      IHN3Correction3. Derived from PERL file nu_estimate_np_and_em.in Iteratively estimates intensity non-uniformity artifacts in MRI volumes.
    • smoothVolumeLookup2D

      private void smoothVolumeLookup2D()
      DOCUMENT ME!
    • smoothVolumeLookup3D

      private void smoothVolumeLookup3D()
      DOCUMENT ME!
    • TBSplineVolume

      private void TBSplineVolume()
      DOCUMENT ME!
    • transformBilinear

      private void transformBilinear(float[] imgBuf, TransMatrix xfrm)
      Transforms and resamples volume using bilinear interpolation.
      Parameters:
      imgBuf - - image array
      xfrm - - TransMatrix to be applied
    • transformNearestNeighbor2D

      private void transformNearestNeighbor2D(float[] imgBuf, TransMatrix xfrm)
      Transforms and resamples volume using nearest neighbor interpolation.
      Parameters:
      imgBuf - image array
      xfrm - transformation matrix to be applied
    • transformNearestNeighbor3D

      private void transformNearestNeighbor3D(float[] imgBuf, TransMatrix xfrm)
      Transforms and resamples volume using nearest neighbor interpolation.
      Parameters:
      imgBuf - image array
      xfrm - transformation matrix to be applied
    • transformTrilinear

      private void transformTrilinear(float[] imgBuffer, TransMatrix matrix)
      Transforms and resamples volume using trilinear interpolation.
      Parameters:
      imgBuffer - image array
      xfrm - transformation matrix to be applied
    • volumeDomain

      private void volumeDomain()
      Allocates and initializes important buffers.