[Insight-developers] Re: [Insight-users] Histogram from red component of RGB image

Karthik Krishnan Karthik.Krishnan at kitware.com
Tue Sep 27 18:08:44 EDT 2005


Interesting...

// snippet....
inline const TMeasurementVector &
::GetMeasurementVector(const InstanceIdentifier &id) const
{
    return *(reinterpret_cast< const MeasurementVectorType* >
             ( &(m_Image->GetPixel( m_Image->ComputeIndex( id ) ) ) ) ) ;
}
// end snippet

Adaptors do not return values by reference, but return them by value. 
This is by design.
The class itkImageToListAdaptor expects the input pixels the image to be 
a reference. This should never be done unless the class is using the 
input image's pixel container directly.

This implies that the class can *never* be used when the input image is 
an adaptor,

Yet I am puzzled that the CVS logs for this class say: 

----------------------------
revision 1.14
date: 2003-07-03 22:24:18 +0000;  author: jisung;  state: Exp;  lines: 
+27 -33
ENH: GetMeasurementVector method now returns a measurement vector by 
value instead of by reference.
----------------------------
revision 1.13
date: 2003-06-23 19:39:55 +0000;  author: jisung;  state: Exp;  lines: 
+18 -3

BUG: Previously, the adaptor class access pixels directly from the
image's pixel container which is wrong if the image type is
ImageAdaptor. In the case of ImageAdaptor, the adaptor class should use
GetPixel method.
----------------------------

The first log should read the other way around GetMeasurementVector 
method is returning by reference instead of value.
And the second log is not true.

This is definitely a bug. Please log this in the bug tracker.

http://www.itk.org/Bug/

For now, your best bet is to add an additional filter in between the 
RedAdaptorType and the ImageToListAdaptor. This will just be a dummy 
filter, You could use a CastImageFilter (which probably wouldn't hurt 
too much hoping that the static_casts get optimized away by the 
compiler.. ).

I wonder if anybody has run into this problem before.

Thanks
Regards
Karthik

Pablo Arias wrote:

>Hi,
>   I am just starting with ITK, and I want to compute the histogram
>of the red component of an RGB image. At this time I am doing this by
>using the ImageToHistogramGenerator and setting the number of bins in
>[255,0,0]. This way my software is too slow, and I thought that
>perhaps using the ScalarImageToHistogramGenerator with an appropiate
>image adaptor would be faster.
>
>  I found an old message in this mailing list where it said that this
>could be done by treating the image adaptor as if it was an actual
>image.
>
>  I've done so, but I had some compiling errors when I tried to pass
>the adaptor type to the ScalarImageToHistogramGenerator as a template
>parameter. The first error is like this:
>
>c:\vap\insighttoolkit-2.0.1-source\code\numerics\statistics\itkimagetolistadaptor.txx(116)
>: error C2102: '&' requires l-value
>
>  
>
>  And my code looks like this:
>
>typedef typename ImageType::PixelType PixelType;
>typedef typename PixelType::ValueType ValueType;
>
>typedef itk::ImageAdaptor<ImageType,
>RedChannelPixelAccessor<ValueType> >   RedAdaptorType;
>
>typedef itk::Statistics::ScalarImageToHistogramGenerator<RedAdaptorType>
>ScalarHistogramGeneratorType;  // this is the line that causes the
>error
>
>Thanks
>
>Pablo
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>
>  
>


More information about the Insight-developers mailing list