Class AlgorithmSubsample
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.utilities.AlgorithmSubsample
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmSubsample extends AlgorithmBase
Takes in an image and subsamples it to a new set of dimensions. The subsample image is a Gaussian weighted average of neighboring pixels (voxels) of the original image. For 4D images only the first 3 dimensions are subsampled- Author:
- Evan McCreedy
-
-
Field Summary
Fields Modifier and Type Field Description private ModelImage
paddedImage
Padded image.private double[]
posRatios
Ratios used to translate points in the result image to points in the source image.private boolean
processIndep
DOCUMENT ME!private int[]
resultExtents
Extents the resultImage should have.private ModelImage
resultImage
Result image.private float[]
sigmas
Std deviation of the Gaussian function.private ModelImage
srcImage
Image to subsample from.private boolean
transformVOI
DOCUMENT ME!private TransMatrix
transMatrix
DOCUMENT ME!private boolean
trilinearFlag
Whether to perform trilinear filtering when getting intensities of points on the source image.-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmSubsample(ModelImage src, ModelImage result, int[] newExtents, int[] padExtents, float[] _sigmas, boolean indep, boolean transformVOI, TransMatrix transMatrix, boolean doPad)
Setup for a later subsampling of an image.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private double
computeGaussian2D(double locX, double locY, double sigmaX, double sigmaY)
Compute the value of the 2D gaussian at a point.private double
computeGaussian3D(double locX, double locY, double locZ, double sigmaX, double sigmaY, double sigmaZ)
Computes the gaussian weights for a particular point.private void
computeRatios()
Computes the image scaling ratios.void
finalize()
Prepares this class for destruction.private float[]
getNearestNeighborPos2D(float x, float y)
Translates a point from the result image to the source image.private float[]
getNearestNeighborPos3D(float x, float y, float z)
Translates a point from the result image to the source image.ModelImage
getResultImage()
Return the result image (or null if not created yet).private float
getTriLinearVal3D(float x, float y, float z, int t, int channelIndex, ModelSimpleImage src)
Version of get that performs tri-linear interpoloation.private float
getTriLinearVal3D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
Version of get that performs tri-linear interpoloation.private float
getValue2D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
Get the value of a 2D point.private float
getValue3D(float x, float y, float z, int t, int channelIndex, ModelSimpleImage src)
Get the value of a 4D point.private float
getValue3D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
Get the value of a 3D point.private static java.lang.String
makeImageName(java.lang.String image_name, java.lang.String ext)
Helper method for making the result image's name.private ModelImage
padImage(ModelImage kImage, int[] padExtents)
void
runAlgorithm()
Subsample the image.private ModelSimpleImage
subsample2D(int nImages)
Subsample a 2D image.private ModelSimpleImage
subsample3D()
Perform the subsampling.private ModelSimpleImage
subsample4D()
Perform the subsampling.private void
transform25DVOI(ModelImage image, float[] imgBuffer, TransMatrix xfrm)
Transforms and resamples a 2D or 25D VOI using nearest neighbor interpolation.private void
transform3DVOI(ModelImage image, float[] imgBuffer, TransMatrix xfrm)
Transforms and resamples a 3D VOI using nearest neighbor interpolation.-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
posRatios
private double[] posRatios
Ratios used to translate points in the result image to points in the source image.
-
processIndep
private boolean processIndep
DOCUMENT ME!
-
resultExtents
private int[] resultExtents
Extents the resultImage should have.
-
resultImage
private ModelImage resultImage
Result image.
-
paddedImage
private ModelImage paddedImage
Padded image.
-
sigmas
private float[] sigmas
Std deviation of the Gaussian function.
-
srcImage
private ModelImage srcImage
Image to subsample from.
-
transformVOI
private boolean transformVOI
DOCUMENT ME!
-
transMatrix
private TransMatrix transMatrix
DOCUMENT ME!
-
trilinearFlag
private boolean trilinearFlag
Whether to perform trilinear filtering when getting intensities of points on the source image.
-
-
Constructor Detail
-
AlgorithmSubsample
public AlgorithmSubsample(ModelImage src, ModelImage result, int[] newExtents, int[] padExtents, float[] _sigmas, boolean indep, boolean transformVOI, TransMatrix transMatrix, boolean doPad)
Setup for a later subsampling of an image.- Parameters:
src
- image to be subsampledresult
- image created by subsamplingnewExtents
- dimensions of the result image to be sampled into_sigmas
- x, y, and z scales for the gaussian functionindep
- process slices independently (cannot change the z dimension)transformVOI
- if true transform the VOIstransMatrix
- transformation matrix
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
getResultImage
public ModelImage getResultImage()
Return the result image (or null if not created yet).- Returns:
- the subsampled image
-
runAlgorithm
public void runAlgorithm()
Subsample the image.- Specified by:
runAlgorithm
in classAlgorithmBase
-
computeGaussian2D
private double computeGaussian2D(double locX, double locY, double sigmaX, double sigmaY)
Compute the value of the 2D gaussian at a point.- Parameters:
locX
- x location of the value to computelocY
- y location of the value to computesigmaX
- standard deviation of the guassian in the x dimensionsigmaY
- standard deviation of the guassian in the y dimension- Returns:
- the value of the 2D gaussian at the given point
-
computeGaussian3D
private double computeGaussian3D(double locX, double locY, double locZ, double sigmaX, double sigmaY, double sigmaZ)
Computes the gaussian weights for a particular point. Written by Paul Hemler in AlgorithmVesselSegmenation.- Parameters:
locX
- distance to go in the x dir from the pointlocY
- distance to go in the y dir from the pointlocZ
- distance to go in the z dir from the pointsigmaX
- stddev of the gaussian function in the x dirsigmaY
- stddev of the gaussian function in the y dirsigmaZ
- stddev of the gaussian function in the z dir- Returns:
- the gaussian weight coeff.
-
computeRatios
private void computeRatios()
Computes the image scaling ratios.
-
getNearestNeighborPos2D
private float[] getNearestNeighborPos2D(float x, float y)
Translates a point from the result image to the source image.- Parameters:
x
- x coordinate of point to be translatedy
- y coordinate of point to be translated- Returns:
- the translated point on the source image
-
getNearestNeighborPos3D
private float[] getNearestNeighborPos3D(float x, float y, float z)
Translates a point from the result image to the source image.- Parameters:
x
- x coordinate of point to be translatedy
- y coordinate of point to be translatedz
- z coordinate of point to be translated- Returns:
- the translated point on the source image
-
getTriLinearVal3D
private float getTriLinearVal3D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
Version of get that performs tri-linear interpoloation. Note: does NOT perform bounds checking.- Parameters:
x
- x coordinatey
- y coordinatez
- z coordinatechannelIndex
- color channelsrc
- image to get intensity value from- Returns:
- the tri-linear interpolated value
-
getTriLinearVal3D
private float getTriLinearVal3D(float x, float y, float z, int t, int channelIndex, ModelSimpleImage src)
Version of get that performs tri-linear interpoloation. Note: does NOT perform bounds checking.- Parameters:
x
- x coordinatey
- y coordinatez
- z coordinatet
- t coordinatechannelIndex
- color channelsrc
- image to get intensity value from- Returns:
- the tri-linear interpolated value
-
getValue2D
private float getValue2D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
Get the value of a 2D point.- Parameters:
x
- x coordinatey
- y coordinatez
- z coordinate (0 if really 2D)channelIndex
- color channelsrc
- image to sample from- Returns:
- the point's value
-
getValue3D
private float getValue3D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
Get the value of a 3D point.- Parameters:
x
- x coordinatey
- y coordinatez
- z coordinatechannelIndex
- color channelsrc
- image to sample from- Returns:
- the point's value
-
getValue3D
private float getValue3D(float x, float y, float z, int t, int channelIndex, ModelSimpleImage src)
Get the value of a 4D point.- Parameters:
x
- x coordinatey
- y coordinatez
- z coordinatet
- DOCUMENT ME!channelIndex
- color channelsrc
- image to sample from- Returns:
- the point's value
-
subsample2D
private ModelSimpleImage subsample2D(int nImages)
Subsample a 2D image.- Parameters:
nImages
- the number of 2D images to subsample (1 if really 2D)- Returns:
- the subsampled image
-
subsample3D
private ModelSimpleImage subsample3D()
Perform the subsampling. Create a result image with the extents given into the constuctor. Then, for each point in the result image, find point which corresponds to it in the source image. Add up weighted intensities of the neighbors of this point in the source image and the intensity of the point itself. Store this value in the point of the result image. Once all points in the result image have been visted, return the result image.- Returns:
- resampled image
-
subsample4D
private ModelSimpleImage subsample4D()
Perform the subsampling. Create a result image with the extents given into the constuctor. Then, for each point in the result image, find point which corresponds to it in the source image. Add up weighted intensities of the neighbors of this point in the source image and the intensity of the point itself. Store this value in the point of the result image. Once all points in the result image have been visted, return the result image. Does not subsample in fourth time dimension - 3.5D operation- Returns:
- resampled image
-
transform25DVOI
private void transform25DVOI(ModelImage image, float[] imgBuffer, TransMatrix xfrm)
Transforms and resamples a 2D or 25D VOI using nearest neighbor interpolation.- Export VOIs as a mask image
- Transform mask
- Extract VOI contours from mask image and put in new image.
- Parameters:
image
- Image where VOIs are storedimgBuffer
- Image arrayxfrm
- Transformation matrix to be applied
-
transform3DVOI
private void transform3DVOI(ModelImage image, float[] imgBuffer, TransMatrix xfrm)
Transforms and resamples a 3D VOI using nearest neighbor interpolation.- Export VOIs as a mask image
- Transform mask
- Extract VOI contours from mask image and put in new image.
- Parameters:
image
- Image where VOIs are storedimgBuffer
- Image arrayxfrm
- Transformation matrix to be applied
-
padImage
private ModelImage padImage(ModelImage kImage, int[] padExtents)
-
makeImageName
private static java.lang.String makeImageName(java.lang.String image_name, java.lang.String ext)
Helper method for making the result image's name. Strips the current extension from the original name, adds the given extension, and returns the new name.- Parameters:
image_name
- the original image's nameext
- Extension to add which gives information about what algorithm was performed on the image.- Returns:
- The new image name.
-
-