[Insight-users] Creating a spatial object from a binary image

Luis Ibanez luis.ibanez at kitware.com
Sat Jun 5 10:07:53 EDT 2004


Hi Vincent,


The new class

        ImageMaskSpatialObject

is now available under


    Insight/Code/SpatialObject


A new example illustrating how to use it in the
context of image registration was added to


    Insight/Examples/Registration
                ImageRegistration12.cxx


This is a variation of ImageRegistration6.cxx.


A regression test has been added using the
BrainProtonDensitySliceBorder20.png image.
and a synthetic mask
BrainProtonDensitySliceBorder20Mask.png

Note that for this particular case it may have
been simpler to use the EllipseSpatialObject
directly.


The computation time for this test passed
from 5 seconds to 3 seconds when adding the
mask. The effect should be even more dramatic
in 3D images where the actual volume occupied
by a brain for example is about 1/4 to 1/10
of the typical total image volume.


Please let us know if you find any problems
or you have any further questions.



   Thanks



      Luis


-------------------
Luis Ibanez wrote:
> 
> Hi Vincent,
> 
> We discussed this issue today in the weekly developers
> meeting and agreed in creating a new SpatialObject
> class called
> 
>           ImageMaskSpatialObject
> 
> With a modified version of the IsInside() method.
> This new class will actually check for the values to
> be on in the binary image mask.
> 
> I'll send you an early version of this class by the
> end of the day so you can give it a try.
> 
> 
> 
>    Regards,
> 
> 
> 
>       Luis
> 
> 
> -------------------
> Vincent Chu wrote:
> 
>> Hi Luis,
>>
>> The quick and dirty fix doesn't seem to work.  The ValueAt function seems
>> to call IsInside indirectly, resulting an infinite recursion.  Any
>> suggestion around this?
>>
>> Thanks,
>>
>> Vincent
>>
>> On Thu, 3 Jun 2004, Luis Ibanez wrote:
>>
>>
>>> Hi Vincent,
>>>
>>> Thanks for pointing this out.
>>>
>>> This looks like a bug in the ImageSpatialObject.
>>>
>>> We just entered as Bug # 909
>>> http://www.itk.org/Bug/bug.php?op=show&bugid=909&pos=0
>>>
>>>
>>> The "IsInside()" method is simply checking if
>>> the point is inside the bounding box of the image.
>>>
>>> As a quick and dirty fix please do the following:
>>>
>>> 1) Go to
>>>
>>>    Insight/Code/SpatialObjects/
>>>                 itkImageSpatialObject.txx
>>>
>>>
>>> 2) Search for lines 68 to 78 where the methods
>>>    "IsInside()" is defined.
>>>
>>> 3) Replace the current content of "IsInside()" with
>>>    a delegation like
>>>
>>>      {
>>>      this->ValueAt( point, value, depth, name );
>>>      return (value != 0);
>>>      }
>>>
>>>
>>> For a long term solution we probably need to
>>> add a explicit class:
>>>
>>>        ImageMaskSpatialObject
>>>
>>>
>>> with an IsInside() methods as the one you just
>>> implemented.
>>>
>>>
>>>
>>> Please let us know if you find any other problems,
>>>
>>>
>>>    Thanks
>>>
>>>
>>>      Luis
>>>
>>>
>>> -------------------
>>> Vincent Chu wrote:
>>>
>>>> Hi Luis,
>>>>
>>>> Thanks for the reply.  I tried SetImage() to an image whose pixel 
>>>> type is
>>>> unsigned char, and each pixel has value either 0 or 255.  However,
>>>> isInside(PointType x) seems to return true regardless of whether x is a
>>>> point where the pixel value is 0 or 255.  This is what I have in code:
>>>>
>>>> /////////////////////////////////////////////////////////////////////
>>>>
>>>> typedef itk::Point<double,3> Point;
>>>>  Point insidePoint;
>>>>  insidePoint[0]=182;
>>>>  insidePoint[1]=256;
>>>>  insidePoint[2]=15;
>>>>  if( imageSO->IsInside(insidePoint) )
>>>>       std::cout << insidePoint << " is inside the image." <<
>>>> std::endl;
>>>>  double returnedValue;
>>>>  imageSO->ValueAt(insidePoint,returnedValue);
>>>>  std::cout << "ValueAt(" << insidePoint << ") = " << returnedValue <<
>>>> std::endl;
>>>>  insidePoint.Fill(1);
>>>>  if( imageSO->IsInside(insidePoint) )
>>>>       std::cout << insidePoint << " is inside the image." <<
>>>> std::endl;
>>>>  imageSO->ValueAt(insidePoint,returnedValue);
>>>>  std::cout << "ValueAt(" << insidePoint << ") = " << returnedValue <<
>>>> std::endl;imageSO->ValueAt(insidePoint,returnedValue);
>>>>
>>>> ////////////////////////////////////////////////////////////////////////// 
>>>>
>>>>
>>>> And I get the following output:
>>>>
>>>> 182  256  15 is inside the image.
>>>> ValueAt(182  256  15) = 255
>>>> 1  1  1 is inside the image.
>>>> ValueAt(1  1  1) = 0
>>>>
>>>> Did I setup something wrong?
>>>>
>>>> Thanks,
>>>>
>>>> Vincent
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, 3 Jun 2004, Luis Ibanez wrote:
>>>>
>>>>
>>>>
>>>>
>>>>> Hi Vincent,
>>>>>
>>>>> You are in the right track,
>>>>> the class to use is the:
>>>>> ImageSpatialObject.
>>>>> http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageSpatialObject.html 
>>>>>
>>>>>
>>>>>
>>>>> Just connect your image mask to the ImageSpatialObject
>>>>> using its "SetImage()" method.
>>>>>
>>>>> There is no overload for doing this. At the end,
>>>>> the spatial object just need to answers the queries
>>>>> for whether a pixel is "inside" of the object (your
>>>>> image mask in this case) or not. What the Spatial
>>>>> object is doing is simply delegating the quiery to
>>>>> the underlying image mask that you provided.
>>>>>
>>>>>
>>>>> Please let us know if you have further questions,
>>>>>
>>>>>
>>>>>   Thanks
>>>>>
>>>>>
>>>>>     Luis
>>>>>
>>>>>
>>>>> ----------------
>>>>> Vincent Chu wrote:
>>>>>
>>>>>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am new to ITK and would like to perform registration between two 
>>>>>> images.
>>>>>> The region of interest has arbitrary shapes, and I previously read 
>>>>>> from
>>>>>> the list that we can use SetMovingImageMak() and 
>>>>>> SetFixedImageMask() in
>>>>>> ImageToImageMetrics to set the region in which the metrics will be
>>>>>> computed.  However, those two methods expect spatial objects as 
>>>>>> parameter,
>>>>>> and I have trouble converting a binary image into a spatial 
>>>>>> object.  I
>>>>>> have tried ImageSpatialObject, but the entire binary image would be
>>>>>> created as one big spatial object.  Which class should I use instead?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Vincent
>>>>>> _______________________________________________
>>>>>> Insight-users mailing list
>>>>>> Insight-users at itk.org
>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>>
> 
> 
> 
> _______________________________________________
> 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