Skip to content

Behavior of EC2d close to the edges #433

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

Open
mchouza opened this issue Dec 3, 2017 · 2 comments
Open

Behavior of EC2d close to the edges #433

mchouza opened this issue Dec 3, 2017 · 2 comments

Comments

@mchouza
Copy link

mchouza commented Dec 3, 2017

While testing the Euler characteristic computation function, nipy.algorithms.statistics.intvol.EC2d, I found some unexpected behavior that could be reduced to the following :

In [2]: import numpy as np

In [3]: from nipy.algorithms.statistics.intvol import EC2d

In [4]: a = np.ones(shape=(3, 3), dtype='int'); print a, EC2d(a)
[[1 1 1]
 [1 1 1]
 [1 1 1]] -1

In [5]: a[0, 0] = 0; print a, EC2d(a)
[[0 1 1]
 [1 1 1]
 [1 1 1]] 1

In [6]: a[0, 0] = 1; a[-1, 0] = 0; print a, EC2d(a)
[[1 1 1]
 [1 1 1]
 [0 1 1]] -1

Is that a expected consequence of those functions being approximate? Thanks for your help and sorry if I am misunderstanding the intended purpose of the functions.

@matthew-brett
Copy link
Member

@jonathan-taylor - any thoughts on this one?

@jonathan-taylor
Copy link
Contributor

I think this has to do with how a binary "image" is triangulated. It has been some time since I've looked at the code. If a is padded with 0s this problem is not there.

In [22]: a = np.ones(shape=(3, 3), dtype='int'); print a, EC2d(a)
[[1 1 1]
[1 1 1]
[1 1 1]] -1

In [23]: a1 = a.copy()

In [24]: a2 = a.copy()

In [25]: a1[0, 0] = 0

In [26]: a2[-1, 0] = 0

In [30]: b = np.zeros((5, 5), np.int)

In [31]: b[1:-1][:,1:-1] = a

In [32]: EC2d(b)
Out[32]: 1

In [33]: b1 = np.zeros_like(b)

In [34]: b1[1:-1][:,1:-1] = a1

In [35]: EC2d(b1)
Out[35]: 1

In [36]: b2 = np.zeros_like(b)

In [37]: b2[1:-1][:,1:-1] = a2

In [38]: EC2d(b2)
Out[38]: 1

In [39]:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants