Class FracLac_2003August__1

java.lang.Object
  |
  +--FracLac_2003August__1
All Implemented Interfaces:
ij.plugin.PlugIn

public class FracLac_2003August__1
extends java.lang.Object
implements ij.plugin.PlugIn

Plugin for ImageJ returns an ImageJ results window showing fractal dimensions, lacunarity, and other measures for binary images.

Operates on single or multiple image files. Popups ask the user for parameters. Shows regression lines for the box counting dimension at the original location, an average box counting dimension, a minimum cover dimension (from the minimum count at each box size over multiple origins), and a slope corrected version.

The user can choose to use one series of grids, where each smaller sized grid is always positioned at the top left corner of the image. Or the user can choose to use several such series, where each smaller size within a series always starts at the same position but the absolute position of the series is randomly chosen from between the top left corner and the edge of the screen (a border is added to images to ensure there is space to do this).

If the subareas option is selected, calculates a distribution of local fractal dimensions over smaller subareas of the image then delivers a colour-coded graphic as well as text values of these local dimensions. This function only works on single images and the option to open multiple images is not allowed in this mode. Alternatively, contact the author for an algorithm to calculate data for the multifractal spectrum of entropies; this is a great deal of data that clutters the results file so is not automatically included.

Delivers information about variability in the image. Calculates the coefficient of variation in the fractal dimension over multiple locations and two lacunarity values, the average coefficient of variation in the pixel distribution and the probability density lacunarity.

Calculates the horizontal and vertical axes of the rectangle and oval enclosing the image, and the perimeter and area of the convex hull enclosing the image. Delivers circularity based on the convex hull. This program is free software distributed in the same way that ImageJ is. A. Karperien, Charles Sturt University, August 2003 Copyright (C) 2003 Audrey Karperien For futher information or to send comments, bugs, and feature requests contact the author or see FracLac page ) .

file: FracLac_2003August__1.java

IDE: Sun ONE Studio 4, Community Edition

Since:
J2SKD1.4.1_02b

Nested Class Summary
 class FracLac_2003August__1.ColourRule
          Specifies colours to use for colour coding local fractal dimensions calculated over many subareas.
 class FracLac_2003August__1.FracStats
           
 class FracLac_2003August__1.LogPlotter
           
 
Field Summary
 float alpha
          Specifies the transparency of the graphic for subareas in drawit(int, int, int, java.awt.Graphics2D, int, int[], int[], double[]).
 double AREA
           
 int border
          Size of border to add around images.
 int boxes
           
 double centrex
          Centre coordinate of pixelated area.
 double centrey
          Centre coordinate of pixelated area.
 double circularity
          Circularity of convex hull.
 double[] colourarray
          Holds values for each colour for each square for doing sub areas.
 java.lang.String countstring
          Holds values for box count data.
 int docircul
          If set to 1, runs circularity calculations.
 boolean doglobal
          True does entire image area.
 boolean dosomethreshes
          True runs automatic thresholding.
 boolean dosubs
          True finds fractal dimension over several subareas of the image.
 boolean fill
          True fills coloured squares if subareas are being done.
 int foreground
          Value of pixels that will be assessed.
 ij.ImagePlus img
          Is reused for each image processed.
 int incs
          Maximum number of box sizes to use in a series.
 ij.process.ImageProcessor ip
          Is reused for each image processed.
 double maxAcross
          Stores maximum of pixelated area's width or height
 double maxpercent
          Maximum percent of image area to use as box size.
 int newNumSizes
          Working variable for number of box sizes that is used.
 int numlocations
          Number of times to do an entire series of grids (i.e., if multiple origins are being used).
 double perimeter
          Perimeter of convex hull.
 java.lang.String printsummary
          "Y" prints summary data.
 boolean randomsquares
          True checks a random sample of subareas over the image.
 java.awt.Rectangle rec
          Current rectangle enclosing image.
 double roundness
          Variable for roundness of convex hull.
 java.lang.String sdir
          Directory where files to be opened are.
 boolean showcolours
          True shows a graphic colour coded for the fractal dimension of each subarea.
 java.lang.String sizestring
          Holds values for box count data.
 int subboxsize
          Size of boxes to use if doing subareas.
 int subsamples
          Number of subareas to analyze if doing a random sample.
 java.lang.String tab
          "Y" prints summary data.
 boolean userNumber
          True if the user wants to set the number of boxes rather than use a value optimized for each image size.
 double vDiameter
          Vertical axis of oval enclosing pixelated area.
 boolean viewplots
          True shows graphs of regression lines.
 ij.gui.ImageWindow win
          Is reused for each image.
 int[] xarray
          Coordinates of each origin for coloured squared for doing sub areas.
 int[] yarray
          Coordinates of each origin for coloured squared for doing sub areas.
 
