8000 Behavior of EC2d close to the edges · Issue #433 · nipy/nipy · GitHub
[go: up one dir, main page]

Skip to content

Behavior of EC2d close to the edges #433

Open

Description

@mchouza

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.

Activity

  1. matthew-brett commented on Dec 5, 2017

    @matthew-brett
    Member

    @jonathan-taylor - any thoughts on this one?

  2. jonathan-taylor commented on Jan 26, 2018

    @jonathan-taylor
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0