net.grelf.grip
Class Blob_

java.lang.Object
  extended by net.grelf.grip.Blob_
All Implemented Interfaces:
java.io.Serializable, Blob

public class Blob_
extends java.lang.Object
implements Blob, java.io.Serializable

Representing the shape of a contiguous set of pixels which have been detected in an image. The shape is described by a list of points defining the boundary together with a list of horizontal lines (of type Blob.BlobRow) defining the area enclosed by the boundary. This double description is to facilitate drawing and measuring the object.

This class also contains a static method for detecting a list of Blobs from a mask, such as would have been set by thresholding - see class ImThreshRGBDialogue.

See Also:
Serialized Form

Nested Class Summary
protected static class Blob_.BlobRow
           
 
Constructor Summary
Blob_(int x, int y)
          Construct a 1-pixel blob at (x, y) - for a detected pixel with no neighbours.
Blob_(java.util.List<java.awt.Point> aBoundary, byte[][] mask)
          Construct a Blob from a boundary (list of points) and a mask.
 
Method Summary
 int area()
          Measure the area of the blob, as the total number of pixels in its rows.
 int[] brightness(java.awt.image.BufferedImage image)
          Measure the integrated detected brightness (NOT the average) in each channel
 PointFloat densityCentre(java.awt.image.BufferedImage im)
          Calculate the centre of the blob with weighting from pixel densities (brightnesses).
 BlobFrame display(ImFrame srcFrame, BlobMeas meas)
          Display this blob magnified in the given frame.
 void drawBoundary(java.awt.image.BufferedImage image, int[] rgb)
          Draw the boundary of the blob in the given image with the given RGB levels.
 void drawBoundary(byte[][] mask, byte value)
          Draw the boundary of the blob in the mask array with the given value.
 void drawRegion(java.awt.image.BufferedImage image, int[] rgb)
          Draw the rows of the blob in the given image with the given RGB levels.
 void drawRegion(byte[][] mask, byte value)
          Draw the rows of the blob in the mask array with the given value.
 void erase(byte[][] mask)
          Erase this blob from a given mask.
 Blob getBackgroundDisc()
          For accurate brightness measurement in BlobMenu.
 java.util.List<java.awt.Point> getBoundary()
           
 Bounds getBounds()
          Get the bounds of this Blob.
 Blob getBrightnessDisc()
          For accurate brightness measurement in BlobMenu.
 float getMeasuringRingSizeFactor()
          Get the factor by which the measuring circles in display () are expanded.
protected  java.util.List<Blob_.BlobRow> getRegion()
           
 java.util.List<PointFloat> getVerticalCentreLineFromBoundary()
          Get a list of the centre points of all horizontal rows that comprise the blob with a simple shape.
 java.util.List<PointFloat> getVerticalCentreLineFromRegion()
          Get a list of the centre points of all horizontal rows that comprise the blob.
 boolean hasRows()
          Whether region comprises at least one row.
 PointFloat maskCentre()
          Calculate the centre of the blob simply as average of detected x and y, with no weighting from pixel densities.
 BlobMeas measure(Image image)
          Measure brightness, density-weighted centre and area (pixel count) all on one pass.
 void measureAccurately(BlobMeas meas, Image image)
          Measure meanBackground, accurateBrightnesses and snRatios fields of the given BlobMeas using backgroundDisc and brightnessDisc in the given frame (which is assumed to be the parent frame of the magnified blob frame).
The signal-to-noise (S/N) ratio for each channel is measured as
(mean (starBrightness) - mean (backgroundBrightness)) / stdDev (backgroundBrightness)
where mean (starBrightness) is the accurately measured brightness in the inner disc divided by the number of pixels in that disc.
 void measureAccurately(BlobMeas meas, ImFrame parentFrame)
          Measure meanBackground, accurateBrightnesses and snRatios fields of the given BlobMeas using backgroundDisc and brightnessDisc in the given frame (which is assumed to be the parent frame of the magnified blob frame).
The signal-to-noise (S/N) ratio for each channel is measured as
(mean (starBrightness) - mean (backgroundBrightness)) / stdDev (backgroundBrightness)
where mean (starBrightness) is the accurately measured brightness in the inner disc divided by the number of pixels in that disc.
protected  void nullRows()
          Available for saving memory if the boundary has to be kept but we no longer need the region.
 double perimeter()
          Measure the perimeter of the blob as the length of its boundary vectors.
 void remeasureAccurately(BlobMeas meas, ImFrame parentFrame)
           
 void setMeasuringRingSizeFactor(float factor)
          Set the factor by which the measuring circles in display () are expanded.
 java.lang.String toString()
          Get a simple description of the Blob
 java.lang.StringBuffer toXML(java.lang.String indent)
          The indent string would typically contain some tab characters (\t).
 void translate(int dx, int dy)
          Move the blob by the given pixel displacement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Blob_

public Blob_(java.util.List<java.awt.Point> aBoundary,
             byte[][] mask)
Construct a Blob from a boundary (list of points) and a mask. Detected pixels in the mask must have the value 3 and all others value 0 at the start.


Blob_

public Blob_(int x,
             int y)
Construct a 1-pixel blob at (x, y) - for a detected pixel with no neighbours.

Method Detail

getBoundary

public java.util.List<java.awt.Point> getBoundary()
Specified by:
getBoundary in interface Blob

getRegion

protected java.util.List<Blob_.BlobRow> getRegion()

nullRows

protected void nullRows()
Available for saving memory if the boundary has to be kept but we no longer need the region. Use with care - make any measurements first!


hasRows

public boolean hasRows()
Description copied from interface: Blob
Whether region comprises at least one row.

Specified by:
hasRows in interface Blob

getBrightnessDisc

public Blob getBrightnessDisc()
For accurate brightness measurement in BlobMenu. The brightness disc is created when displaying a single blob in its own frame, by using display () in this class.

Specified by:
getBrightnessDisc in interface Blob

getBackgroundDisc

public Blob getBackgroundDisc()
For accurate brightness measurement in BlobMenu. The background disc is created when displaying a single blob in its own frame, by using display () in this class.

Specified by:
getBackgroundDisc in interface Blob

toString

public java.lang.String toString()
Get a simple description of the Blob

Overrides:
toString in class java.lang.Object

toXML

public java.lang.StringBuffer toXML(java.lang.String indent)
The indent string would typically contain some tab characters (\t).

Specified by:
toXML in interface Blob

getVerticalCentreLineFromBoundary

public java.util.List<PointFloat> getVerticalCentreLineFromBoundary()
Get a list of the centre points of all horizontal rows that comprise the blob with a simple shape. y values should be consecutive whole numbers. The blob must only have at most 2 boundary points on any horizontal line, except on the uppermost and lowermost lines which are excluded.

Specified by:
getVerticalCentreLineFromBoundary in interface Blob

getVerticalCentreLineFromRegion

public java.util.List<PointFloat> getVerticalCentreLineFromRegion()
Get a list of the centre points of all horizontal rows that comprise the blob. y values should be consecutive whole numbers.

Specified by:
getVerticalCentreLineFromRegion in interface Blob

erase

public void erase(byte[][] mask)
Erase this blob from a given mask.

Specified by:
erase in interface Blob

getBounds

public Bounds getBounds()
Get the bounds of this Blob.

Specified by:
getBounds in interface Blob

drawBoundary

public void drawBoundary(java.awt.image.BufferedImage image,
                         int[] rgb)
Draw the boundary of the blob in the given image with the given RGB levels.

Specified by:
drawBoundary in interface Blob

drawBoundary

public void drawBoundary(byte[][] mask,
                         byte value)
Draw the boundary of the blob in the mask array with the given value.

Specified by:
drawBoundary in interface Blob

drawRegion

public void drawRegion(java.awt.image.BufferedImage image,
                       int[] rgb)
Draw the rows of the blob in the given image with the given RGB levels.

