#include <ParzenDistributionForce.h>
Inheritance diagram for lsseg::ParzenDistributionForce:
Public Member Functions | |
ParzenDistributionForce (bool multireg_mode=false) | |
Constructor making a ParzenDistributionForce-generator which will have to be initialized with the init() function before being usable. | |
ParzenDistributionForce (const Image< double > *img, Mask *mask=0, bool multireg_mode=false) | |
Constructor. | |
virtual | ~ParzenDistributionForce () |
virtual void | init (const Image< double > *img, const Mask *mask=0) |
Initialize the ForceGenerator. | |
virtual void | update (const LevelSetFunction &phi) |
Update the force field based on a given segmentation of an image. | |
virtual double | force2D (int x, int y) const |
Get the normal force value of a (x, y) location in the current normal force field. | |
virtual double | force3D (int x, int y, int z) const |
Get the normal force value of a (x, y, z) location in the current normal force field. | |
virtual double | force (size_t ix) const |
Get the normal force value of a particular pixel, specified by its internal storage index. | |
virtual void | force (LevelSetFunction &, const Mask *mask=0) const |
Get the complete normal force field as a LevelSetFunction. | |
void | saveChannelDistribution (int channel, std::ostream &os, bool inside) const |
Write one of the currently estimated distributions to a stream. | |
void | fixChannelDistributionTo (int channel, std::istream &is, bool inside) |
Read a precomputed distribution for a spesific region/channel from stream, and 'fix' it, i.e., the distribution will not be changed in the future, even if the update() function is called. | |
void | fixDistributionToUniform (int channel, bool inside) |
Fix the distribution for a particular region/channel to a distribution where all pixel values have the same probability. The distribution will then not be changed in the future, even if the update() function is called. | |
void | unfixChannelDistribution (int channel, bool inside) |
Unfix a previously fixed distribution, so that it becomes recomputed whenever the update() function is called. | |
const Image< double > *const | baseImage () const |
get a const-pointer to the underlying Image<T> to segment | |
Private Member Functions | |
void | report () const |
int | getForceBin (double val, int channel) const |
determine the correct 'bin' in the precalc_force_ lookup-array for a given pixel intensity in a given image channel. | |
void | precompute_force (int channel, const Histogram &ihist, const Histogram &ohist, std::vector< double > &forcevec) |
fill out the information in the precalc_force_ table for a particular channel, based on estimated distributions (presented as smoothed histograms). | |
double | getCenterBinValue (int channel, int ix) |
get the value for the "average" or the "center" of a particular channel and bin of the precalc_force_ lookup table. | |
void | get_histogram (int channel, const LevelSetFunction &phi, Histogram &inside_hist, Histogram &outside_hist) const |
compute the estimated region distributions for a given image channel and a given segmentation. | |
Histogram | makeDefaultHistogram (int channel) const |
construct and return an empty histogram based on the pixel value range for a particular channel in the image. | |
Private Attributes | |
const bool | multi_region_mode_ |
flag specifying whether this object is intended to be used in a multi-region setting (see here for an explanation), or if it is to be used in the classical two-region problem. | |
const int | num_force_bins_ |
number of entries ("bins") in the precalculated force vectors (precalc_force_). | |
const Image< double > * | img_ |
pointer to the Image to be segmented | |
const Mask * | mask_ |
pointer to a Mask specifying which parts of the image are considered to be active | |
std::vector< std::pair< bool, bool > > | is_fixed_ |
specify which distributions are 'fixed' (i.e. do not change even though the region changes and update() is called). | |
std::vector< std::pair< Histogram, Histogram > > | hist_ |
vector with one entry for each image channel of img_. Each entry contains the smoothed Histogram (considered as an estimated probability distribution), for the pixels inside and outside the closed region for the corresponding image channel. | |
std::vector< std::pair< double, double > > | channel_ranges_ |
vector with one entry for each image channel of img_. Each entry specifies the max. and min. pixel value found in img_ for the corresponding channel. | |
std::vector< double > | force_bin_factor_ |
contains one entry per image channel. Specifies the inverse of the width of each bin in the precalculated force vector precalc_force_. | |
std::vector< std::vector< double > > | precalc_force_ |
contains one vector per image channel. Each vector is a lookup-table where one can find the resulting force acting on a pixel based on the intensity of that pixel for each image channel. This force is derived from the distributions in hist_, but are precalculated and stored here for optimization reasons. The number of entries ("bins") in each vector has been given by num_force_bins_. Since the distributions in hist_ are apt to change each time update() is called, this vector will change accordingly. |
In the model from which this force is derived, the image regions in the Mumford-Shah functional are modeled by unknown probability distributions which are estimtated from the current segmentation. This is done by computing the pixel distribution for each current region and channel, and smoothing the obtained histograms by convolution with a Gauss kernel. The distributions thus obtained capture more information about the regions than does a parametrized distribution like the one used by the NormalDistributionForce generator (a normal distribution described by its average and mean variation). On the other hand, using a parzen estimate for modeling the regions risk overfitting the data if the histograms are not sufficiently smoothed. For that reason, it is best to apply the ParzenDistributionForce to the region development when departing from an initial segmentation that is already not too bad. For more details, please refer to page 113-118 of Thomas Brox' thesis: [Brox05].
Definition at line 84 of file ParzenDistributionForce.h.
lsseg::ParzenDistributionForce::ParzenDistributionForce | ( | bool | multireg_mode = false |
) | [inline] |
Constructor making a ParzenDistributionForce-generator which will have to be initialized with the init() function before being usable.
multireg_mode | The ParzenDistributionForce-generator is written to also work in a multiregion setting (ie. when segmenting an image into more than two parts using a region competition approach). If you construct this object with the intention of using it in a multiregion setting, set multireg_mode to true . Otherwise (if you intend to use the classical setting with two regions), leave it at false . For more about the multiregion setting, refer to the appropriate section of the page on How Segmentation in LSSEG Works. |
Definition at line 100 of file ParzenDistributionForce.h.
lsseg::ParzenDistributionForce::ParzenDistributionForce | ( | const Image< double > * | img, | |
Mask * | mask = 0 , |
|||
bool | multireg_mode = false | |||
) | [explicit] |
Constructor.
img | pointer to the image to be segmented | |
mask | (pointer to) an optional Mask that specifies which part(s) of the image are active. (No forces will be computed for the inactive part(s) of an image). If this pointer is left at zero, the whole of img is considered to be active. | |
multireg_mode | The ParzenDistributionForce-generator is written to also work in a multiregion setting (ie. when segmenting an image into more than two parts using a region competition approach). If you construct this object with the intention of using it in a multiregion setting, set multireg_mode to true . Otherwise (if you intend to use the classical setting with two regions), leave it at false . For more about the multiregion setting, refer to the appropriate section of the page on How Segmentation in LSSEG Works. |
Definition at line 68 of file ParzenDistributionForce.C.
virtual lsseg::ParzenDistributionForce::~ParzenDistributionForce | ( | ) | [inline, virtual] |
Definition at line 128 of file ParzenDistributionForce.h.
const Image<double>* const lsseg::ParzenDistributionForce::baseImage | ( | ) | const [inline] |
get a const-pointer to the underlying Image<T> to segment
Definition at line 177 of file ParzenDistributionForce.h.
void lsseg::ParzenDistributionForce::fixChannelDistributionTo | ( | int | channel, | |
std::istream & | is, | |||
bool | inside | |||
) |
Read a precomputed distribution for a spesific region/channel from stream, and 'fix' it, i.e., the distribution will not be changed in the future, even if the update() function is called.
channel | specify the image channel of the distribution | |
is | the stream from which to read the precomputed distribution | |
inside | if true , the distribution of the closed region will be read, if false , it is distribution for the outside of the closed region that will be read. |
Definition at line 143 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::fixDistributionToUniform | ( | int | channel, | |
bool | inside | |||
) |
Fix the distribution for a particular region/channel to a distribution where all pixel values have the same probability. The distribution will then not be changed in the future, even if the update() function is called.
channel | specify the image channel of the distribution | |
inside | if true , this call will apply to the inside of the closed region. If false , it is the outside of the closed region that will be fixed. |
Definition at line 126 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::force | ( | LevelSetFunction & | , | |
const Mask * | mask = 0 | |||
) | const [virtual] |
Get the complete normal force field as a LevelSetFunction.
phi | the LevelSetFunction which will, upon completion of the function, contain the force field currently contained in the ForceGenerator |
mask | (pointer to) an optional Mask that specifies which part(s) of the force field are active. (The inactive parts will not be filled into the LevelSetFunction ). If this pointer is left at zero, the whole of the force field is considered to be active. |
Implements lsseg::ForceGenerator.
Definition at line 338 of file ParzenDistributionForce.C.
double lsseg::ParzenDistributionForce::force | ( | size_t | ix | ) | const [virtual] |
Get the normal force value of a particular pixel, specified by its internal storage index.
The internal storage index of any pixel can be found by applying the Image::indexOf() member function.
Implements lsseg::ForceGenerator.
Definition at line 318 of file ParzenDistributionForce.C.
double lsseg::ParzenDistributionForce::force2D | ( | int | x, | |
int | y | |||
) | const [virtual] |
Get the normal force value of a (x, y) location in the current normal force field.
for
3D images, z
is here set to be 0. The method is not overloaded due to performance reasons. For true 3D fields, use the force3D() function instead. Implements lsseg::ForceGenerator.
Definition at line 304 of file ParzenDistributionForce.C.
double lsseg::ParzenDistributionForce::force3D | ( | int | x, | |
int | y, | |||
int | z | |||
) | const [virtual] |
Get the normal force value of a (x, y, z) location in the current normal force field.
Implements lsseg::ForceGenerator.
Definition at line 311 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::get_histogram | ( | int | channel, | |
const LevelSetFunction & | phi, | |||
Histogram & | inside_hist, | |||
Histogram & | outside_hist | |||
) | const [inline, private] |
compute the estimated region distributions for a given image channel and a given segmentation.
channel | specifies the image channel for which the region distributions will be estimated. | |
phi | a level-set function specifying the current segmentation of the image img_ into two regions. |
inside_hist | upon return, this variable will contain the estimated pixel distribution of the inside of the closed segmentation region | |
outside_hist | upon return, this variable will contain the estimated pixel distribution of the outside of the closed segmentation region. |
Definition at line 235 of file ParzenDistributionForce.C.
double lsseg::ParzenDistributionForce::getCenterBinValue | ( | int | channel, | |
int | ix | |||
) | [private] |
get the value for the "average" or the "center" of a particular channel and bin of the precalc_force_ lookup table.
channel | specify the image channel | |
ix | specify the bin by its index |
Definition at line 370 of file ParzenDistributionForce.C.
int lsseg::ParzenDistributionForce::getForceBin | ( | double | val, | |
int | channel | |||
) | const [inline, private] |
determine the correct 'bin' in the precalc_force_ lookup-array for a given pixel intensity in a given image channel.
val | the pixel intensity | |
channel | the image channel |
Definition at line 293 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::init | ( | const Image< double > * | img, | |
const Mask * | mask = 0 | |||
) | [virtual] |
Initialize the ForceGenerator.
img | (pointer to) the image that the ForceGenerator should use to derive the force field (i.e. the Image to be segmented). | |
mask | (pointer to) an optional Mask that specifies which part(s) of the image are active. (No forces will be computed for the inactive part(s) of an image). If this pointer is left at zero, the whole of img is considered to be active. |
Implements lsseg::ForceGenerator.
Definition at line 78 of file ParzenDistributionForce.C.
Histogram lsseg::ParzenDistributionForce::makeDefaultHistogram | ( | int | channel | ) | const [private] |
construct and return an empty histogram based on the pixel value range for a particular channel in the image.
Definition at line 176 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::precompute_force | ( | int | channel, | |
const Histogram & | ihist, | |||
const Histogram & | ohist, | |||
std::vector< double > & | forcevec | |||
) | [private] |
fill out the information in the precalc_force_ table for a particular channel, based on estimated distributions (presented as smoothed histograms).
channel | the channel for which we want to compute the corresponding table in precalc_force_. | |
ihist | Histogram representing the estimated pixel distribution inside the closed region for this particular image channel. | |
ohist | Histogram representing the estimated pixel distribution outside the closed region for this particular image channel. | |
forcevec | vector containing the precomputed forces. When this method is called internally, the corresponding entry in precalc_force_ is always given here. |
Definition at line 379 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::report | ( | ) | const [inline, private] |
void lsseg::ParzenDistributionForce::saveChannelDistribution | ( | int | channel, | |
std::ostream & | os, | |||
bool | inside | |||
) | const |
Write one of the currently estimated distributions to a stream.
channel | specify the image channel of the distribution | |
os | the stream to which the distribution will be written | |
inside | if true , the distribution of the closed region will be written, if false , it is the distribution outside the closed region that will be written. |
Definition at line 112 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::unfixChannelDistribution | ( | int | channel, | |
bool | inside | |||
) |
Unfix a previously fixed distribution, so that it becomes recomputed whenever the update() function is called.
channel | specify the channel of the distribution to unfix | |
inside | specify whether it is the distribution inside or outside the closed region that will be unfixed. |
Definition at line 163 of file ParzenDistributionForce.C.
void lsseg::ParzenDistributionForce::update | ( | const LevelSetFunction & | phi | ) | [virtual] |
Update the force field based on a given segmentation of an image.
phi | this LevelSetFunction should be of the same shape as the Image that the ForceGenerator derives the force field from, and it specifies a segmentation of the Image. Taking this segmentation of the Image into consideration, the ForceGenerator computes the new force field. |
Implements lsseg::ForceGenerator.
Definition at line 204 of file ParzenDistributionForce.C.
std::vector<std::pair<double, double> > lsseg::ParzenDistributionForce::channel_ranges_ [private] |
vector with one entry for each image channel of img_. Each entry specifies the max. and min. pixel value found in img_ for the corresponding channel.
Definition at line 220 of file ParzenDistributionForce.h.
std::vector<double> lsseg::ParzenDistributionForce::force_bin_factor_ [private] |
contains one entry per image channel. Specifies the inverse of the width of each bin in the precalculated force vector precalc_force_.
The width of each bin of a given channel is defined as the total pixel value range of that channel (as found in channel_ranges_), divided by the number of bins (as found in num_force_bins_). For computational optimizing reasons, it is the inverses of the widths that are stored in this vector.
Definition at line 229 of file ParzenDistributionForce.h.
std::vector<std::pair<Histogram, Histogram> > lsseg::ParzenDistributionForce::hist_ [private] |
vector with one entry for each image channel of img_. Each entry contains the smoothed Histogram (considered as an estimated probability distribution), for the pixels inside and outside the closed region for the corresponding image channel.
Definition at line 215 of file ParzenDistributionForce.h.
const Image<double>* lsseg::ParzenDistributionForce::img_ [private] |
std::vector<std::pair<bool, bool> > lsseg::ParzenDistributionForce::is_fixed_ [private] |
specify which distributions are 'fixed' (i.e. do not change even though the region changes and update() is called).
Definition at line 210 of file ParzenDistributionForce.h.
const Mask* lsseg::ParzenDistributionForce::mask_ [private] |
pointer to a Mask specifying which parts of the image are considered to be active
Definition at line 206 of file ParzenDistributionForce.h.
const bool lsseg::ParzenDistributionForce::multi_region_mode_ [private] |
flag specifying whether this object is intended to be used in a multi-region setting (see here for an explanation), or if it is to be used in the classical two-region problem.
Definition at line 184 of file ParzenDistributionForce.h.
const int lsseg::ParzenDistributionForce::num_force_bins_ [private] |
number of entries ("bins") in the precalculated force vectors (precalc_force_).
The force acting on a pixel as a function of its intensity for each image channel depends on the estimated distributions for the different regions. These distributions may change each time the ParzenDistributionForce object is update()d. However, for a given set of distributions, these forces can be precomputed, saving time when computing the complete force field for an image. The various possible force values are stored in a discrete set of "bins", so that one can quickly look up the force for a given pixel by looking at its intensity and determining which bin it belongs to. num_force_bins_ specifies the resolution of this discrete set of bins.
Definition at line 197 of file ParzenDistributionForce.h.
std::vector<std::vector<double> > lsseg::ParzenDistributionForce::precalc_force_ [private] |
contains one vector per image channel. Each vector is a lookup-table where one can find the resulting force acting on a pixel based on the intensity of that pixel for each image channel. This force is derived from the distributions in hist_, but are precalculated and stored here for optimization reasons. The number of entries ("bins") in each vector has been given by num_force_bins_. Since the distributions in hist_ are apt to change each time update() is called, this vector will change accordingly.
Definition at line 238 of file ParzenDistributionForce.h.