Package gov.nih.mipav.model.algorithms
Class AlgorithmPbBoundaryDetection
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmPbBoundaryDetection
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmPbBoundaryDetection extends AlgorithmBase
Compute probability of boundary using brightness gradient and texture gradient Original MATLAB code written by David R. Martin in April 2003 Reference: "Learning to Detect Natural Image Boundaries Using Local Brightness, Color, and Texture Cues" by David R. Martin, Charles C. Fowlkes, and Jitendra Malik, IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 26, No. 5, May, 2004, pp. 530-549.- Author:
- ilb
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BG
private static int
BGTG
private byte[]
byteIntBuffer
byte array for int *private byte[]
byteLongBuffer
byte array for long *private byte[]
byteShortBuffer
byte array for short *private static int
CANNY
private static int
CG
private static int
CGTG
private static int
COLOR_PRESENTATION
private double
epsilon
private static int
GM
private static int
GM2
private int
gradientType
private static int
GRAY_PRESENTATION
private double
highRadius
private double
hmult
private double
lowRadius
private int
nthresh
private int
numOrientations
private int
presentation
private java.io.RandomAccessFile
raFile
private double
sigma
private java.lang.String
smooth
private static int
TG
private static int
TWOMM
private static int
TWOMM2
private int
xDim
private int
yDim
-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmPbBoundaryDetection()
AlgorithmPbBoundaryDetection - default constructor.AlgorithmPbBoundaryDetection(ModelImage destImg, ModelImage srcImg, int gradientType, int presentation, double lowRadius, double highRadius, int numOrientations, java.lang.String smooth, double sigma, int nthresh, double hmult)
AlgorithmPbBoundaryDetection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
assignTextons(int[][] map, double[][][][] fim, double[][] textons)
private void
cgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, int nbins, double sigmaSim, double gamma, java.lang.String smooth, double[] sigmaSmooth)
cgmo for color Compute the color gradient at a single scale and multiple orientationsprivate void
cgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, java.lang.String smooth, double[] sigmaSmooth)
private void
cgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, int nbins, double sigmaSim, java.lang.String smooth, double sigmaSmooth)
cgmo for black and white Compute the color gradient at a single scale and multiple orientationsprivate void
cgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, java.lang.String smooth, double sigmaSmooth)
private void
conv2(double[][] A, double[][] B, double[][] Cout)
private void
det2MM(double[][] e0, double[][] e1, double[][] theta, double sigmaI, double sigmaO)
private void
detBG(double[][][] bg, double[] theta)
private void
detBGTG(double[][][] bg, double[][][] tg, double[] theta)
private void
detCG(double[][][][] cg, double[] theta)
private void
detCGTG(double[][][][] cg, double[][][] tg, double[] theta)
private void
detGM(double[][] m, double[][] theta, double sigma)
private void
detTG(double[][][] tg, double[] theta)
private void
distsqr(double[][] z, double[][] x, double[][] y)
private void
fbRun(double[][][][] fim, double[][][][] fb, double[][] im)
private void
fbRun(double[][] fim, double[][] fb, double[][] im)
private void
fftconv2(double[][] fim, double[][] im, double[][] f)
private void
fitparab(double[][] a, double[][] b, double[][] c, double[][] z, double ra, double rb, double theta)
int
getInt(boolean bigEndian)
Reads four signed bytes from file.long
getLong(boolean bigEndian)
Reads eight unsigned bytes from file.java.lang.String
getString(int length)
Reads a string from a file of givenlength
.int
getUnsignedShort(boolean bigEndian)
Reads two unsigned bytes from file.private void
nonmax(double[][] imout, double[][] im, double theta)
private void
nonmax(double[][] imout, double[][] im, double[][] theta)
private void
oeFilter(double[][] f, double sigmaX, double sigmaY, int support)
private void
oeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta)
private void
oeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta, int deriv)
private void
oeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta, int deriv, boolean dohil, boolean dovis)
Compute unit L1- norm 2D filter.private void
padReflect(double[][] impad, double[][] im, int r)
private void
pb2MM(double[][] pb, double[][] theta)
private void
pb2MM2(double[][] pb, double[][] theta)
private void
pbBG(double[][] pb, double[][] theta)
private void
pbBGTG(double[][] pb, double[][] theta)
private void
pbCanny(double[][] pb)
private void
pbCG(double[][] pb, double[][] theta)
private void
pbCGTG(double[][] pb, double[][] theta)
private void
pbGM(double[][] pb, double[][] theta)
private void
pbGM2(double[][] pb, double[][] theta)
private void
pbTG(double[][] pb, double[][] theta)
private java.lang.String
readCString()
private void
readFile(double[][][][] fb, double[][] tex, double[][] tsim)
private void
RGB2Lab(double[][][] L, double[] red, double[] green, double[] blue)
void
runAlgorithm()
Actually runs the algorithm.private void
savgol(double[][] c, double[][] z, int d, int k, double ra, double rb, double theta)
private void
tgmo(double[][][] tg, double[] theta, int[][] tmap, int ntex, double radius, int numOrientations, double[][] tsim, java.lang.String smooth, double sigma)
Compute the texture gradient at a single scale and multiple orientationsprivate void
tgso(double[][] tg, int[][] tmap, int ntex, double radius, double theta, java.lang.String smooth, double sigma, double[][] tsim)
Compute the texture graident at a single orientation and scale-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, 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
-
BGTG
private static final int BGTG
- See Also:
- Constant Field Values
-
CGTG
private static final int CGTG
- See Also:
- Constant Field Values
-
BG
private static final int BG
- See Also:
- Constant Field Values
-
CG
private static final int CG
- See Also:
- Constant Field Values
-
TG
private static final int TG
- See Also:
- Constant Field Values
-
GM
private static final int GM
- See Also:
- Constant Field Values
-
GM2
private static final int GM2
- See Also:
- Constant Field Values
-
TWOMM
private static final int TWOMM
- See Also:
- Constant Field Values
-
TWOMM2
private static final int TWOMM2
- See Also:
- Constant Field Values
-
CANNY
private static final int CANNY
- See Also:
- Constant Field Values
-
gradientType
private int gradientType
-
GRAY_PRESENTATION
private static final int GRAY_PRESENTATION
- See Also:
- Constant Field Values
-
COLOR_PRESENTATION
private static final int COLOR_PRESENTATION
- See Also:
- Constant Field Values
-
presentation
private int presentation
-
lowRadius
private double lowRadius
-
highRadius
private double highRadius
-
numOrientations
private int numOrientations
-
smooth
private java.lang.String smooth
-
sigma
private double sigma
-
nthresh
private int nthresh
-
hmult
private double hmult
-
xDim
private int xDim
-
yDim
private int yDim
-
raFile
private java.io.RandomAccessFile raFile
-
byteShortBuffer
private final byte[] byteShortBuffer
byte array for short *
-
byteIntBuffer
private final byte[] byteIntBuffer
byte array for int *
-
byteLongBuffer
private final byte[] byteLongBuffer
byte array for long *
-
epsilon
private final double epsilon
-
-
Constructor Detail
-
AlgorithmPbBoundaryDetection
public AlgorithmPbBoundaryDetection()
AlgorithmPbBoundaryDetection - default constructor.
-
AlgorithmPbBoundaryDetection
public AlgorithmPbBoundaryDetection(ModelImage destImg, ModelImage srcImg, int gradientType, int presentation, double lowRadius, double highRadius, int numOrientations, java.lang.String smooth, double sigma, int nthresh, double hmult)
AlgorithmPbBoundaryDetection.- Parameters:
destImg
- DOCUMENT ME!srcImg
- DOCUMENT ME!gradientType
-presentation
-lowRadius
-highRadius
-numOrientations
-smooth
-sigma
-
-
-
Method Detail
-
runAlgorithm
public void runAlgorithm()
Description copied from class:AlgorithmBase
Actually runs the algorithm. Implemented by inheriting algorithms.- Specified by:
runAlgorithm
in classAlgorithmBase
-
pbCanny
private void pbCanny(double[][] pb)
-
pb2MM2
private void pb2MM2(double[][] pb, double[][] theta)
-
pb2MM
private void pb2MM(double[][] pb, double[][] theta)
-
pbCG
private void pbCG(double[][] pb, double[][] theta)
-
pbCGTG
private void pbCGTG(double[][] pb, double[][] theta)
-
pbGM2
private void pbGM2(double[][] pb, double[][] theta)
-
pbGM
private void pbGM(double[][] pb, double[][] theta)
-
pbBG
private void pbBG(double[][] pb, double[][] theta)
-
pbBGTG
private void pbBGTG(double[][] pb, double[][] theta)
-
pbTG
private void pbTG(double[][] pb, double[][] theta)
-
nonmax
private void nonmax(double[][] imout, double[][] im, double[][] theta)
-
nonmax
private void nonmax(double[][] imout, double[][] im, double theta)
-
det2MM
private void det2MM(double[][] e0, double[][] e1, double[][] theta, double sigmaI, double sigmaO)
- Parameters:
e0
- output smaller eigenvlauese1
- output larger eigenvaluestheta
- output Orientation of first eigenvector + PI/2 (i.e. orientation of possible edge)sigmaI
- input Inner scale (sigma for image derivatives)sigmaO
- input Outer scale (sigma for spatial averaging)
-
detCG
private void detCG(double[][][][] cg, double[] theta)
-
detCGTG
private void detCGTG(double[][][][] cg, double[][][] tg, double[] theta)
-
detGM
private void detGM(double[][] m, double[][] theta, double sigma)
-
detBG
private void detBG(double[][][] bg, double[] theta)
-
detBGTG
private void detBGTG(double[][][] bg, double[][][] tg, double[] theta)
-
detTG
private void detTG(double[][][] tg, double[] theta)
-
assignTextons
private void assignTextons(int[][] map, double[][][][] fim, double[][] textons)
-
distsqr
private void distsqr(double[][] z, double[][] x, double[][] y)
-
readFile
private void readFile(double[][][][] fb, double[][] tex, double[][] tsim)
-
getString
public final java.lang.String getString(int length) throws java.io.IOException
Reads a string from a file of givenlength
.- Parameters:
length
- Number of bytes that form the string.- Returns:
- The string read from the file.
- Throws:
java.io.IOException
- if there is an error reading the file
-
getLong
public final long getLong(boolean bigEndian) throws java.io.IOException
Reads eight unsigned bytes from file.- Parameters:
bigEndian
-true
indicates big endian byte order,false
indicates little endian.- Returns:
- The value of the long read from the file.
- Throws:
java.io.IOException
- if there is an error reading the file
-
getInt
public final int getInt(boolean bigEndian) throws java.io.IOException
Reads four signed bytes from file.- Parameters:
bigEndian
-true
indicates big endian byte order,false
indicates little endian.- Returns:
- The value of the integer read from the file.
- Throws:
java.io.IOException
- if there is an error reading the file
-
getUnsignedShort
public final int getUnsignedShort(boolean bigEndian) throws java.io.IOException
Reads two unsigned bytes from file.- Parameters:
bigEndian
-true
indicates big endian byte order,false
indicates little endian.- Returns:
- The value of unsigned short read from the file returned as an int.
- Throws:
java.io.IOException
- if there is an error reading the file
-
readCString
private java.lang.String readCString() throws java.io.IOException
- Throws:
java.io.IOException
-
cgmo
private void cgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, java.lang.String smooth, double[] sigmaSmooth)
-
cgmo
private void cgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, int nbins, double sigmaSim, double gamma, java.lang.String smooth, double[] sigmaSmooth)
cgmo for color Compute the color gradient at a single scale and multiple orientations- Parameters:
cg
- output output [yDim][xDim][3][numOrientations] array for coloroutput
- [numOrientations] thetaimage
- RGB image, values in [0, 1].radius
- Radius of disc for cg arraynumOrientations
- Number of orientations for cg arraynbins
- Number of bins; should be > 1/sigmaSim.sigmaSim
- For color similarity functiongamma
- Gamma correction for LAB [2.5].smooth
- Smoothing method, one of {"gaussian", "savgol", "none"}, default nonesigmaSmooth
- Sigma for smoothing, default to radius
-
RGB2Lab
private void RGB2Lab(double[][][] L, double[] red, double[] green, double[] blue)
-
cgmo
private void cgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, java.lang.String smooth, double sigmaSmooth)
-
cgmo
private void cgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, int nbins, double sigmaSim, java.lang.String smooth, double sigmaSmooth)
cgmo for black and white Compute the color gradient at a single scale and multiple orientations- Parameters:
cg
- output [yDim][xDim][numOrientations] array for black and whiteoutput
- [numOrientations] thetaimage
- Grayscale image, values in [0, 1].radius
- Radius of disc for cg arraynumOrientations
- Number of orientations for cg arraynbins
- Number of bins; should be > 1/sigmaSim.sigmaSim
- For color similarity functionsmooth
- Smoothing method, one of {"gaussian", "savgol", "none"}, default nonesigmaSmooth
- Sigma for smoothing, default to radius
-
tgmo
private void tgmo(double[][][] tg, double[] theta, int[][] tmap, int ntex, double radius, int numOrientations, double[][] tsim, java.lang.String smooth, double sigma)
Compute the texture gradient at a single scale and multiple orientations- Parameters:
output
- tg [yDim][xDim][numOrientations] arrayoutput
- [numOrientations] theta Disc orientations (which are orthogonal to the texture gradient).tmap
- [yDim][xDim] Texton map, values in [1, ntex]ntex
- Number of textonsradius
- Radius of disc for texture gradientnumOrientations
- Number of orientations at which to compute the texture graidenttsim
- Texton similarity matrix. If not provided, then use chi-squared.smooth
- Smoothing method. One of "gaussian", "savgol", "none". Default "none".sigma
- Sigma for smoothing. Default to radius.
-
tgso
private void tgso(double[][] tg, int[][] tmap, int ntex, double radius, double theta, java.lang.String smooth, double sigma, double[][] tsim)
Compute the texture graident at a single orientation and scale- Parameters:
output
- tg [yDim][xDim] arraytmap
- [yDim][xDim] Texton map, values in [1, ntex].ntex
- Number of textonsradius
- Radius of disc for tgtheta
- Orientation orthogonal to tg.smooth
- Smoothing method, one of {"gaussian", "savgol", "none"}, default = "none".sigma
- Sigma for smoothing. Default to radius.tsim
- [ntex][ntex] Texton similarity matrix. If not provided, then use chi-squared.
-
fitparab
private void fitparab(double[][] a, double[][] b, double[][] c, double[][] z, double ra, double rb, double theta)
-
savgol
private void savgol(double[][] c, double[][] z, int d, int k, double ra, double rb, double theta)
-
fbRun
private void fbRun(double[][][][] fim, double[][][][] fb, double[][] im)
-
fbRun
private void fbRun(double[][] fim, double[][] fb, double[][] im)
-
fftconv2
private void fftconv2(double[][] fim, double[][] im, double[][] f)
-
padReflect
private void padReflect(double[][] impad, double[][] im, int r)
-
oeFilter
private void oeFilter(double[][] f, double sigmaX, double sigmaY, int support)
-
oeFilter
private void oeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta)
-
oeFilter
private void oeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta, int deriv)
-
oeFilter
private void oeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta, int deriv, boolean dohil, boolean dovis)
Compute unit L1- norm 2D filter. The filter is a Gaussian in the x direction The filter is a Gaussian derivative with optional Hilbert transform in the y direction. The filter is zero-meaned if deriv > 0.- Parameters:
f
- output [sz][sz] square filtersigmaX
-sigmaY
-support
- Make filter +/- this many sigmatheta
- Orientation of x axis, in radiansderiv
- Degree of y derivative, one of {0, 1, 2}.dohil
- Do Hilbert transform in y direction?dovis
- Visualization for debugging?
-
conv2
private void conv2(double[][] A, double[][] B, double[][] Cout)
-
-