Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Modules/Core/Common/wrapping/itkImageToImageFilterA.wrap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ itk_wrap_class("itk::ImageToImageFilter" POINTER)
# Vector types
itk_wrap_image_filter_combinations("${WRAP_ITK_VECTOR}" "${WRAP_ITK_VECTOR}")

# VectorImage <-> vector
foreach(d ${ITK_WRAP_IMAGE_DIMS})
if(ITK_WRAP_vector_float)
itk_wrap_template("${ITKM_IVF${d}${d}}${ITKM_VIF${d}}" "${ITKT_IVF${d}${d}},${ITKT_VIF${d}}")
endif()
if(ITK_WRAP_vector_double)
itk_wrap_template("${ITKM_IVD${d}${d}}${ITKM_VID${d}}" "${ITKT_IVD${d}${d}},${ITKT_VID${d}}")
endif()
endforeach()

# For GradientRecursiveGaussianImageFilter we need some specific combinations
foreach(image_dim ${ITK_WRAP_IMAGE_DIMS})
foreach(input_vector_dim ${ITK_WRAP_VECTOR_COMPONENTS})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ CastImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateDataDispatche
// Implementation for non-implicit convertible pixels which are
// itk-array-like.

static_assert(OutputPixelType::Dimension == InputPixelType::Dimension, "Vector dimensions are required to match!");
static_assert(std::is_convertible<typename InputPixelType::ValueType, typename OutputPixelType::ValueType>::value,
"Component types are required to be convertible.");

Expand All @@ -140,6 +139,8 @@ CastImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateDataDispatche

this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);

const unsigned int componentsPerPixel = outputPtr->GetNumberOfComponentsPerPixel();

// Define the iterators
ImageScanlineConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread);
ImageScanlineIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
Expand All @@ -152,7 +153,7 @@ CastImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateDataDispatche
{
const InputPixelType & inputPixel = inputIt.Get();
OutputPixelType value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not get set to the correct length for vector pixels.

Copy link
Member

@blowekamp blowekamp Jan 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the loops add something like:

OutputPixelType value;
NumericTraits<OutputPixelType>::SetLength(value, componentsPerPixels)

I'm not sure if its a NumericTraits or some other pixel traits class that is needed to set the number components correctly for all types OK.

Pulling it outside the loop also removes per-pixel allocation which is a performance killer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blowekamp thanks for the note.

@Leengit it looks this addition was missed when with #2073 -- could you please add it in a follow-up patch?

for (unsigned int k = 0; k < OutputPixelType::Dimension; k++)
for (unsigned int k = 0; k < componentsPerPixel; k++)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
Expand Down
10 changes: 10 additions & 0 deletions Modules/Filtering/ImageFilterBase/wrapping/itkCastImageFilter.wrap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ itk_wrap_class("itk::CastImageFilter" POINTER_WITH_SUPERCLASS)
# vector <-> vector
itk_wrap_image_filter_combinations("${WRAP_ITK_VECTOR}" "${WRAP_ITK_VECTOR}")

# VectorImage <-> vector
foreach(d ${ITK_WRAP_IMAGE_DIMS})
if(ITK_WRAP_vector_float)
itk_wrap_template("${ITKM_IVF${d}${d}}${ITKM_VIF${d}}" "${ITKT_IVF${d}${d}},${ITKT_VIF${d}}")
endif()
if(ITK_WRAP_vector_double)
itk_wrap_template("${ITKM_IVD${d}${d}}${ITKM_VID${d}}" "${ITKT_IVD${d}${d}},${ITKT_VID${d}}")
endif()
endforeach()

# RGB <-> RGB
UNIQUE(rgb "RGBUC;${WRAP_ITK_RGB}")
itk_wrap_image_filter_combinations("${rgb}" "${rgb}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
itk.auto_progress(2)

dim = 2
IType = itk.Image[itk.F, dim]
OIType = itk.Image[itk.UC, dim]
InputImageType = itk.Image[itk.F, dim]
OutputImageType = itk.Image[itk.UC, dim]

reader = itk.ImageFileReader[IType].New(FileName=argv[1])
filter = itk.CastImageFilter[IType, OIType].New(reader)
writer = itk.ImageFileWriter[OIType].New(filter, FileName=argv[2])
reader = itk.ImageFileReader[InputImageType].New(FileName=argv[1])
filt = itk.CastImageFilter[InputImageType, OutputImageType].New(reader)
writer = itk.ImageFileWriter[OutputImageType].New(filt, FileName=argv[2])

writer.Update()