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:
ActionListener,WindowListener,Runnable,EventListener
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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate final byte[]byte array for int *private final byte[]byte array for long *private final byte[]byte array for short *private static final intprivate static final intprivate static final intprivate static final intprivate final doubleprivate static final intprivate static final intprivate intprivate static final intprivate doubleprivate doubleprivate doubleprivate intprivate intprivate intprivate RandomAccessFileprivate doubleprivate Stringprivate static final intprivate static final intprivate static final intprivate intprivate intFields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmPbBoundaryDetection - default constructor.AlgorithmPbBoundaryDetection(ModelImage destImg, ModelImage srcImg, int gradientType, int presentation, double lowRadius, double highRadius, int numOrientations, String smooth, double sigma, int nthresh, double hmult) AlgorithmPbBoundaryDetection. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidassignTextons(int[][] map, double[][][][] fim, double[][] textons) private voidcgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, int nbins, double sigmaSim, double gamma, String smooth, double[] sigmaSmooth) cgmo for color Compute the color gradient at a single scale and multiple orientationsprivate voidcgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, String smooth, double[] sigmaSmooth) private voidcgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, int nbins, double sigmaSim, String smooth, double sigmaSmooth) cgmo for black and white Compute the color gradient at a single scale and multiple orientationsprivate voidcgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, String smooth, double sigmaSmooth) private voidconv2(double[][] A, double[][] B, double[][] Cout) private voiddet2MM(double[][] e0, double[][] e1, double[][] theta, double sigmaI, double sigmaO) private voiddetBG(double[][][] bg, double[] theta) private voiddetBGTG(double[][][] bg, double[][][] tg, double[] theta) private voiddetCG(double[][][][] cg, double[] theta) private voiddetCGTG(double[][][][] cg, double[][][] tg, double[] theta) private voiddetGM(double[][] m, double[][] theta, double sigma) private voiddetTG(double[][][] tg, double[] theta) private voiddistsqr(double[][] z, double[][] x, double[][] y) private voidfbRun(double[][][][] fim, double[][][][] fb, double[][] im) private voidfbRun(double[][] fim, double[][] fb, double[][] im) private voidfftconv2(double[][] fim, double[][] im, double[][] f) private voidfitparab(double[][] a, double[][] b, double[][] c, double[][] z, double ra, double rb, double theta) final intgetInt(boolean bigEndian) Reads four signed bytes from file.final longgetLong(boolean bigEndian) Reads eight unsigned bytes from file.final StringgetString(int length) Reads a string from a file of givenlength.final intgetUnsignedShort(boolean bigEndian) Reads two unsigned bytes from file.private voidnonmax(double[][] imout, double[][] im, double theta) private voidnonmax(double[][] imout, double[][] im, double[][] theta) private voidoeFilter(double[][] f, double sigmaX, double sigmaY, int support) private voidoeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta) private voidoeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta, int deriv) private voidoeFilter(double[][] f, double sigmaX, double sigmaY, int support, double theta, int deriv, boolean dohil, boolean dovis) Compute unit L1- norm 2D filter.private voidpadReflect(double[][] impad, double[][] im, int r) private voidpb2MM(double[][] pb, double[][] theta) private voidpb2MM2(double[][] pb, double[][] theta) private voidpbBG(double[][] pb, double[][] theta) private voidpbBGTG(double[][] pb, double[][] theta) private voidpbCanny(double[][] pb) private voidpbCG(double[][] pb, double[][] theta) private voidpbCGTG(double[][] pb, double[][] theta) private voidpbGM(double[][] pb, double[][] theta) private voidpbGM2(double[][] pb, double[][] theta) private voidpbTG(double[][] pb, double[][] theta) private Stringprivate voidreadFile(double[][][][] fb, double[][] tex, double[][] tsim) private voidRGB2Lab(double[][][] L, double[] red, double[] green, double[] blue) voidActually runs the algorithm.private voidsavgol(double[][] c, double[][] z, int d, int k, double ra, double rb, double theta) private voidtgmo(double[][][] tg, double[] theta, int[][] tmap, int ntex, double radius, int numOrientations, double[][] tsim, String smooth, double sigma) Compute the texture gradient at a single scale and multiple orientationsprivate voidtgso(double[][] tg, int[][] tmap, int ntex, double radius, double theta, String smooth, double sigma, double[][] tsim) Compute the texture graident at a single orientation and scaleMethods 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, windowOpenedMethods 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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
BGTG
private static final int BGTG- See Also:
-
CGTG
private static final int CGTG- See Also:
-
BG
private static final int BG- See Also:
-
CG
private static final int CG- See Also:
-
TG
private static final int TG- See Also:
-
GM
private static final int GM- See Also:
-
GM2
private static final int GM2- See Also:
-
TWOMM
private static final int TWOMM- See Also:
-
TWOMM2
private static final int TWOMM2- See Also:
-
CANNY
private static final int CANNY- See Also:
-
gradientType
private int gradientType -
GRAY_PRESENTATION
private static final int GRAY_PRESENTATION- See Also:
-
COLOR_PRESENTATION
private static final int COLOR_PRESENTATION- See Also:
-
presentation
private int presentation -
lowRadius
private double lowRadius -
highRadius
private double highRadius -
numOrientations
private int numOrientations -
smooth
-
sigma
private double sigma -
nthresh
private int nthresh -
hmult
private double hmult -
xDim
private int xDim -
yDim
private int yDim -
raFile
-
byteShortBuffer
private final byte[] byteShortBufferbyte array for short * -
byteIntBuffer
private final byte[] byteIntBufferbyte array for int * -
byteLongBuffer
private final byte[] byteLongBufferbyte array for long * -
epsilon
private final double epsilon
-
-
Constructor Details
-
AlgorithmPbBoundaryDetection
public AlgorithmPbBoundaryDetection()AlgorithmPbBoundaryDetection - default constructor. -
AlgorithmPbBoundaryDetection
public AlgorithmPbBoundaryDetection(ModelImage destImg, ModelImage srcImg, int gradientType, int presentation, double lowRadius, double highRadius, int numOrientations, String smooth, double sigma, int nthresh, double hmult) AlgorithmPbBoundaryDetection.- Parameters:
destImg- DOCUMENT ME!srcImg- DOCUMENT ME!gradientType-presentation-lowRadius-highRadius-numOrientations-smooth-sigma-
-
-
Method Details
-
runAlgorithm
public void runAlgorithm()Description copied from class:AlgorithmBaseActually runs the algorithm. Implemented by inheriting algorithms.- Specified by:
runAlgorithmin 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
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:
IOException- if there is an error reading the file
-
getLong
Reads eight unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the long read from the file.
- Throws:
IOException- if there is an error reading the file
-
getInt
Reads four signed bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the integer read from the file.
- Throws:
IOException- if there is an error reading the file
-
getUnsignedShort
Reads two unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of unsigned short read from the file returned as an int.
- Throws:
IOException- if there is an error reading the file
-
readCString
- Throws:
IOException
-
cgmo
private void cgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, String smooth, double[] sigmaSmooth) -
cgmo
private void cgmo(double[][][][] cg, double[] theta, ModelImage image, double[] radius, int numOrientations, int nbins, double sigmaSim, double gamma, 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 colorimage- 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 radiusoutput- [numOrientations] theta
-
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, String smooth, double sigmaSmooth) -
cgmo
private void cgmo(double[][][] cg, double[] theta, ModelImage image, double radius, int numOrientations, int nbins, double sigmaSim, 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 whiteimage- 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 radiusoutput- [numOrientations] theta
-
tgmo
private void tgmo(double[][][] tg, double[] theta, int[][] tmap, int ntex, double radius, int numOrientations, double[][] tsim, String smooth, double sigma) Compute the texture gradient at a single scale and multiple orientations- Parameters:
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.output- tg [yDim][xDim][numOrientations] arrayoutput- [numOrientations] theta Disc orientations (which are orthogonal to the texture gradient).
-
tgso
private void tgso(double[][] tg, int[][] tmap, int ntex, double radius, double theta, String smooth, double sigma, double[][] tsim) Compute the texture graident at a single orientation and scale- Parameters:
tmap- [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.output- tg [yDim][xDim] array
-
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)
-