[Insight-users] Bug in CastImageFIlter?
Matthias Schabel
mschabel at ucair.med.utah.edu
Thu Feb 8 16:35:20 EST 2007
Taking a quick look at the code, it appears that there is not a do-
nothing specialization for
CastImageFilter in the case that the input and output image types are
degenerate; this means
that a bunch of unnecessary work gets done if you call
CastImageFilter<short,short>, for
example. Why, you ask, would you do something like that? Consider a
generic class for
reading in DICOM data and, possibly converting it to another type via
casting:
template<std::size_t R,typename T = short>
class DicomData :
public itk::Image<T,R>
{
public:
DicomData(const std::vector<std::string>& filenames);
};
template<std::size_t R,typename T>
DicomData<R,T>::DicomData(const std::vector<std::string>& filenames)
{
// use ImageSeriesReader to read DICOM data
itk::Image<short,R>::Pointer input_image_ptr = reader->GetOutput();
typedef itk::CastImageFilter<itk::Image<short,R>,itk::Image<T,R> >
cast_image_filter_type;
typedef typename cast_image_filter_type::Pointer
cast_image_filter_pointer_type;
cast_image_filter_pointer_type caster = cast_image_filter_type::New();
caster->SetInput(input_image_ptr);
try
{
// if T == short, this should do nothing, but it doesn't (do nothing)
caster->Update();
}
catch (itk::ExceptionObject& e)
{
std::cerr << "exception in image series reader " << std::endl;
std::cerr << e << std::endl;
throw;
}
image_pointer_type::operator=(caster->GetOutput());
}
Really, all that is needed is a template specialization in
CastImageFilter like this:
template<class TImage>
class CastImageFilter<TImage,TImage>
{
// don't do anything, just return the input pointer...
}
Is there some reason why this isn't done? Maybe I'm missing some
subtlety that precludes this...
Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070208/de3430f4/attachment-0001.htm
More information about the Insight-users
mailing list