Constructor Summary
FracLac_2003August__1()
           
 
Method Summary
 ij.process.ImageProcessor addborder(ij.process.ImageProcessor ip)
           
 double count(boolean asub, int boxnumber, int sze, ij.process.ImageProcessor ip, int x, int y)
           
 void doBoxCounts(boolean wassub, ij.process.ImageProcessor ipc, int x, int y)
           
 void drawit(int w, int h, int numShapes, java.awt.Graphics2D g2, int s, int[] x, int[] y, double[] colours)
           
 ij.process.ImageProcessor drawNewImage(ij.ImagePlus imp, int numShapes, int subboxsize, int[] x, int[] y, double[] colours)
           
 ij.process.ImageProcessor expandImage(ij.process.ImageProcessor ipOld, double wNew, double hNew, double xOff, double yOff)
           
 boolean FindMargins(ij.process.ImageProcessor ip)
           
 int[] findMinCover(int[][] TestArray, int numLocs, int numBoxes)
           
 java.lang.String fnum(double sum, int decimals)
           
 void getCircularityOfConvexHull(ij.process.ImageProcessor ip)
          Gets circularity of convex hull for passed ImageProcessor.
 void GetDimensions(ij.process.ImageProcessor ip)
           
 boolean getInputs()
          Gets user inputs from popups to set global variables.
 ij.gui.PolygonRoi getPolygon(ij.process.ImageProcessor ip)
           
 java.lang.String makeheadings()
          Lists the headings for the results file.
 void openAndrun(boolean DoRandomSquares)
          Opens and processes selected files.
 double[] probmass(int epsilon)
          Returns a double array holding a probability density distribution for the passed array, using as many elements as the passed number; since it is usually called after each box size is scanned, it is usually for a particular epsilon (box size) at a particular location.
 ij.process.ImageProcessor ready(ij.process.ImageProcessor ip)
          Thresholds, finds margins, and sets foreground value on image to be analyzed.
 void run(java.lang.String arg)
          Runs FracLac.
 void runSubs(boolean DoRandomSquares)
          Finds local fractal dimensions over portions of an image.
 void savecolour(double dddf, int iter)
           
 int stdboxsizes(double Across)
           
 double writeFinal(FracLac_2003August__1.FracStats avgstat, FracLac_2003August__1.FracStats min, ij.process.ImageProcessor ipk, FracLac_2003August__1.StoreAvgs avs, boolean circ, boolean issub, java.lang.String suborglobal, int thisiteration, java.lang.String origins)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rec

public java.awt.Rectangle rec
Current rectangle enclosing image.


border

public int border
Size of border to add around images.


alpha

public float alpha
Specifies the transparency of the graphic for subareas in drawit(int, int, int, java.awt.Graphics2D, int, int[], int[], double[]).


maxAcross

public double maxAcross
Stores maximum of pixelated area's width or height


newNumSizes

public int newNumSizes
Working variable for number of box sizes that is used.


boxes

public int boxes

colourarray

public double[] colourarray
Holds values for each colour for each square for doing sub areas.


xarray

public int[] xarray
Coordinates of each origin for coloured squared for doing sub areas.

See Also:
#drawnewimage

yarray

public int[] yarray
Coordinates of each origin for coloured squared for doing sub areas.

See Also:
#drawnewimage

sdir

public java.lang.String sdir
Directory where files to be opened are. Is set by openAndrun(boolean).


sizestring

public java.lang.String sizestring
Holds values for box count data.


countstring

public java.lang.String countstring
Holds values for box count data.


foreground

public int foreground
Value of pixels that will be assessed. Is determined in ready(ij.process.ImageProcessor).


img

public ij.ImagePlus img
Is reused for each image processed. Is set by openAndrun(boolean).

See Also:
getCircularityOfConvexHull(ij.process.ImageProcessor), dosubs

ip

public ij.process.ImageProcessor ip
Is reused for each image processed. Is set by openAndrun(boolean).

See Also:
getCircularityOfConvexHull(ij.process.ImageProcessor), dosubs

win

public ij.gui.ImageWindow win
Is reused for each image. Is set by openAndrun(boolean).


numlocations

public int numlocations
Number of times to do an entire series of grids (i.e., if multiple origins are being used). If set to 1, only one location is used. Is the number of locations to start a grid series at, rather than the number of box sizes or boxes in each grid series. Is set by getInputs().


incs

public int incs
Maximum number of box sizes to use in a series. Is set by getInputs(). Default is 500.


subboxsize

public int subboxsize
Size of boxes to use if doing subareas. Is set by getInputs().


