[Insight-users] Isolated Connected Filter: How the threshold
is determined?
Luis Ibanez
luis.ibanez at kitware.com
Sat Jan 8 10:15:33 EST 2005
Hi Quan,
Ahhh ! The pleasure of Open Source:
Just look at the code
Lines 130-257 of
Insight/Code/BasicFilter/
itkIsolatedConnectedImageFilter.txx
{
AccumulateType lower = static_cast<AccumulateType>(m_Lower);
AccumulateType upper = static_cast<AccumulateType>(m_Upper);
AccumulateType guess = upper;
// do a binary search to find an upper threshold that separates the
// two sets of seeds.
const unsigned int maximumIterationsInBinarySearch =
static_cast< unsigned int > (
log( ( static_cast<float>( upper ) -
static_cast<float>( lower ) ) /
static_cast<float>(m_IsolatedValueTolerance))/log(2.0) );
while (lower + m_IsolatedValueTolerance < guess)
{
outputImage->FillBuffer(umericTraits<OutputImagePixelType>::Zero);
function->ThresholdBetween ( m_Lower,
static_cast<InputImagePixelType>(guess));
it.GoToBegin();
while( !it.IsAtEnd())
{
it.Set(m_ReplaceValue);
if (it.GetIndex() == *m_Seeds2.begin())
{
break;
}
++it;
}
// If any of second seeds are included, decrease the upper bound.
// Find the sum of the intensities in m_Seeds2. If the second
// seeds are not included, the sum should be zero. Otherwise,
// it will be other than zero.
InputRealType seedIntensitySum = 0;
typename SeedsContainerType::const_iterator si = m_Seeds2.begin();
typename SeedsContainerType::const_iterator li = m_Seeds2.end();
while( si != li )
{
const InputRealType value =
static_cast< InputRealType >( outputImage->GetPixel( *si ) );
seedIntensitySum += value;
si++;
}
if (seedIntensitySum != 0)
{
upper = guess;
}
// Otherwise, increase the lower bound.
else
{
lower = guess;
}
guess = (upper + lower) /2;
}
m_IsolatedValue = static_cast<InputImagePixelType>(lower);
//the lower bound on the upper threshold guess
}
As you can see, this is a binary search, and because at every
iteration the leap is reduced by half, the stopping criterion
is defined as the moment when the leap is smaller than the
tolerance (m_IsolatedValueTolerance).
Using the mean of the two seed values may overestimate or
underestimate the threshold value.
Regards,
Luis
-----------------------
Quan Chen wrote:
> The manual said only "A binary search is used". Why not just the mean
> of the two seed value? I read the previous question about this filter
> at
> http://public.kitware.com/pipermail/insight-users/2004-February/006599.html but
> still not get how the threshold is determined and varied during the
> iteration, therefore, I am still not get the "variation of the threshold
> is under a tolerance" thing.
>
> Anyone could provide me some info?
>
> thanks.
>
> Quan
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list