[Insight-users] EstimateGaussianModelPrameters

Cook, Gregory W. grecook at iupui . edu
Thu, 23 Oct 2003 12:30:48 -0500


Has anyone tried to use GibbsPriorImageFilter1.cxx lately?   I was
unable to get this to run correctly until I repaired what I
believe is a bug in EstimateGaussianModelPrameters()
which is in the itkImageGaussModelEstimator.txx file.

(BTW, Prameters is misspelled and should of course be Parameters.  Easy to
miss.)

These are the steps I took and my reasoning:

First, since the test files are missing I created a training file for
BrainProtonDensitySlice.png called BrainProtonDensitySlice-training.png,
where several small areas were labeled with integer values indicating that
the corresponding pixels in the input image were to be used as training
data.   They, according to the
documentation, should be labeled with positive integers (not including
zero.)
The documentation is unclear about labeling things with zero.   It does
specify
that negative integers (not including zero) would be ignored.

As it turns out neither of these is true:  with the code as presently
written
you *cannot* have negative labels of any kind.  Further, you also cannot
have labels of zero, but zero labels will always be counted and a
distribution
computed forcing the model size to be one larger than intended and causing
trouble later in the program.  Here's why the first is true:

In EstimateGaussianModelPrameters()  the line

unsigned int classIndex = (unsigned int) trainingImageIt.Get();

will (silently) force negative trainingImage values to be large positive
ones.

Here's why the second is true:
The conditional

if(classIndex > 0)

makes sure that 0 values are ignored.  (From above they can't be negative.)
However, the following for block is:

for( unsigned int classIndex = 0; classIndex < numberOfModels;
classIndex++ )

Thus 0 values (labels), which cannot have any correct statistics associated
with them, will always
have the mean and variance computed.

I have modified  the lines above in itkImageGaussModelEstimator.txx
to

TTrainingImage::ValueType classIndex = trainingImageIt.Get();

and

if(classIndex >= 0)

which seems to fix the problem if you assume that negative values are to be
ignored and labels need to  be in the range of 0 to numberOfModels-1.

There are also a few modifications that need to be made to
GibbsPriorImageFilter1.cxx,
chiefly because short values instead of unsigned short are specified, which
causes an extra
cast filter to be required on the output stage for PNG files.

I would appreciate comments and will post these modifications as a bug
report unless I am wrong in my
reasoning somewhere.

Thanks,
Greg Cook