[Insight-users] extracting partial image and sending it over a network

Luis Ibanez luis.ibanez@kitware.com
Thu May 13 20:43:42 EDT 2004


Hi Michael,


Thanks for your very clear and pictorial email.


There is probably not a built-in functionlity in
ITK that will allow you to do this in a single shot.


However here is one option that should be too hard
to implement.



A) Let's assume that you have

     - Your image
     - A binary mask that defines the
       region to be transmited. We assume
       this mask to have the same grid as
       the image. That is: same spacing
       same number of pixels alon each dimension,
       and same origin.



B) You can do Run Length Encoding (RLE) on the
    region in the following way:


    B.1) Encoder:

    typedef itk::Image< PixelType, Dimension > ImageType;
    typedef ImageType::IndexType               IndexType;

    std::vector< IndexType > startIndices;
    std::vector< IndexType > stopIndices;
    std::vector< PixelType > pixelData;

    typedef itk::ImageRegionConstIterator<
                           ImageType > IteratorType;

    ImageType::RegionType region = image->GetBufferedRegion() );
    IteratorType it( image, region );
    IteratorType mt( mask,  region );

    it.GoToBegin();
    mt.GoToBegin();

    bool isInside = false;

    while( !it.IsAtEnd() )
       {
       if( mt.Get() )
         {
         if( !isInside ) // if it wasn't inside...
           { // this index starts a line with content
           startIndices.push_back( mt.GetIndex() );
           isInside = true; // now we are inside
           }
         pixelData.push_back( it.Get() );
         }
       else
         {
         if( isInside ) // if it was inside...
           { // this index is at the exit of the region line.
           stopIndices.push_back( mt.GetIndex() );
           isInside = false;
           }
         }
       ++it;
       ++mt;
       }

    At the end of this process you have

     startIndices = The list of indices where you start a
                    line with image content

     stopIndices  = The list of indices where the line segment
                    with content ends.

     pixelData    = pixel values to be assigned to the pixels
                    inside the mask.


     You push these three arrays through the Network....



              --------------------------------


    Then, on the other side you put the decoder:


    B.2) Dencoder:


    typedef itk::Image< PixelType, Dimension > ImageType;
    typedef ImageType::IndexType               IndexType;

    std::vector< IndexType > startIndices = GetFromNetwork(1);
    std::vector< IndexType > stopIndices  = GetFromNetwork(2);
    std::vector< PixelType > pixelData    = GetFromNetwork(3);

    typedef itk::ImageRegionConstIterator<
                           ImageType > IteratorType;

    ImageType::Pointer image =
                 CreateImageWithCorrectSizeSpacingAndOriging();

    ImageType::RegionType region = image->GetBufferedRegion() );
    IteratorType it( image, region );

    typedef std::vector< IndexType >::const_iterator indexItr;

    indexItr  start = startIndices.begin();
    indexItr  stop  = stopIndices.begin();

    typedef std::vector< PixelType >::const_iterator  pixelItr;

    pixelItr pixels = pixelData.begin();

    bool isInside = false;

    it.GoToBegin();

    while( !it.IsAtEnd() )
       {
       if( !isInside && (it.GetIndex() == *start ) )
         {
         isInside = true;
         start++;
         }

       if( isInside && (it.GetIndex() == *stop) )
         {
         isInside = false;
         stop++;
         }

       if( isInside )
         {
         image.SetPixel( it.GetIndex() , *pixels );
         pixels++;
         }

       ++it;
       }



---------------------------------


Since images ususally have local corelation you will
probably be able to further commpress the amount
of data transmited by using differecial encoding:
e.g. sending the different between a pixel and its
previous value, and encoding such values using Hoffman
codes.  Note that in this encoding you want to skip
the differences between the last pixel of one line
segment and the first pixels of the next. These two
pixels will probably lack any coherence.



Regards,


   Luis




------------------

Michael wrote:

> Hi,
> 
> is there an elegant solution within ITK that allows me to extract a 
> (non-cubic) part of an image such that I can send it over a network and 
> reconstruct it there?
> 
> Say, I have an image like this:
> 
> --------------------------------
> ¦                ______          ¦
> ¦               /     /          ¦
> ¦              /     /           ¦
> ¦             /     /            ¦
> ¦            /     /             ¦
> ¦           /     /              ¦
> ¦          /     /               ¦
> ¦         /     /                ¦
> ¦        /     /                 ¦
> ¦       /   --                   ¦
> ¦      /    \                    ¦
> ¦     /      \                   ¦
> ¦     --------                   ¦
> ¦                                ¦
> ¦                                ¦
> --------------------------------
> 
> I would like to extract either the exact shape shown above, or something 
> as shown below.
> 
> --------------------------------
> ¦                _______         ¦
> ¦               /     / /        ¦
> ¦              /     / /         ¦
> ¦             /     / /          ¦
> ¦            /     / /           ¦
> ¦           /     / /            ¦
> ¦          /     / /             ¦
> ¦         /     / /              ¦
> ¦        /     / /               ¦
> ¦       /   --  /                ¦
> ¦      /    \  /                 ¦
> ¦     /      \/                  ¦
> ¦     --------                   ¦
> ¦                                ¦
> ¦                                ¦
> --------------------------------
> 
> I DO NOT want, however, to cut the image along the coordinate axes, as 
> shown below. The reason is that I want to minimize the data amount to be 
> sent over the network.
> 
> --------------------------------
> ¦      ________________          ¦
> ¦     ¦         /     /¦         ¦
> ¦     ¦        /     / ¦         ¦
> ¦     ¦       /     /  ¦         ¦
> ¦     ¦      /     /   ¦         ¦
> ¦     ¦     /     /    ¦         ¦
> ¦     ¦    /     /     ¦         ¦
> ¦     ¦   /     /      ¦         ¦
> ¦     ¦  /     /       ¦         ¦
> ¦     ¦ /   --         ¦         ¦
> ¦     ¦/    \          ¦         ¦
> ¦     /      \         ¦         ¦
> ¦     -----------------          ¦
> ¦                                ¦
> ¦                                ¦
> --------------------------------
> 
> Are there any methods withing ITK that help to ease this task?
> 
> Thanks,
> 
> Michael
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 






More information about the Insight-users mailing list