[Insight-developers] MRF : VectorType , Traits , Adaptors & Iterators

Luis Ibanez ibanez@cs.unc.edu
Tue, 30 Jan 2001 15:27:38 -0500


Hi,

Recent changes in itkVector affected the file itkMRFLabellerTest.cxx.

The type VectorType was removed from itk::Vector,
and this type was expected on MRFLabellerTest.

The basic change is that with adaptors, it is no longer needed to use
Set/GetScalar() and Set/GetVector() when accessing a pixel in an image.

The following code was used to store a value in an pixel of an
unsigned short image:

 ClassImagePixelType  outputPixel;
 ClassImageIterator   classoutIt( classImage,
                                  classImage->GetBufferedRegion() );

  itk::ScalarTraits<ClassImagePixelType>::SetScalar(outputPixel, 0 );
  *classoutIt = outputPixel;
  ++classoutIt;


This now can be written just as:

   classoutIt.Set( 0 );
   ++classoutIt;


There was also a particular use for iterators, like:

 ClassImageIterator labeloutIt( outClassImage,
 outClassImage->GetBufferedRegion() );

 labeloutIt.Begin();
 ClassImageIterator labeloutItEnd = labeloutIt.End();

 labeloutIt = labeloutIt.Begin();
 labeloutItEnd = labeloutIt.End();

 while(labeloutIt != labeloutItEnd)
 {
    ...
    ++labeloutIt;
 }


There are several overload in this code.

1- The iterator is initialized with a call to its own Begin(),   
   it = it.Begin. while it.Begin() is enough for initializing 
   the iterator.

2- The end of the region is extracted and stored in another 
   iterator : itend  = itend.End(); this one is used to compare 
   with, during the while loop that goes through the region.
   For a N-D image, that implies N comparisions each time the 
   while loop is tested.


Iterators can be used more efficiently with a sequence like:

   typedef   ImageIterator< ImageType >  IteratorType;
   IteratorType  it(   image, image->GetRequestedRegion() );
   it.begin();  
   while( !  it.IsAtEnd() )  
   {
     ++it;
   }



-----


Access to pixels of vector type  where of the type:


  IteratorType  it(   image, image->GetRequestedRegion() );
 (* it).SetVector(  vectorValue );


But, given that the image is of pixeltype  Vector, this can be just

  IteratorType  it(   image, image->GetRequestedRegion() );
  it.Set(  vectorValue  );



Reading values from pixed were done by:


   int classIndex = 
      (int) itk::ScalarTraits<ClassImagePixelType>::GetScalar(
                                                    *labeloutIt );

This can now be just:
 
   int classIndex = (int) labeloutIt.Get();


-----

These changes have been made on MRFLabelTest.cxx 
and similar code changes were done in

itkClassifier
itkSupervisedClassifier
itkGaussianSupervisedClassifier
itkMRFLabeller

txx & h files

----------

The code is now compiling but not running...

There is a saturation of an unsigned short in 
itkMRFLabeller.txx: 

line: 446
            //Read the classified pixels from the labelled image
            tempLabelled = labelledImageIt.Get();
            tempLabelled += offset;
            labelledImageIt.Set( tempLabelled );

            labelledPixel = tempLabelled;
                
            //Assuems that the MRF label is an image with 1 value
            //per pixel and is treated as a vector with 1 entry
            // pervector
            int index = (int) labelledPixel;
    
            //Do the prior probability calculations for each class
            //in the 3x3x3 neighborhood
>>>>>>>     neighborInfluence[index] += m_Beta3x3x3[k];       
index == 65536  
pass the end of the array neighborInfluence
>>>>>>>>
          }// end if
line: 460


I'll try to get advice from Sayan regarding 
how to trace this error.


----

Thanks


Luis