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

ENH: Threshold mask in images_to_matrix #646

Merged
merged 1 commit into from
May 20, 2024
Merged

Conversation

cookpa
Copy link
Member

@cookpa cookpa commented May 20, 2024

Prevents cryptic error if the mask is not binarized, because the threshold was being applied to the numpy matrix but not the mask itself.

Also add some more tests

@cookpa
Copy link
Member Author

cookpa commented May 20, 2024

Related to #641

@ncullen93 the matrix here was all zero because it was sampling a corner of the image, by adding the spacing arg I make the downsampled mask cover all of the image domain

s = [65]*img.dimension
mask2 = ants.from_numpy(np.random.randn(*s), spacing=[4.0, 4.0])
mask2 = mask2 > mask2.mean()
imgmat = ants.images_to_matrix(imglist, mask=mask2)

Still not sure what the Windows seg faults were about, but will revisit if they happen again

@ncullen93
Copy link
Member

Great! My guess is the windows error was because there was a function within a function trying to access an image in the outer function environment.. perhaps something with the c++ references that is quit complicated. I removed that and it will hopefully be OK. Here is a simplified version:

def outer_fn(image, mask):
    def inner_fn(image):
        # mask not in "inner" environment but being accessed anyways
        return image + mask 
    return inner_fn(image)

@coveralls
Copy link

Coverage Status

coverage: 81.145% (+0.004%) from 81.141%
when pulling 0796515 on image_to_matrix_mask
into 7d876d8 on master.

@cookpa cookpa merged commit 91fcb8e into master May 20, 2024
2 checks passed
@cookpa cookpa deleted the image_to_matrix_mask branch May 20, 2024 16:43
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

Successfully merging this pull request may close these issues.

3 participants