[ITK] Python wrapper for first order ITKTextureFeatures

yannick.suter at istb.unibe.ch yannick.suter at istb.unibe.ch
Mon Sep 18 10:09:00 EDT 2017


Dear Matt,

Thank you for helping!
The link to the structuring element example was very useful.

I ran into a new issue where I would appreciate some help:
The FirstOrderTextureFeaturesImageFilter uses the "MovingHistogramImageFilter", and I have some issues wrapping it correctly. I get the  following error for each type I want to wrap:

 Warning 401: Nothing known about base class 'itk::MovingHistogramImageFilter< itk::Image< short,2 >,itk::VectorImage< float,2 >,itk::FlatStructuringElement< 2 >,itk::Function::FirstOrderTextureHistogram< short,itk::VariableLengthVector< float > > >'. Ignored.
/home/yannick/Projects/PhD/ITK/ITK/bin/Wrapping/Typedefs/itkFirstOrderTextureFeaturesImageFilter.i:99: Warning 401: Maybe you forgot to instantiate 'itk::MovingHistogramImageFilter< itk::Image< short,2 >,itk::VectorImage< float,2 >,itk::FlatStructuringElement< 2 >,itk::Function::FirstOrderTextureHistogram< short,itk::VariableLengthVector< float > > >' using %template.

Even though I put the MovingHistogramImageFilter in the .wrap file and tried including the base class itkMovingHistogramImageFilterBase as well. 

Could you take a look?
Here's my itkFirstOrderTextureFeaturesImageFilter.wrap file:
----------------------------------------------------
set(OutputVectorDim 8)
itk_wrap_class("itk::FixedArray")
  itk_wrap_template("${ITKM_F}${OutputVectorDim}" "${ITKT_F},${OutputVectorDim}")
itk_end_wrap_class()

itk_wrap_class("itk::Vector")
  itk_wrap_template("${ITKM_F}${OutputVectorDim}" "${ITKT_F},${OutputVectorDim}")
itk_end_wrap_class()

WRAP_TYPE("itk::Image" "I" "itkImage.h")
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    ADD_TEMPLATE("V${ITKM_F}${OutputVectorDim}${d}" "itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}")
  endforeach()
END_WRAP_TYPE()