viewplots

public boolean viewplots
True shows graphs of regression lines. Is set by getInputs().


maxpercent

public double maxpercent
Maximum percent of image area to use as box size. Based on smallest rectangle enclosing the pixelated part of the image. Is set by getInputs().


dosubs

public boolean dosubs
True finds fractal dimension over several subareas of the image. False finds it over only the entire area. Is set by getInputs().


dosomethreshes

public boolean dosomethreshes
True runs automatic thresholding. Is set by getInputs().


subsamples

public int subsamples
Number of subareas to analyze if doing a random sample. Is set by getInputs().


printsummary

public java.lang.String printsummary
"Y" prints summary data. Is set by getInputs().


tab

public java.lang.String tab
"Y" prints summary data. Is set by getInputs().


docircul

public int docircul
If set to 1, runs circularity calculations. Default is 0, to not run them. Is set by getInputs().


fill

public boolean fill
True fills coloured squares if subareas are being done. Is set by getInputs().


randomsquares

public boolean randomsquares
True checks a random sample of subareas over the image. Is set by getInputs().


showcolours

public boolean showcolours
True shows a graphic colour coded for the fractal dimension of each subarea. Is set by getInputs().


userNumber

public boolean userNumber
True if the user wants to set the number of boxes rather than use a value optimized for each image size. Is set by getInputs().


doglobal

public boolean doglobal
True does entire image area. Is set by getInputs().


perimeter

public double perimeter
Perimeter of convex hull.


AREA

public double AREA

circularity

public double circularity
Circularity of convex hull.


roundness

public double roundness
Variable for roundness of convex hull.


centrex

public double centrex
Centre coordinate of pixelated area.


centrey

public double centrey
Centre coordinate of pixelated area.


vDiameter

public double vDiameter
Vertical axis of oval enclosing pixelated area.

Constructor Detail

FracLac_2003August__1

public FracLac_2003August__1()
Method Detail

run

public void run(java.lang.String arg)
Runs FracLac. Calls getInputs method. If this returns true, initializes column headings for IJ results window and calls openAndrun(boolean) method, which depends on the value in randomsquares. Otherwise terminates. Calls IJ.register on this class.

Specified by:
run in interface ij.plugin.PlugIn
Parameters:
arg - string not yet used

getCircularityOfConvexHull

public void getCircularityOfConvexHull(ij.process.ImageProcessor ip)
Gets circularity of convex hull for passed ImageProcessor. Is called by writeFinal method. Calls GetDimensions method to find image coordinates, then calls getPolygon method to make an IJ polygon roi and sets this as the current roi. Uses IJ analyzer and ResultsTable to change variables for roundness, circularity, area, and perimeter.

circularity = (perimeter*perimeter)/area

If perimeter is 0 roundness = 0; otherwise roundness = 4.0*pi*(area/(perimeter*perimeter));

Parameters:
ip - ImageProcessor of binary image to make convex hull for

openAndrun

public void openAndrun(boolean DoRandomSquares)
Opens and processes selected files. Reuses global img variable for each opened image. Stores file directory as sdir. Calls ready(ij.process.ImageProcessor) and sets win to current image. Makes a new colourarray, xarray, and yarray for the image's data, and when done closes win if no colour-coding is being shown. Calls #runFL on ip if doglobal is true, and runSubs(boolean) if dosubs is true.

Parameters:
DoRandomSquares - boolean true to do random sample instead of entire grid of subareas

runSubs

public void runSubs(boolean DoRandomSquares)
Finds local fractal dimensions over portions of an image. Calls stdboxsizes to make a series of sizes starting at subboxsize*2. If doing a random sample, resets the roi to a random location once for each subsamples, otherwise covers the whole image using rec for the margins. In both cases, calls #runFL at each starting origin over the image. Calls drawnewimage if showcolours is true.

Parameters:
DoRandomSquares - boolean True does a random sample; false does the entire image

drawNewImage

public ij.process.ImageProcessor drawNewImage(ij.ImagePlus imp,
                                              int numShapes,
                                              int subboxsize,
                                              int[] x,
                                              int[] y,
                                              double[] colours)
Parameters:
imp -
numShapes -
subboxsize -
x -
y -
colours -
Returns:

drawit

public void drawit(int w,
                   int h,
                   int numShapes,
                   java.awt.Graphics2D g2,
                   int s,
                   int[] x,
                   int[] y,
                   double[] colours)
Parameters:
w -
h -
numShapes -
g2 -
s -
x -
y -
colours -

ready

