# \[itk-python\] BlockMatchingImageFilter usage problem

**URL:** https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122
**Category:** Engineering
**Tags:** python
**Created:** [May 26, 2020, 6:36pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122 "2020-05-26T18:36:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![totoro3y](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@totoro3y](https://discourse.itk.org/u/totoro3y)
#### Post date: [May 26, 2020, 6:36pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/1 "2020-05-26T18:36:03Z")

</div>

Hello everyone, I am trying to use BlockMatchingImageFilter to do block matching.  
I refered to the c++ example match feature points ([https://itk.org/Doxygen/html/SphinxExamples\_2src\_2Registration\_2Common\_2MatchFeaturePoints\_2Code\_8cxx-example.html#\_a1](https://itk.org/Doxygen/html/SphinxExamples_2src_2Registration_2Common_2MatchFeaturePoints_2Code_8cxx-example.html#_a1)) and wrote the following codes,

```python
Dimension = 2
CoordType = itk.F
PointSetType = itk.PointSet[CoordType, Dimension]

pointSet = PointSetType.New()
points = pointSet.GetPoints()

# Create points
point = itk.Point[CoordType,Dimension]()
point[0] = 40
point[1] = 65
points.InsertElement(0, point)

# read images 
PixelType = itk.F
n = 200
path_tr = '../training'
name = '_2CH_ES'
sample = 'patient'+str(n).zfill(4)+'/patient'+str(n).zfill(4)+name+'.mhd'
img_es = itk.imread(os.path.join(path_tr,sample),PixelType)

name = '_2CH_ED'
sample = 'patient'+str(n).zfill(4)+'/patient'+str(n).zfill(4)+name+'.mhd'
img_ed = itk.imread(os.path.join(path_tr,sample),PixelType)

ImageType = itk.Image[PixelType,3]

# block matching 
block_filter = itk.BlockMatchingImageFilter[ImageType].New()
block_filter.SetFixedImage(img_ed)
block_filter.SetMovingImage(img_es)
block_filter.SetFeaturePoints(points)
block_filter.UpdateLargestPossibleRegion()

```

# Error

I got an error : in method ‘itkBlockMatchingImageFilterIF3\_SetFeaturePoints’, argument 2 of type ‘itkPointSetMD33STMD3333FFMD33 const \*’. Does anyone know how to make the pointset type to be MD33STMD3333FFMD33??

Thank you for your help!!!

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 26, 2020, 6:44pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/2 "2020-05-26T18:44:17Z")

</div>

> [@totoro3y](#):
>
> CoordType = itk.F

Did you try `itk.D`? `double`s are more commonly used for everything else except pixel type.

---

<div class="post-metadata">

### Author: ![totoro3y](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@totoro3y](https://discourse.itk.org/u/totoro3y)
#### Post date: [May 26, 2020, 7:38pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/3 "2020-05-26T19:38:03Z")

</div>

Hello! Thank you for your reply!  
Yes, I have tried the itk.D and i still got the same error.  
I used help() function to check the type of arguments in Blockmatchingfilter and i got:

> Help on itkBlockMatchingImageFilterIF3 in module itkBlockMatchingImageFilterPython object:  
> class itkBlockMatchingImageFilterIF3(itkBlockMatchingImageFilterIF3\_Superclass)  
> | Computes displacements of given points from a fixed image in a  
> | floating image.  
> | …  
> | …  
> | …  
> | SetFeaturePoints = itkBlockMatchingImageFilterIF3\_SetFeaturePoints(…)  
> | itkBlockMatchingImageFilterIF3\_SetFeaturePoints( **itkBlockMatchingImageFilterIF3** self, **itkPointSetMD33STMD3333FFMD33** \_arg)  
> |  
> | SetFixedImage = itkBlockMatchingImageFilterIF3\_SetFixedImage(…)  
> | itkBlockMatchingImageFilterIF3\_SetFixedImage(itkBlockMatchingImageFilterIF3 self, itkImageF3 \_arg)  
> |  
> | SetMovingImage = itkBlockMatchingImageFilterIF3\_SetMovingImage(…)  
> | itkBlockMatchingImageFilterIF3\_SetMovingImage(itkBlockMatchingImageFilterIF3 self, itkImageF3 \_arg)  
> | …

I know that **itkBlockMatchingImageFilterIF3** should be an image object of float type and with dimension 3, but i am totally lost by the definition of **itkPointSetMD33STMD3333FFMD33**.  
Do you have any idea what does it mean? How could i define the pointset object?  
( In the c++ example, the pointset object was defined as following

> using PointSetType = BlockMatchingImageFilterType::FeaturePointsType;  
> using PointType = PointSetType::PointType;  
> using PointsContainerPointer = PointSetType::PointsContainerPointer;  
> PointSetType::Pointer pointSet = PointSetType::New();  
> PointsContainerPointer points = pointSet-\>GetPoints();

Thank you very much!

---

<div class="post-metadata">

### Author: ![totoro3y](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@totoro3y](https://discourse.itk.org/u/totoro3y)
#### Post date: [May 26, 2020, 7:47pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/4 "2020-05-26T19:47:46Z")

</div>

I got the type of pointset needed in this filter

> itk::PointSet\<itk::Matrix\<double, 3u, 3u\>, 3u, itk::DefaultStaticMeshTraits\<itk::Matrix\<double, 3u, 3u\>3u, 3u, float, float, itk::Matrix\<double, 3u, 3u\> \> \>

This is quite complicated…

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 26, 2020, 7:50pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/5 "2020-05-26T19:50:01Z")

</div>

I remember there was a [problem with wrapping mesh traits](https://github.com/InsightSoftwareConsortium/ITKExamples/pull/66/commits/71a37b790cf0832c2b9ce7f229e5ea016e866ab0#diff-a6d670e5b306f15e0176a9b64c158cf2R29), but I don’t know whether that has been fixed meanwhile. @matt.mccormick is `BlockMatchingImageFilter`'s wrapping supposed to work?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [June 8, 2020, 10:59pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/6 "2020-06-08T22:59:09Z")

</div>

> [@totoro3y](#):
>
> I got the type of pointset needed in this filter
> 
> > itk::PointSet\<itk::Matrix\<double, 3u, 3u\>, 3u, itk::DefaultStaticMeshTraits\<itk::Matrix\<double, 3u, 3u\>3u, 3u, float, float, itk::Matrix\<double, 3u, 3u\> \> \>
> 
> This is quite complicated…

These classes squeaked past the mesh simplification of ITK 5.0 – I’ll see if we can improve on that.

> [@totoro3y](#):
>
> How could i define the pointset object?

These feature points are meant to be generated by the `itk.MaskFeaturePointSelectionFilter` as described in the [corresponding article](https://www.frontiersin.org/articles/10.3389/fninf.2014.00033/full).

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [June 10, 2020, 2:32pm UTC](https://discourse.itk.org/t/itk-python-blockmatchingimagefilter-usage-problem/3122/7 "2020-06-10T14:32:23Z")

</div>

> [@matt.mccormick](#):
>
> These classes squeaked past the mesh simplification of ITK 5.0 – I’ll see if we can improve on that.

This was addressed here:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/1856>
>
> …ngling
> 
> Simplify the Python wrapping name mangling to remove the
> DefaultStat…icMeshTraits, standard with itk 5 mesh wrapping.