Specified by:
drawRegion in interface Blob

drawRegion

public void drawRegion(byte[][] mask,
                       byte value)
Draw the rows of the blob in the mask array with the given value.

Specified by:
drawRegion in interface Blob

brightness

public int[] brightness(java.awt.image.BufferedImage image)
Measure the integrated detected brightness (NOT the average) in each channel

Specified by:
brightness in interface Blob

area

public int area()
Measure the area of the blob, as the total number of pixels in its rows.

Specified by:
area in interface Blob

perimeter

public double perimeter()
Measure the perimeter of the blob as the length of its boundary vectors.

Specified by:
perimeter in interface Blob

maskCentre

public PointFloat maskCentre()
Calculate the centre of the blob simply as average of detected x and y, with no weighting from pixel densities.

Specified by:
maskCentre in interface Blob

densityCentre

public PointFloat densityCentre(java.awt.image.BufferedImage im)
Calculate the centre of the blob with weighting from pixel densities (brightnesses). Brightnesses simply sum all channels (R,G, B given equal weight).

Specified by:
densityCentre in interface Blob

measure

public BlobMeas measure(Image image)
Measure brightness, density-weighted centre and area (pixel count) all on one pass. 2/10/09: Modified so that brightness combines channels not just by adding but as the square of the sum of the square of channel brightnesses.

Specified by:
measure in interface Blob

remeasureAccurately

public void remeasureAccurately(BlobMeas meas,
                                ImFrame parentFrame)
Specified by:
remeasureAccurately in interface Blob

measureAccurately

public void measureAccurately(BlobMeas meas,
                              ImFrame parentFrame)
Measure meanBackground, accurateBrightnesses and snRatios fields of the given BlobMeas using backgroundDisc and brightnessDisc in the given frame (which is assumed to be the parent frame of the magnified blob frame).
The signal-to-noise (S/N) ratio for each channel is measured as
(mean (starBrightness) - mean (backgroundBrightness)) / stdDev (backgroundBrightness)
where mean (starBrightness) is the accurately measured brightness in the inner disc divided by the number of pixels in that disc. The signal is thus measured by the amount by which the star profile sticks up above the background. The noisiness of the background is measured by its standard deviation.

Specified by:
measureAccurately in interface Blob

measureAccurately

public void measureAccurately(BlobMeas meas,
                              Image image)
Description copied from interface: Blob
Measure meanBackground, accurateBrightnesses and snRatios fields of the given BlobMeas using backgroundDisc and brightnessDisc in the given frame (which is assumed to be the parent frame of the magnified blob frame).
The signal-to-noise (S/N) ratio for each channel is measured as
(mean (starBrightness) - mean (backgroundBrightness)) / stdDev (backgroundBrightness)
where mean (starBrightness) is the accurately measured brightness in the inner disc divided by the number of pixels in that disc. The signal is thus measured by the amount by which the star profile sticks up above the background. The noisiness of the background is measured by its standard deviation.

Specified by:
measureAccurately in interface Blob

getMeasuringRingSizeFactor

public float getMeasuringRingSizeFactor()
Get the factor by which the measuring circles in display () are expanded. The factor is static, so changing it for one blob affects all subsequent accurate measurements.

Specified by:
getMeasuringRingSizeFactor in interface Blob

setMeasuringRingSizeFactor

public void setMeasuringRingSizeFactor(float factor)
Set the factor by which the measuring circles in display () are expanded. The factor is static, so changing it for one blob affects all subsequent accurate measurements.

Specified by:
setMeasuringRingSizeFactor in interface Blob

display

public BlobFrame display(ImFrame srcFrame,
                         BlobMeas meas)
Display this blob magnified in the given frame. Boundary and lines through centre of gravity of detected blob are overlaid. Returns reference to the BlobFrame (magnified ImFrame) that is displayed, so the caller could dispose of it.

Specified by:
display in interface Blob

translate

public void translate(int dx,
                      int dy)
Move the blob by the given pixel displacement.

Specified by:
translate in interface Blob