[Insight-users] ImageMaskSpatialObject with non unsigned char PixelType?

Geoff Topping g_topping at hotmail.com
Mon May 4 20:13:28 EDT 2009


Hi all,

I'm trying to make a version of ImageMaskSpatialObject that is parameterized in pixel type.  The current version is hard-coded to use unsigned char pixel type, which is an unnecessary limitation, in my opinion.

Because its pixel type is unsigned char, the current implementation makes some assumptions based on its pixel type that I'm not sure how to adapt to a more general case, and I'm hoping someone can clarify things.

First, to test whether a particular pixel is to be included in the masked region, the current code checks whether this pixel's value is 0:

const bool insideMask = (this->GetImage()->GetPixel(index) != NumericTraits::Zero)

Since the hard-coded PixelType is unsigned char, there is no possibility for negative pixel values, however I'm going to have signed and floating point pixel values, so this form of test is probably insufficient.  I'm wondering if there's any reason not to modify this to:

const bool insideMask = (this->GetImage()->GetPixel(index)> NumericTraits::Zero)


That is, change it so that the pixel value has to be greater than zero, and negative pixels are excluded from the mask.

A more complicated implementation might have configurable thresholds, but presumably a thresholding filter could be used to do this beforehand.

In most cases, I suspect postive values would be used to be included in the mask, and negative or zero elsewhere, but I might not be considering obvious use cases to still check for exactly NumericTraits::Zero.

...

Additionally, I'm confused about how GetAxisAlignedBoundingBoxRegion() works.  In particular:

PixelType outsideValue = NumericTraits< PixelType>::Zero;

This value is set, and then in the loops, there is a check:

if( fit.Get() != outsideValue )

where fit is an itk::ImageSliceConstIteratorWithIndex< ImageType>

This again appears to be scanning in from the edges of the image to determine where pixels that have value sufficient to be included in the mask start.  Would it be appropriate to change this to

PixelType inclusionThreshold = NumericTraits< PixelType>::Zero;

and


if( fit.Get()> inclusionThreshold )


for this section?

Thanks,
Geoff Topping


----------------------------------------
> From: g_topping at hotmail.com
> To: luke.bloy at gmail.com
> CC: insight-users at itk.org
> Subject: RE: [Insight-users] ImageMaskSpatialObject with non unsigned char PixelType?
> Date: Thu, 23 Apr 2009 18:04:12 -0400
>
>
> Hi Luke,
>
> I considered just casting to unsigned char, but the file format I'm reading in (Analyze75) has a calibration / scale parameter that seems to get lost when casting to a signed integer type. The absolute value of the scaled input image pixels is something like 0.001, so when cast to an integer type like signed int, or presumably unsigned char, I get all 0's. This seems likely to cause problems when trying to use the image as a mask. I realize this can probably be worked around as well, but having a float-compatible version of the ImageMaskSpatialObject class available by default would be much simpler and would avoid all these issues.
>
> If memory footprint becomes a problem, then it seems like that would be the time to worry about reducing it, not ahead of time by unnecessarily restricting the acceptable input to the class.
>
> Geoff
>
>> Hi Geoff,
>>
>> I thought the same thing, if you template ImageMaskSpatialObject over
>> the pixeltype and it would still work. However it is pretty simple to
>> use an itkCastImageFilter.h to cast your image to unsigned char and this
>> way has a smaller memory foot print.
>>
>> -Luke
>>
>> Geoff Topping wrote:
>>> Hi,
>>>
>>> I'd like to do some masking of image registration using ImageMaskSpatialObject, but when I try to pass a
>>>
>>> itk::Image
>>>
>>> to
>>>
>>> itk::ImageMaskSpatialObject::SetImage()
>>>
>>>
>>> I get compile errors along the lines of:
>>>
>>> error: no matching function for call to `itk::ImageMaskSpatialObject::SetImage(itk::Image*)'
>>> itkImageSpatialObject.txx:281: note: candidates are: void itk::ImageSpatialObject::SetImage(const itk::Image*) [with unsigned int TDimension = 3u, TPixelType = unsigned char]
>>>
>>>
>>> This is apparently because ImageMaskSpatialObject is defined as:
>>>
>>> class ImageMaskSpatialObject
>>> : public ImageSpatialObject< TDimension, unsigned char>
>>>
>>>
>>> So I'm wondering, is there a reason ImageMaskSpatialObject can only accept images with PixelType unsigned char? (Or should it be able to take images with PixelType float?)
>>>
>>> Shouldn't it be able to work with any PixelType for which NumericTraits::Zero is valid / defined?
>>>
>>> Can I just make my own version of ImageMaskSpatialObject that instantiates its ImageSpatialObject with float instead of unsigned char, or will this cause problems?
>>>
>>> Thanks,
>>> Geoff Topping
_________________________________________________________________
Create a cool, new character for your Windows Live™ Messenger. 
http://go.microsoft.com/?linkid=9656621


More information about the Insight-users mailing list