public ij.process.ImageProcessor ready(ij.process.ImageProcessor ip)
Thresholds, finds margins, and sets foreground value on image to be analyzed. Changes #strOldTitle to img's current title and reinitializes sizestring and countstring before getting new #stats on img. If the image is not binary and dosomethreshes is true, calls IJ's thresholding function. Gets stats again then sets foreground to 255 or 0, whichever is lesser in the image.

Kills any lefover roi then sets ip to img's current processor. Calls FindMargins(ij.process.ImageProcessor) and resets newNumSizes to value returned by stdboxsizes(double) using value in maxAcross. Resets border to the greater of 50 or half numlocations then sets #XLimit and #YLimit to this value.

Makes a new ImageProcessor by calling addborder(ij.process.ImageProcessor) on ip, then calls FindMargins(ij.process.ImageProcessor) to reset values.

Parameters:
ip - ImageProcessor on which to act
Returns:
thisip the final ImageProcessor

findMinCover

public int[] findMinCover(int[][] TestArray,
                          int numLocs,
                          int numBoxes)

writeFinal

public double writeFinal(FracLac_2003August__1.FracStats avgstat,
                         FracLac_2003August__1.FracStats min,
                         ij.process.ImageProcessor ipk,
                         FracLac_2003August__1.StoreAvgs avs,
                         boolean circ,
                         boolean issub,
                         java.lang.String suborglobal,
                         int thisiteration,
                         java.lang.String origins)

expandImage

public ij.process.ImageProcessor expandImage(ij.process.ImageProcessor ipOld,
                                             double wNew,
                                             double hNew,
                                             double xOff,
                                             double yOff)
Parameters:
ipOld -
wNew -
hNew -
xOff -
yOff -
Returns:

savecolour

public void savecolour(double dddf,
                       int iter)

stdboxsizes

public int stdboxsizes(double Across)

FindMargins

public boolean FindMargins(ij.process.ImageProcessor ip)

addborder

public ij.process.ImageProcessor addborder(ij.process.ImageProcessor ip)

count

public double count(boolean asub,
                    int boxnumber,
                    int sze,
                    ij.process.ImageProcessor ip,
                    int x,
                    int y)

fnum

public java.lang.String fnum(double sum,
                             int decimals)

probmass

public double[] probmass(int epsilon)
Returns a double array holding a probability density distribution for the passed array, using as many elements as the passed number; since it is usually called after each box size is scanned, it is usually for a particular epsilon (box size) at a particular location. The array holds at each element the percent of boxes that had the number of pixels that corresponds to the index of the element, so to access the probability that a box had 3 pixels, get the value at index 3. Calculates statistics from array named mprob: the mean of the probability distribution is: sum of all(i*mprob[i]) where i is the index and value, and mprob[i] is the weight the variance of the probability distribution is: sum of all (((mprob[i]-meanProb)*(mprob[i]-meanProb))*i); the Probability Density Lacunarity at this epsilon is: (sumMsq - (sumM*sumM))/(sumM*sumM); where sumM=sum of all(i*mprob[i]) and sumMsq = sum of all (i*i*mprob[i]); These are all stored in arrays and written to the final file.

Parameters:
epsilon - integer for the box size; is only used to store final value
Returns:

doBoxCounts

public void doBoxCounts(boolean wassub,
                        ij.process.ImageProcessor ipc,
                        int x,
                        int y)

getPolygon

public ij.gui.PolygonRoi getPolygon(ij.process.ImageProcessor ip)

GetDimensions

public void GetDimensions(ij.process.ImageProcessor ip)

getInputs

public boolean getInputs()
Gets user inputs from popups to set global variables. Is invoked by run(java.lang.String) when plugin is first invoked.

Returns:
false if cancelled
See Also:
dosomethreshes, incs, userNumber, maxpercent, numlocations, doglobal, printsummary, dosubs, fill, randomsquares, dosubs, subboxsize, viewplots, subsamples, docircul

makeheadings

public java.lang.String makeheadings()
Lists the headings for the results file.

"FracLac2003 FILE"

"AVG Box Count Df"

"r squared"

"Corrected"

"r squared"

"Coef Var Lacunarity"

"Avg Coef Var for Y-Int at Multiple Origins"

"Probability Density Lacunarity (Coef Var over all epsilon at Multiple Locations)"

"HULL AREA"

"HULL PERIMETER"

"ROUNDNESS"

"CIRCULARITY"

"WIDTH"

"HEIGHT"

"VERTICAL"

"HORIZONTAL"

"CENTRE (origin)"

"NUM BOXES"

"adjusted NUM BOXES"

"Minimum Cover Df"

"r squared"

"Corrected"

"r squared"

"Coef Var for all Y-int"

"Coef Variation Df"

"Number of origins"

Returns:
string of headings.