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

cwatershed fails on large 3D images (>2**31 voxels) #102

Closed
williamjshipman opened this issue Mar 16, 2019 · 6 comments
Closed

cwatershed fails on large 3D images (>2**31 voxels) #102

williamjshipman opened this issue Mar 16, 2019 · 6 comments

Comments

@williamjshipman
Copy link

I was attempting to process a 2304x2304x2475 voxel tomogram using cwatershed. I'd keep getting an array of zeros out. I eventually found that just processing 100 slices worked fine, so I kept increasing the number of slices until it failed. It seems like the issue is that as soon as the no. of voxels exceeds 2**31, cwatershed fails (either giving an array of zeros, or once even causing Python to segfault). Looking at _morph.cpp, I think the problem is that int is used for indices, e.g. line 599, instead of int64_t or uint64_t.

@luispedro
Copy link
Owner

Wow, I thought 2³¹ voxels should be enough for everybody, but I guess I was wrong (seriously, I never even thought this could be an issue).

Obviously, the fix is easy, so I will just do it.

@luispedro
Copy link
Owner

I just committed what I think is a fix. Do you have the ability to test the github version and tell me if it works?

@williamjshipman
Copy link
Author

williamjshipman commented Mar 18, 2019 via email

@williamjshipman
Copy link
Author

Bad news, didn't fix it. Going above 2**31 voxels now leads to a seg fault, no exception error message to give you unfortunately.

Here's my very simple test code, if it helps. Change the 512 slices to 511 slices and it seems to work fine. With 512 slices, it seg faults.

import numpy as np
import mahotas
from matplotlib import pyplot as plt

xx, yy, zz = np.meshgrid(np.arange(2048), np.arange(2048), np.arange(512))
dist = np.sqrt((xx - 1024) ** 2 + (yy - 1024) ** 2 + (zz - 256) ** 2)
del xx, yy, zz
seed_img = np.zeros(dist.shape, dtype=np.uint64)
dist = dist.astype(np.float32)
wsimg = mahotas.cwatershed(dist, seed_img, Bc=np.ones((3,3,3)))
wsimg[dist > 100] = 0
plt.imsave('ws_test_img.png', wsimg[:, :, 256])

luispedro added a commit that referenced this issue Apr 8, 2019
@luispedro
Copy link
Owner

luispedro commented Apr 8, 2019

I was trying to test this, but it's incredibly slow to work with such very large matrices on the only machine to that I have access to that has enough memory for this to work (it's a pretty old and slow machine, but has a lot of memory).

I switched a few remaining uses of int (32 bit s) to npy_intp (64 bits), so this may now work (if you wait long enough, at least it hasn't crashed yet).

@williamjshipman
Copy link
Author

williamjshipman commented Apr 11, 2019 via email

luispedro added a commit that referenced this issue Jul 10, 2019
Bugfix release

Full `ChangeLog`:
    * Make watershed work for >2³¹ voxels (issue #102)
    * Remove milk from demos
    * Improve performance by avoid unnecessary array copies in
    ``cwatershed()``, ``majority_filter()``, and color conversions
    * Fix bug in interpolation
luispedro added a commit that referenced this issue Jul 10, 2019
Bugfix release

Full `ChangeLog`:
    * Make watershed work for >2³¹ voxels (issue #102)
    * Remove milk from demos
    * Improve performance by avoid unnecessary array copies in
    ``cwatershed()``, ``majority_filter()``, and color conversions
    * Fix bug in interpolation
luispedro added a commit that referenced this issue Oct 14, 2021
luispedro added a commit that referenced this issue Oct 14, 2021
luispedro added a commit that referenced this issue Oct 14, 2021
Bugfix release

Full `ChangeLog`:
    * Make watershed work for >2³¹ voxels (issue #102)
    * Remove milk from demos
    * Improve performance by avoid unnecessary array copies in
    ``cwatershed()``, ``majority_filter()``, and color conversions
    * Fix bug in interpolation
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

2 participants