Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with the python wrapping of ShapePriorMAPCostFunction #871

Open
bpaniagua opened this issue May 15, 2019 · 0 comments

Comments

Projects
None yet
3 participants
@bpaniagua
Copy link
Contributor

commented May 15, 2019

Description

There seems to be a problem using the ShapePriorMAPCostFunction class in python.

When assigning the mean and stddev vectors and then printing the cost function object, those arrays seem to be empty. This assignment does not create a problem in C++. The test here uses the ShapePriorMAPCostFunction and it works perfectly.

Steps to Reproduce

In python, I create a ShapePriorMAPCostFunction in the following way:

costfunction=itk.ShapePriorMAPCostFunction[ImageType, InputPixelType].New()
weights=itk.FixedArray[itk.D,4]()
weights[0] =  1.0  # weight for contour fit term
weights[1] =  20.0 # weight for image fit term
weights[2] =  1.0  # weight for shape prior term
weights[3] =  1.0  # weight for pose prior term
costfunction.SetWeights(weights)
mean=itk.Array[itk.D](pca.GetNumberOfShapeParameters())
mean.Fill(0.0)
stddev=itk.Array[itk.D](pca.GetNumberOfShapeParameters())
stddev.Fill(1.0)
costfunction.SetShapeParameterMeans(mean)
costfunction.SetShapeParameterStandardDeviations(stddev)

I try to use this costfunction object in a GeodesicActiveContourShapePriorLevelSetImage filter, and when I update the filter I get the following error:

RuntimeError: /work/standalone-x64-build/ITKs/Modules/Segmentation/LevelSets/include/itkShapePriorMAPCostFunction.hxx:187:
itk::ERROR: ShapePriorMAPCostFunction(0x9675fa0): ShapeParameterMeans does not have at least 3 number of elements.

When I print the costfunction object I created in the way I described I see this information:

ShapePriorMAPCostFunction (0x9675fa0)
RTTI typeinfo: itk::ShapePriorMAPCostFunction<itk::Image<float, 2u>, float>
Reference Count: 3
Modified Time: 8414
Debug: Off
Object Name:
Observers:
none
ShapeFunction: 0x982d9f0
ActiveRegion: 0x982d9a0
FeatureImage: 0x91f1f80
ShapeParameterMeans: []
ShapeParameterStandardDeviations: []
Weights: [1, 20, 1, 1]

Note that despite having assigned the mean and stddev vectors, they seem to be empty in the costfunction object.

If I try to access the costfunction variable by print costfunction.GetShapeParameterMeans() I get the following information:

swig_name ([])

Expected behavior

I expect my filter to have the same behavior than the C++ code. It doesnt.

Reproducibility

100%

Versions

I run my jupyter notebook with precompiled itk python packages from last week (05/10/2019)

Environment

I am running this in a python jupyter notebook.

Additional Information

N/A

@bpaniagua bpaniagua added the type:Bug label May 15, 2019

fbudin69500 pushed a commit to fbudin69500/ITK that referenced this issue May 16, 2019

Francois Budin
BUG: DECL_PYTHON_VARLEN_SEQ_TYPEMAP typenames only works with Python …
…sequence

Addresses issue InsightSoftwareConsortium#871.

`typemap(in)` for `DECL_PYTHON_VARLEN_SEQ_TYPEMAP` was incorrect:
* It was only accepting Python sequences (list, tuple,...) but was not
working properly when trying to pass the original ITK type.
* It an incorrect type was passed, it was crashing instead of returning
an error message.

fbudin69500 pushed a commit to fbudin69500/ITK that referenced this issue May 16, 2019

Francois Budin
BUG: DECL_PYTHON_VARLEN_SEQ_TYPEMAP typenames only works with Python …
…sequence

Addresses issue InsightSoftwareConsortium#871.

`typemap(in)` for `DECL_PYTHON_VARLEN_SEQ_TYPEMAP` was incorrect:
* It was only accepting Python sequences (list, tuple,...) but was not
working properly when trying to pass the original ITK type.
* It an incorrect type was passed, it was crashing instead of returning
an error message.

fbudin69500 pushed a commit to fbudin69500/ITK that referenced this issue May 16, 2019

Francois Budin
BUG: DECL_PYTHON_VARLEN_SEQ_TYPEMAP typenames only works with Python …
…sequence

Addresses issue InsightSoftwareConsortium#871.

`typemap(in)` for `DECL_PYTHON_VARLEN_SEQ_TYPEMAP` was incorrect:
* It was only accepting Python sequences (list, tuple,...) but was not
working properly when trying to pass the original ITK type.
* It an incorrect type was passed, it was crashing instead of returning
an error message.

@thewtex thewtex modified the milestones: ITK v5.0.0, ITK v5.0.1 May 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.