Object defined by a connected binary pixel region. More...
#include <MBARI/BitObject.H>
Public Types | |
enum | Coords { OBJECT, IMAGE } |
Coordinate system for return values. More... | |
Public Member Functions | |
BitObject () | |
default Constructor | |
BitObject (const Image< byte > &img, const Point2D< int > location, const byte threshold=1) | |
Constructor from a byte Image and a location. | |
BitObject (const Image< byte > &img) | |
Construct from a byte Image. | |
BitObject (std::istream &is) | |
Construct from the data contained in the input stream is. | |
Image< byte > | reset (const Image< byte > &img, const Point2D< int > location, const byte threshold=1) |
Reset to a new object. | |
int | reset (const Image< byte > &img) |
Reset to a new object. | |
void | freeMem () |
delete all stored data, makes the object invalid | |
void | writeToStream (std::ostream &os) const |
write the entire BitObject to the output stream os | |
void | readFromStream (std::istream &is) |
read the BitObject from the input stream is | |
template<class T > | |
void | setMaxMinAvgIntensity (const Image< T > &img) |
Extract the maximum, minimum and average intensity over the object shape in img. | |
void | getMaxMinAvgIntensity (float &maxIntensity, float &minIntensity, float &avgIntensity) |
Return the maximum, minimum and average intensity. | |
Rectangle | getBoundingBox (const Coords coords=IMAGE) const |
Returns the bounding box of the object. | |
Image< byte > | getObjectMask (const byte value=byte(1), const Coords coords=IMAGE) const |
Returns the object as a binary mask. | |
Dims | getObjectDims () const |
The dimensions of the bounding box of the object. | |
Point2D< int > | getObjectOrigin () const |
The location of the upper left corner of the boundary box in the original image. | |
Point2D< int > | getCentroid (const Coords coords=IMAGE) const |
The centroid of the object rounded to integer coordinates. | |
Vector2D | getCentroidXY (const Coords coords=IMAGE) const |
The centroid, not rounded. | |
int | getArea () const |
The area (number of pixels) of the object. | |
void | getSecondMoments (float &uxx, float &uyy, float &uxy) |
Returns the second moments of the object (normalized by the area). | |
float | getMajorAxis () |
Returns the length of the major axis of the object. | |
float | getMinorAxis () |
Returns the length of the minor axis of the object. | |
float | getElongation () |
Returns the elongation of the object (major axis / minor axis). | |
float | getOriAngle () |
Returns the angle between the major axis and the x axis. | |
bool | isValid () const |
whether the object is valid | |
bool | doesIntersect (const BitObject &other) const |
returns the intersection of this BitObject with other | |
template<class T_or_RGB > | |
void | drawShape (Image< T_or_RGB > &, const T_or_RGB &color, float opacity=1.0F) |
draw the shape of this BitObject into img with color | |
template<class T_or_RGB > | |
void | drawOutline (Image< T_or_RGB > &, const T_or_RGB &color, float opacity=1.0F) |
draw the outline of this BitObject into img with color | |
template<class T_or_RGB > | |
void | drawBoundingBox (Image< T_or_RGB > &, const T_or_RGB &color, float opacity=1.0F) |
draw the bounding box of this BitObject into img with color | |
template<class T_or_RGB > | |
void | draw (BitObjectDrawMode mode, Image< T_or_RGB > &, const T_or_RGB &color, float opacity=1.0F) |
draw this BitObject according to mode |
Object defined by a connected binary pixel region.
This class extracts a connected binary pixel region from a grayscale image and analyzes a few of its properties
Definition at line 53 of file BitObject.H.
enum BitObject::Coords |
Coordinate system for return values.
These values are used to specify whether return values should be given in coordinates of the extracted object or in coordinates of the image from which the object was extracted.
Definition at line 107 of file BitObject.H.
BitObject::BitObject | ( | ) |
BitObject::BitObject | ( | const Image< byte > & | img, | |
const Point2D< int > | location, | |||
const byte | threshold = 1 | |||
) |
Constructor from a byte Image and a location.
img | Image from which the object is extracted | |
location | a point that is inside the object - the object is flooded starting from this seed | |
threshold | for flooding |
Definition at line 64 of file BitObject.C.
References reset().
Construct from a byte Image.
img | image containing only the object the object pixels are 1, all other pixels are 0 |
Definition at line 71 of file BitObject.C.
References reset().
BitObject::BitObject | ( | std::istream & | is | ) |
Construct from the data contained in the input stream is.
Definition at line 77 of file BitObject.C.
References readFromStream().
bool BitObject::doesIntersect | ( | const BitObject & | other | ) | const |
returns the intersection of this BitObject with other
if the intersection is empty, an invalid BitObject is returned
Definition at line 533 of file BitObject.C.
References Rectangle::bottomI(), getBoundingBox(), getObjectMask(), isValid(), Rectangle::left(), max(), min(), Rectangle::rightI(), sum(), takeMin(), Rectangle::tlbrI(), and Rectangle::top().
Referenced by VisualEvent::doesIntersect().
void BitObject::draw | ( | BitObjectDrawMode | mode, | |
Image< T_or_RGB > & | img, | |||
const T_or_RGB & | color, | |||
float | opacity = 1.0F | |||
) | [inline] |
draw this BitObject according to mode
Definition at line 696 of file BitObject.C.
References BODMbbox, BODMoutline, BODMshape, drawBoundingBox(), drawOutline(), and drawShape().
Referenced by VisualEventSet::drawTokens().
void BitObject::drawBoundingBox | ( | Image< T_or_RGB > & | img, | |
const T_or_RGB & | color, | |||
float | opacity = 1.0F | |||
) | [inline] |
draw the bounding box of this BitObject into img with color
Definition at line 666 of file BitObject.C.
References ASSERT, Rectangle::bottomI(), Image< T >::getDims(), Image< T >::getVal(), Image< T >::initialized(), isValid(), Rectangle::left(), Rectangle::rightI(), Image< T >::setVal(), and Rectangle::top().
Referenced by draw().
void BitObject::drawOutline | ( | Image< T_or_RGB > & | img, | |
const T_or_RGB & | color, | |||
float | opacity = 1.0F | |||
) | [inline] |
draw the outline of this BitObject into img with color
Definition at line 622 of file BitObject.C.
References ASSERT, Rectangle::bottomO(), Image< T >::coordsOk(), Image< T >::getDims(), Image< T >::getVal(), Image< T >::initialized(), isValid(), Rectangle::left(), Rectangle::rightO(), Image< T >::setVal(), Rectangle::top(), and ZEROS.
Referenced by draw().
void BitObject::drawShape | ( | Image< T_or_RGB > & | img, | |
const T_or_RGB & | color, | |||
float | opacity = 1.0F | |||
) | [inline] |
draw the shape of this BitObject into img with color
Definition at line 594 of file BitObject.C.
References ASSERT, Image< T >::begin(), Image< T >::beginw(), Rectangle::bottomO(), Image< T >::getDims(), Image< T >::getWidth(), Image< T >::initialized(), isValid(), Rectangle::left(), Rectangle::rightO(), and Rectangle::top().
Referenced by draw().
void BitObject::freeMem | ( | ) |
delete all stored data, makes the object invalid
Definition at line 255 of file BitObject.C.
References Image< T >::freeMem().
Referenced by BitObject(), and reset().
int BitObject::getArea | ( | ) | const |
The area (number of pixels) of the object.
Definition at line 491 of file BitObject.C.
Referenced by VisualEvent::assign(), VisualEventSet::drawTokens(), extractBitObjects(), VisualEvent::getPropertyVector(), and VisualEvent::VisualEvent().
Returns the bounding box of the object.
Definition at line 423 of file BitObject.C.
References Rectangle::height(), Rectangle::tlbrI(), and Rectangle::width().
Referenced by doesIntersect(), and VisualEventSet::drawTokens().
The centroid of the object rounded to integer coordinates.
Definition at line 472 of file BitObject.C.
References getCentroidXY(), and Vector2D::getPoint2D().
The centroid, not rounded.
Definition at line 478 of file BitObject.C.
References getObjectOrigin().
Referenced by getCentroid().
float BitObject::getElongation | ( | ) |
Returns the elongation of the object (major axis / minor axis).
Definition at line 516 of file BitObject.C.
Referenced by VisualEvent::getPropertyVector().
float BitObject::getMajorAxis | ( | ) |
Returns the length of the major axis of the object.
Definition at line 502 of file BitObject.C.
Referenced by VisualEvent::getPropertyVector().
void BitObject::getMaxMinAvgIntensity | ( | float & | maxIntensity, | |
float & | minIntensity, | |||
float & | avgIntensity | |||
) |
Return the maximum, minimum and average intensity.
See setMinMaxAvgIntensity for details
Definition at line 413 of file BitObject.C.
Referenced by VisualEvent::getPropertyVector().
float BitObject::getMinorAxis | ( | ) |
Returns the length of the minor axis of the object.
Definition at line 509 of file BitObject.C.
Referenced by VisualEvent::getPropertyVector().
Dims BitObject::getObjectDims | ( | ) | const |
The dimensions of the bounding box of the object.
Definition at line 462 of file BitObject.C.
References Image< T >::getDims().
Image< byte > BitObject::getObjectMask | ( | const byte | value = byte(1) , |
|
const Coords | coords = IMAGE | |||
) | const |
Returns the object as a binary mask.
value | the value that is used for the object |
Definition at line 437 of file BitObject.C.
References ASSERT, getObjectOrigin(), isValid(), pasteImage(), replaceVals(), and ZEROS.
Referenced by doesIntersect().
Point2D< int > BitObject::getObjectOrigin | ( | ) | const |
The location of the upper left corner of the boundary box in the original image.
Definition at line 466 of file BitObject.C.
References Rectangle::left(), and Rectangle::top().
Referenced by getCentroidXY(), and getObjectMask().
float BitObject::getOriAngle | ( | ) |
Returns the angle between the major axis and the x axis.
Definition at line 523 of file BitObject.C.
Referenced by VisualEvent::getPropertyVector().
void BitObject::getSecondMoments | ( | float & | uxx, | |
float & | uyy, | |||
float & | uxy | |||
) |
Returns the second moments of the object (normalized by the area).
Definition at line 495 of file BitObject.C.
Referenced by VisualEvent::getPropertyVector().
bool BitObject::isValid | ( | ) | const |
whether the object is valid
This is going to be false if no object could be extracted from the image that was given at the constructor or at reset
Definition at line 529 of file BitObject.C.
References Rectangle::isValid().
Referenced by doesIntersect(), drawBoundingBox(), drawOutline(), drawShape(), VisualEventSet::drawTokens(), getObjectMask(), VisualEvent::getPropertyVector(), and setMaxMinAvgIntensity().
void BitObject::readFromStream | ( | std::istream & | is | ) |
read the BitObject from the input stream is
Definition at line 327 of file BitObject.C.
References PnmParser::getFrame(), and Rectangle::tlbrI().
Referenced by BitObject().
Reset to a new object.
img | image containing only the object the object pixels are 1, all other pixels are 0; |
Definition at line 133 of file BitObject.C.
References ASSERT, freeMem(), getCentroidFirstLast(), Image< T >::getDims(), Image< T >::initialized(), Vector2D::reset(), sumXY(), and Rectangle::tlbrI().
Image< byte > BitObject::reset | ( | const Image< byte > & | img, | |
const Point2D< int > | location, | |||
const byte | threshold = 1 | |||
) |
Reset to a new object.
img | Image from which the object is extracted | |
location | a point that is inside the object - the object is flooded starting from this seed | |
threshold | for flooding |
Definition at line 83 of file BitObject.C.
References area(), ASSERT, floodCleanBB(), freeMem(), getCentroidFirstLast(), Image< T >::getDims(), Image< T >::getHeight(), Image< T >::getWidth(), Image< T >::initialized(), Rectangle::left(), Vector2D::reset(), sumXY(), and Rectangle::top().
Referenced by BitObject(), and extractBitObjects().
void BitObject::setMaxMinAvgIntensity | ( | const Image< T > & | img | ) | [inline] |
Extract the maximum, minimum and average intensity over the object shape in img.
The results are stored in BitObject and can be accessed using getMaxMinAvgIntensity
Definition at line 372 of file BitObject.C.
References ASSERT, Image< T >::begin(), Rectangle::bottomO(), Image< T >::getDims(), Image< T >::getWidth(), isValid(), Rectangle::left(), Rectangle::rightO(), sum(), and Rectangle::top().
void BitObject::writeToStream | ( | std::ostream & | os | ) | const |
write the entire BitObject to the output stream os
Definition at line 275 of file BitObject.C.
References Rectangle::bottomI(), Dims::h(), Rectangle::isValid(), Rectangle::left(), Rectangle::rightI(), Rectangle::top(), Dims::w(), PnmWriter::writeAsciiBW(), and Vector2D::writeToStream().
Referenced by Token::writeToStream().