forked from InsightSoftwareConsortium/ITK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itkMRFImageFilter.txx
693 lines (562 loc) · 21.6 KB
/
itkMRFImageFilter.txx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkMRFImageFilter.txx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _itkMRFImageFilter_txx
#define _itkMRFImageFilter_txx
#include "itkMRFImageFilter.h"
namespace itk
{
template<class TInputImage, class TClassifiedImage>
MRFImageFilter<TInputImage,TClassifiedImage>
::MRFImageFilter(void):
m_NumberOfClasses(0),
m_MaximumNumberOfIterations(50),
m_ErrorCounter(0),
m_NeighborhoodSize(27),
m_TotalNumberOfValidPixelsInOutputImage(1),
m_TotalNumberOfPixelsInInputImage(1),
m_ErrorTolerance(0.2),
m_SmoothingFactor(1),
m_ClassProbability(0),
m_NumberOfIterations(0),
m_StopCondition(MaximumNumberOfIterations),
m_ClassifierPtr(0)
{
if( (int)InputImageDimension != (int)ClassifiedImageDimension )
{
OStringStream msg;
msg << "Input image dimension: " << InputImageDimension << " != output image dimension: " << ClassifiedImageDimension;
throw ExceptionObject(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION);
}
m_InputImageNeighborhoodRadius.Fill(0);
m_MRFNeighborhoodWeight.resize(0);
m_NeighborInfluence.resize(0);
m_DummyVector.resize(0);
this->SetMRFNeighborhoodWeight( m_DummyVector );
this->SetDefaultMRFNeighborhoodWeight();
}
template<class TInputImage, class TClassifiedImage>
MRFImageFilter<TInputImage, TClassifiedImage>
::~MRFImageFilter(void)
{
}
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::PrintSelf( std::ostream& os, Indent indent ) const
{
Superclass::PrintSelf(os,indent);
unsigned int i;
os << indent <<" MRF Image filter object " << std::endl;
os << indent <<" Number of classes: " << m_NumberOfClasses << std::endl;
os << indent <<" Maximum number of iterations: " <<
m_MaximumNumberOfIterations << std::endl;
os << indent <<" Error tolerance for convergence: " <<
m_ErrorTolerance << std::endl;
os << indent <<" Size of the MRF neighborhood radius:" <<
m_InputImageNeighborhoodRadius << std::endl;
os << indent <<" Number of elements in MRF neighborhood :" <<
static_cast<unsigned long>( m_MRFNeighborhoodWeight.size() ) << std::endl;
os << indent <<" Neighborhood weight : [";
const unsigned int neighborhoodWeightSize =
static_cast<unsigned int>( m_MRFNeighborhoodWeight.size() );
for (i=0; i+1 < neighborhoodWeightSize; i++)
{
os << m_MRFNeighborhoodWeight[i] << ", ";
}
os << m_MRFNeighborhoodWeight[i] << "]" << std::endl;
os << indent <<" Smoothing factor for the MRF neighborhood:" <<
m_SmoothingFactor << std::endl;
os << indent << "StopCondition: "
<< m_StopCondition << std::endl;
os << indent <<" Number of iterations: " <<
m_NumberOfIterations << std::endl;
}// end PrintSelf
/*
* GenerateInputRequestedRegion method.
*/
template <class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::GenerateInputRequestedRegion()
{
// this filter requires the all of the input images
// to be at the size of the output requested region
InputImagePointer inputPtr =
const_cast< InputImageType * >( this->GetInput() );
OutputImagePointer outputPtr = this->GetOutput();
if (inputPtr && outputPtr)
{
inputPtr->SetRequestedRegion( outputPtr->GetRequestedRegion() );
}
}
/*
* EnlargeOutputRequestedRegion method.
*/
template <class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::EnlargeOutputRequestedRegion(
DataObject *output )
{
// this filter requires the all of the output image to be in
// the buffer
TClassifiedImage *imgData;
imgData = dynamic_cast<TClassifiedImage*>( output );
imgData->SetRequestedRegionToLargestPossibleRegion();
}
/*
* GenerateOutputInformation method.
*/
template <class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::GenerateOutputInformation()
{
typename TInputImage::ConstPointer input = this->GetInput();
typename TClassifiedImage::Pointer output = this->GetOutput();
output->SetLargestPossibleRegion( input->GetLargestPossibleRegion() );
}
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::GenerateData()
{
//First run the Gaussian classifier calculator and
//generate the Gaussian model for the different classes
//and then generate the initial labelled dataset.
InputImageConstPointer inputImage = this->GetInput();
//Give the input image and training image set to the
// classifier
m_ClassifierPtr->SetInputImage( inputImage );
//Run the gaussian classifier algorithm
m_ClassifierPtr->Update();
//Allocate memory for the labelled images
this->Allocate();
this->ApplyMRFImageFilter();
//Set the output labelled and allocate the memory
LabelledImagePointer outputPtr = this->GetOutput();
//Allocate the output buffer memory
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
outputPtr->Allocate();
//--------------------------------------------------------------------
//Copy labelling result to the output buffer
//--------------------------------------------------------------------
// Set the iterators to the processed image
//--------------------------------------------------------------------
LabelledImageRegionIterator
labelledImageIt( m_ClassifierPtr->GetClassifiedImage(),
outputPtr->GetRequestedRegion() );
//--------------------------------------------------------------------
// Set the iterators to the output image buffer
//--------------------------------------------------------------------
LabelledImageRegionIterator
outImageIt( outputPtr, outputPtr->GetRequestedRegion() );
//--------------------------------------------------------------------
while ( !outImageIt.IsAtEnd() )
{
LabelledImagePixelType labelvalue =
( LabelledImagePixelType ) labelledImageIt.Get();
outImageIt.Set( labelvalue );
++labelledImageIt;
++outImageIt;
}// end while
}// end GenerateData
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::SetClassifier( typename ClassifierType::Pointer ptrToClassifier )
{
if( ( ptrToClassifier.IsNull() ) || (m_NumberOfClasses <= 0) )
{
throw ExceptionObject(__FILE__, __LINE__,"NumberOfClasses is <= 0",ITK_LOCATION);
}
m_ClassifierPtr = ptrToClassifier;
m_ClassifierPtr->SetNumberOfClasses( m_NumberOfClasses );
}//end SetPtrToClassifier
//-------------------------------------------------------
//Set the neighborhood radius
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::SetNeighborhoodRadius( const unsigned long radiusValue)
{
//Set up the neighbor hood
NeighborhoodRadiusType radius;
for(unsigned int i=0;i < InputImageDimension; ++i)
{
radius[i] = radiusValue;
}
this->SetNeighborhoodRadius( radius );
}// end SetNeighborhoodRadius
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::SetNeighborhoodRadius( const unsigned long *radiusArray)
{
NeighborhoodRadiusType radius;
for(unsigned int i=0;i < InputImageDimension; ++i)
{
radius[i] = radiusArray[i];
}
//Set up the neighbor hood
this->SetNeighborhoodRadius( radius );
}// end SetNeighborhoodRadius
//Set the neighborhood radius
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::SetNeighborhoodRadius( const NeighborhoodRadiusType &radius)
{
//Set up the neighbor hood
for(unsigned int i=0;i < InputImageDimension; ++i)
{
m_InputImageNeighborhoodRadius[ i ] =
radius[ i ];
m_LabelledImageNeighborhoodRadius[ i ] =
radius[ i ];
m_LabelStatusImageNeighborhoodRadius[ i ] =
radius[ i ];
}
}// end SetNeighborhoodRadius
//-------------------------------------------------------
//-------------------------------------------------------
//Set the neighborhood weights
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::SetDefaultMRFNeighborhoodWeight( )
{
// Set the beta matrix of a 3x3x3 kernel
// The index starts from 0 going along the three dimensions
// in the order of [coloumn], [row], [depth].
//Allocate memory for the weights of the 3D MRF algorithm
// and corresponding memory offsets.
//-----------------------------------------------------
//Determine the default neighborhood size
//-----------------------------------------------------
m_NeighborhoodSize = 1;
int neighborhoodRadius = 1; //Default assumes a radius of 1
for( unsigned int i = 0; i < InputImageDimension; i++ )
{
m_NeighborhoodSize *= (2*neighborhoodRadius+1);
}
if( (InputImageDimension == 3) )
{
//Assumes a default 3x3x3 window size
m_MRFNeighborhoodWeight.resize( m_NeighborhoodSize );
for( int i = 0; i < 9; i++ )
m_MRFNeighborhoodWeight[i] = 1.3 * m_SmoothingFactor;
for( int i = 9; i < 18; i++ )
m_MRFNeighborhoodWeight[i] = 1.7 * m_SmoothingFactor;
for( int i = 18; i < 27; i++ )
m_MRFNeighborhoodWeight[i] = 1.3 * m_SmoothingFactor;
// Change the center weights
m_MRFNeighborhoodWeight[4] = 1.5 * m_SmoothingFactor;
m_MRFNeighborhoodWeight[13] = 0.0;
m_MRFNeighborhoodWeight[22] = 1.5 * m_SmoothingFactor;
}
if( (InputImageDimension == 2) )
{
//Assumes a default 3x3x3 window size
m_MRFNeighborhoodWeight.resize( m_NeighborhoodSize );
for( int i = 0; i < m_NeighborhoodSize; i++ )
m_MRFNeighborhoodWeight[i] = 1.7 * m_SmoothingFactor;
// Change the center weights
m_MRFNeighborhoodWeight[4] = 0;
} else
if( (InputImageDimension > 3) )
{
for( int i = 0; i < m_NeighborhoodSize; i++ )
{
m_MRFNeighborhoodWeight[i] = 1;
}
}
}// SetMRFNeighborhoodWeight
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::SetMRFNeighborhoodWeight( std::vector<double> betaMatrix)
{
if( betaMatrix.size() == 0 )
{
//Call a the function to set the default neighborhood
this->SetDefaultMRFNeighborhoodWeight();
}
else
{
m_NeighborhoodSize = 1;
for( unsigned int i = 0; i < InputImageDimension; i++ )
{
m_NeighborhoodSize *= (2*m_InputImageNeighborhoodRadius[i]+1);
}
if( m_NeighborhoodSize != static_cast<int>(betaMatrix.size()) )
{
throw ExceptionObject(__FILE__, __LINE__, "NeighborhoodSize != betaMatrix.szie()", ITK_LOCATION);
}
//Allocate memory for the weights of the 3D MRF algorithm
// and corresponding memory offsets.
m_MRFNeighborhoodWeight.resize( m_NeighborhoodSize );
for( unsigned int i = 0; i < betaMatrix.size(); i++ )
{
m_MRFNeighborhoodWeight[i] = (betaMatrix[i] * m_SmoothingFactor);
}
}
}// end SetDefaultMRFNeighborhoodWeight
//-------------------------------------------------------
//-------------------------------------------------------
//Allocate algorithm specific resources
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::Allocate()
{
if( m_NumberOfClasses <= 0 )
{
throw ExceptionObject(__FILE__, __LINE__,"NumberOfClasses <= 0.",ITK_LOCATION);
}
InputImageSizeType inputImageSize = this->GetInput()->GetBufferedRegion().GetSize();
//---------------------------------------------------------------------
//Get the number of valid pixels in the output MRF image
//---------------------------------------------------------------------
int tmp;
for( unsigned int i=0; i < InputImageDimension; i++ )
{
tmp = static_cast<int>(inputImageSize[i]);
m_TotalNumberOfPixelsInInputImage *= tmp;
m_TotalNumberOfValidPixelsInOutputImage *=
( tmp - 2*m_InputImageNeighborhoodRadius[i] );
}
//Allocate the label image status
LabelStatusIndexType index;
index.Fill(0);
LabelStatusRegionType region;
region.SetSize( inputImageSize );
region.SetIndex( index );
m_LabelStatusImage = LabelStatusImageType::New();
m_LabelStatusImage->SetLargestPossibleRegion( region );
m_LabelStatusImage->SetBufferedRegion( region );
m_LabelStatusImage->Allocate();
LabelStatusImageIterator rIter( m_LabelStatusImage,
m_LabelStatusImage->GetBufferedRegion() );
//Initialize the label status image to 1
while( !rIter.IsAtEnd() )
{
rIter.Set( 1 );
++rIter;
}
}// Allocate
//-------------------------------------------------------
//-------------------------------------------------------
//Apply the MRF image filter
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::ApplyMRFImageFilter()
{
InputImageSizeType inputImageSize =
this->GetInput()->GetBufferedRegion().GetSize();
int totalNumberOfPixelsInInputImage = 1;
for( unsigned int i = 0; i < InputImageDimension; i++ )
{
totalNumberOfPixelsInInputImage *= static_cast<int>(inputImageSize[ i ]) ;
}
int maxNumPixelError = (int) ( vnl_math_rnd (m_ErrorTolerance *
m_TotalNumberOfValidPixelsInOutputImage) );
m_NumberOfIterations = 0;
do
{
itkDebugMacro(<< "Iteration No." << m_NumberOfIterations);
MinimizeFunctional();
m_NumberOfIterations += 1;
m_ErrorCounter = m_TotalNumberOfValidPixelsInOutputImage -
totalNumberOfPixelsInInputImage;
LabelStatusImageIterator rIter( m_LabelStatusImage,
m_LabelStatusImage->GetBufferedRegion() );
//Initialize the label status image to 1
while( !rIter.IsAtEnd() )
{
if ( rIter.Get( ) == 1 ) m_ErrorCounter += 1;
++rIter;
}
}
while(( m_NumberOfIterations < m_MaximumNumberOfIterations ) &&
( m_ErrorCounter > maxNumPixelError ) );
//Determine stop condition
if( m_NumberOfIterations >= m_MaximumNumberOfIterations )
{
m_StopCondition = MaximumNumberOfIterations;
}
else if( m_ErrorCounter <= maxNumPixelError )
{
m_StopCondition = ErrorTolerance;
}
}// ApplyMRFImageFilter
//-------------------------------------------------------
//-------------------------------------------------------
//Minimize the functional
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::MinimizeFunctional()
{
//This implementation uses the ICM algorithm
ApplyICMLabeller();
}
//-------------------------------------------------------
//-------------------------------------------------------
//Core of the ICM algorithm
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::ApplyICMLabeller()
{
//---------------------------------------------------------------------
// Loop through the data set and classify the data
//---------------------------------------------------------------------
m_NeighborInfluence.resize( m_NumberOfClasses );
//Varible to store the input pixel vector value
//InputImagePixelType inputPixel;
m_MahalanobisDistance.resize( m_NumberOfClasses );
//---------------------------------------------------------------------
// Set up the neighborhood iterators and the valid neighborhoods
// for iteration
//---------------------------------------------------------------------
//Set up the nighborhood iterators
//Define the face list for the input/labelled image
InputImageFacesCalculator inputImageFacesCalculator;
LabelledImageFacesCalculator labelledImageFacesCalculator;
LabelStatusImageFacesCalculator labelStatusImageFacesCalculator;
InputImageFaceListType inputImageFaceList;
LabelledImageFaceListType labelledImageFaceList;
LabelStatusImageFaceListType labelStatusImageFaceList;
//Compute the faces for the neighborhoods in the input/labelled image
InputImageConstPointer inputImage = this->GetInput();
inputImageFaceList =
inputImageFacesCalculator( inputImage,
inputImage->GetBufferedRegion(),
m_InputImageNeighborhoodRadius );
LabelledImagePointer labelledImage = m_ClassifierPtr->GetClassifiedImage();
labelledImageFaceList =
labelledImageFacesCalculator( labelledImage,
labelledImage->GetBufferedRegion(),
m_LabelledImageNeighborhoodRadius );
labelStatusImageFaceList =
labelStatusImageFacesCalculator( m_LabelStatusImage,
m_LabelStatusImage->GetBufferedRegion(),
m_LabelStatusImageNeighborhoodRadius );
//Set up a face list iterator
InputImageFaceListIterator inputImageFaceListIter
= inputImageFaceList.begin();
LabelledImageFaceListIterator labelledImageFaceListIter
= labelledImageFaceList.begin();
LabelStatusImageFaceListIterator labelStatusImageFaceListIter
= labelStatusImageFaceList.begin();
//Walk through the entire data set (not visiting the boundaries )
InputImageNeighborhoodIterator
nInputImageNeighborhoodIter( m_InputImageNeighborhoodRadius,
inputImage,
*inputImageFaceListIter );
LabelledImageNeighborhoodIterator
nLabelledImageNeighborhoodIter( m_LabelledImageNeighborhoodRadius,
labelledImage,
*labelledImageFaceListIter );
LabelStatusImageNeighborhoodIterator
nLabelStatusImageNeighborhoodIter( m_LabelStatusImageNeighborhoodRadius,
m_LabelStatusImage,
*labelStatusImageFaceListIter );
//---------------------------------------------------------------------
while( !nInputImageNeighborhoodIter.IsAtEnd() )
{
//Process each neighborhood
this->DoNeighborhoodOperation( nInputImageNeighborhoodIter,
nLabelledImageNeighborhoodIter,
nLabelStatusImageNeighborhoodIter );
++nInputImageNeighborhoodIter;
++nLabelledImageNeighborhoodIter;
++nLabelStatusImageNeighborhoodIter;
}
}//ApplyICMlabeller
//-------------------------------------------------------
//-------------------------------------------------------
//Function that performs the MRF operation with each neighborhood
//-------------------------------------------------------
template<class TInputImage, class TClassifiedImage>
void
MRFImageFilter<TInputImage, TClassifiedImage>
::DoNeighborhoodOperation( const InputImageNeighborhoodIterator &imageIter,
LabelledImageNeighborhoodIterator &labelledIter,
LabelStatusImageNeighborhoodIterator &labelStatusIter )
{
unsigned int index;
//Read the pixel of interest and get its corresponding membership value
InputImagePixelType *inputPixelVec = imageIter.GetCenterValue();
const std::vector<double> & pixelMembershipValue =
m_ClassifierPtr->GetPixelMembershipValue( *inputPixelVec );
//Reinitialize the neighborhood influence at the beginning of the
//neighborhood operation
for( index = 0; index < m_NeighborInfluence.size() ;index++ )
{
m_NeighborInfluence[index]= 0;
}
LabelledImagePixelType labelledPixel;
//Begin neighborhood processing. Calculate the prior for each label
for( int i = 0; i < m_NeighborhoodSize; ++i )
{
labelledPixel = labelledIter.GetPixel( i );
index = (unsigned int) labelledPixel;
m_NeighborInfluence[ index ] += m_MRFNeighborhoodWeight[ i ];
}//End neighborhood processing
//Add the prior probability to the pixel probability
for( index = 0; index < m_NumberOfClasses; index++ )
{
m_MahalanobisDistance[index] = m_NeighborInfluence[index] -
pixelMembershipValue[index] ;
}
//Determine the maximum possible distance
double maximumDistance = -1e+20;
int pixLabel = -1;
double tmpPixDistance;
for( index = 0; index < m_NumberOfClasses; index++ )
{
tmpPixDistance = m_MahalanobisDistance[index];
if ( tmpPixDistance > maximumDistance )
{
maximumDistance = tmpPixDistance;
pixLabel = index;
}// if
}// for
//Read the current pixel label
LabelledImagePixelType *previousLabel = labelledIter.GetCenterValue();
//Check if the labelled pixel value in the previous iteration has changed
//If the value has changed then update the m_LabelStatus set;
if( pixLabel != (int) ( *previousLabel ) )
{
labelledIter.SetCenterPixel( pixLabel );
for( int i = 0; i < m_NeighborhoodSize; ++i )
{
labelStatusIter.SetPixel( i, 1 );
}//End neighborhood processing
}//end if
else
{
labelStatusIter.SetCenterPixel( 0 );
}
}// end DoNeighborhoodOperation
} // namespace itk
#endif