itk_wrap_class("itk::Image" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    itk_wrap_template("V${ITKM_F}${OutputVectorDim}${d}" "itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}")
  endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::ImageSource" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}" "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
  endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::ImageToImageFilter" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    foreach(t ${WRAP_ITK_INT})
      itk_wrap_template("${ITKM_I${t}${d}}IV${ITKM_F}${OutputVectorDim}${d}"
                        "${ITKT_I${t}${d}}, itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
    endforeach()
  endforeach()
itk_end_wrap_class()

itk_wrap_include("itkFlatStructuringElement.h")

WRAP_TYPE("itk::FlatStructuringElement" "SE")
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    ADD_TEMPLATE("${d}"  "${d}")
  endforeach()
END_WRAP_TYPE()
set(itk_Wrap_StructuringElement ${WRAPPER_TEMPLATES})

itk_wrap_simple_class("itk::ImageIOBase" )

itk_wrap_class("itk::KernelImageFilter" POINTER)
  foreach(t ${WRAP_ITK_INT})
    foreach(d ${ITK_WRAP_IMAGE_DIMS})
      itk_wrap_template("${ITKM_I${t}${d}}${ITKM_I${t}${d}}${ITKM_SE${d}}" "${ITKT_I${t}${d}}, ${ITKT_I${t}${d}}, ${ITKT_SE${d}}")
    endforeach()
  endforeach()
itk_end_wrap_class()

itk_wrap_include("itkMovingHistogramImageFilterBase.h")
itk_wrap_class("itk::MovingHistogramImageFilterBase" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    foreach(t ${WRAP_ITK_INT})
      itk_wrap_template("${ITKM_I${t}${d}}${ITKM_I${t}${d}}${ITKM_SE${d}}"
        "${ITKT_I${t}${d}},${ITKT_I${t}${d}},${ITKT_SE${d}}")
    endforeach()
  endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::ImageFileReader" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}"
                      "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
  endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::ImageFileWriter" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}"
                      "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
  endforeach()
itk_end_wrap_class()

itk_wrap_include("itkFirstOrderTextureHistogram.h")
itk_wrap_class("itk::Function::FirstOrderTextureHistogram")
  foreach(t ${WRAP_ITK_INT})
    itk_wrap_template("${ITKM_${t}}${ITKM_${t}}" "${ITKT_${t}}, ${ITKT_${t}}")
  endforeach()
itk_end_wrap_class()

itk_wrap_include("itkMovingHistogramImageFilter.h")
itk_wrap_class("itk::MovingHistogramImageFilter" POINTER)
  foreach(t ${WRAP_ITK_INT})
    foreach(d ${ITK_WRAP_IMAGE_DIMS})
      itk_wrap_template("${ITKM_I${t}${d}}${ITKM_I${t}${d}}${ITKM_SE${d}}" 
                        "${ITKT_I${t}${d}}, ${ITKT_I${t}${d}}, ${ITKT_SE${d}}, itk::Function::FirstOrderTextureHistogram< ${ITKT_${t}}, ${ITKT_${t}} >")
    endforeach()
  endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::FirstOrderTextureFeaturesImageFilter" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    foreach(t ${WRAP_ITK_INT})
      itk_wrap_template("${ITKM_I${t}${d}}${ITKM_VI${ITKM_F}${d}}${ITKM_SE${d}}"
                      "${ITKT_I${t}${d}}, ${ITKT_VI${ITKM_F}${d}}, ${ITKT_SE${d}}")
  endforeach()
endforeach()
itk_end_wrap_class()
----------------------------------------------------

Best and thank you,

Best,

Yannick

________________________________________
Von: Matt McCormick [matt.mccormick at kitware.com]
Gesendet: Sonntag, 17. September 2017 20:48
An: Suter, Yannick Raphael (ISTB)
Cc: community at itk.org; Jean-Baptiste Vimort
Betreff: Re: [ITK] Python wrapper for first order ITKTextureFeatures

Dear Yannick,

It looks like you are close.

To find out what template parameters to pass, the class declaration
has this information:

  https://github.com/InsightSoftwareConsortium/ITKTextureFeatures/blob/master/include/itkFirstOrderTextureFeaturesImageFilter.h#L51

template< class TInputImage, class TOutputImage, class TKernel >

There are three template parameters, the input image, the output
image, and the kernel. To see what kind of types are used for these
parameters, the test gives a hint:

https://github.com/InsightSoftwareConsortium/ITKTextureFeatures/blob/master/test/itkFirstOrderTextureFeaturesImageFilterTest.cxx#L28-L30

The KernelType is usually itk::FlatStructuringElement< ImageDimension
>. A grep through ITK's sources finds an example of how this is used
as a template parameter when wrapping:

  https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/BinaryMathematicalMorphology/wrapping/itkBinaryDilateImageFilter.wrap


There is also a good wrapping reference in the ITK Software Guide to reach for:

  https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch9.html#x48-1540009.5


Please let use know if more help is needed. Contribution pull requests
are welcome and appreciated :-)


Thanks,
Matt

On Sat, Sep 16, 2017 at 12:45 PM,  <yannick.suter at istb.unibe.ch> wrote:
> Dear all,
>
> I would like to use the the first order texture features of
> ITKTextureFeatures
> (https://github.com/InsightSoftwareConsortium/ITKTextureFeatures) in Python.
> Thanks to J.Vimort et al. for the great work!
> Since the coocurrence and run length features are already wrapped, I tried
> to take these as an example and wrap it myself (I'm very new to this).
>
> I would appreciate any help to point me into the right direction.
>
> That's what I've tried:
> - Created a .wrap file "itkFirstOrderTextureFeaturesImageFilter.wrap" and
> put it in the "/Modules/External/ITKTextureFeatures/wrapping" directory (see
> below)
> - Added "itkFirstOrderTextureFeaturesImageFilter" to the CMakeLists.txt in
> the "/Modules/External/ITKTextureFeatures/wrapping" directory, now looking
> like this:
>
> itk_wrap_module(TextureFeatures)
>
> set(WRAPPER_SUBMODULE_ORDER
>    itkCoocurrenceTextureFeaturesImageFilter
>    itkRunLengthTextureFeaturesImageFilter
>    itkFirstOrderTextureFeaturesImageFilter)
>
> itk_auto_load_submodules()
> itk_end_wrap_module()
>
> This gives me the folowwing error for every datatype I set to wrap:
>>>
>>> /home/yannick/Projects/PhD/ITK/ITK/bin/Wrapping/itkFirstOrderTextureFeaturesImageFilter.cxx:79:18:
>>> error: too few template arguments for class template
>>> 'FirstOrderTextureFeaturesImageFilter'
>>>    typedef itk::FirstOrderTextureFeaturesImageFilter< itk::Image< signed
>>> short,2 >, itk::Image<itk::Vector<float,8>,2> >
>>> itkFirstOrderTextureFeaturesImageFilterISS2IVF82;
>                  ^
>>>/home/yannick/Projects/PhD/ITK/ITK/Modules/External/ITKTextureFeatures/include/itkFirstOrderTextureFeaturesImageFilter.h:52:27:
>>> note: template is declared here
>>>class ITK_TEMPLATE_EXPORT FirstOrderTextureFeaturesImageFilter:
>
> Since the it's working if I use it in C++, I don't see where template
> arguments are missing.
>
> Best and thank you,
>
> Yannick
>
> That's my .wrap-file:
> ------------
> set(OutputVectorDim 8)
> itk_wrap_class("itk::FixedArray")
>   itk_wrap_template("${ITKM_F}${OutputVectorDim}"
> "${ITKT_F},${OutputVectorDim}")
> itk_end_wrap_class()
>
> itk_wrap_class("itk::Vector")
>   itk_wrap_template("${ITKM_F}${OutputVectorDim}"
> "${ITKT_F},${OutputVectorDim}")
> itk_end_wrap_class()
>
> WRAP_TYPE("itk::Image" "I" "itkImage.h")
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     ADD_TEMPLATE("V${ITKM_F}${OutputVectorDim}${d}"
> "itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}")
>   endforeach()
> END_WRAP_TYPE()
>
> itk_wrap_class("itk::Image" POINTER)
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     itk_wrap_template("V${ITKM_F}${OutputVectorDim}${d}"
> "itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}")
>   endforeach()
> itk_end_wrap_class()
>
> itk_wrap_class("itk::ImageSource" POINTER)
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}"
> "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
>   endforeach()
> itk_end_wrap_class()
>
> itk_wrap_class("itk::ImageToImageFilter" POINTER)
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     foreach(t ${WRAP_ITK_INT})
>       itk_wrap_template("${ITKM_I${t}${d}}IV${ITKM_F}${OutputVectorDim}${d}"
>                         "${ITKT_I${t}${d}},
> itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
>     endforeach()
>   endforeach()
> itk_end_wrap_class()
>
> itk_wrap_simple_class("itk::ImageIOBase" )
>
> itk_wrap_class("itk::ImageFileReader" POINTER)
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}"
>
> "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
>   endforeach()
> itk_end_wrap_class()
>
> itk_wrap_class("itk::ImageFileWriter" POINTER)
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}"
>
> "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
>   endforeach()
> itk_end_wrap_class()
>
> itk_wrap_class("itk::ImageFileWriter" POINTER)
>   foreach(d ${ITK_WRAP_IMAGE_DIMS})
>     itk_wrap_template("IV${ITKM_F}${OutputVectorDim}${d}"
>
> "itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
>   endforeach()
> itk_end_wrap_class()
>
> itk_wrap_class("itk::FirstOrderTextureFeaturesImageFilter" POINTER)
> foreach(d ${ITK_WRAP_IMAGE_DIMS})
>   foreach(t ${WRAP_ITK_INT})
>     itk_wrap_template("${ITKM_I${t}${d}}IV${ITKM_F}${OutputVectorDim}${d}"
>                       "${ITKT_I${t}${d}},
> itk::Image<itk::Vector<${ITKT_F},${OutputVectorDim}>,${d}>")
>     itk_wrap_template("${ITKM_I${t}${d}}${ITKM_VI${ITKM_F}${d}}"
>                       "${ITKT_I${t}${d}}, ${ITKT_VI${ITKM_F}${d}}")
>   endforeach()
> endforeach()
> itk_end_wrap_class()
>
>
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>


More information about the Community mailing list