Memory Error while using the Binary Opening operation in Sci-Kit Image package for granulometry

596 Views Asked by At

I get a memory error when I am using the opening operation in the scikit-image package (it saturates my RAM). This memory error occurs for a 3-D structuring element which is a sphere/ball of radius 16 or larger. I am trying to use granulometry to measure the size distribution of objects in the image (3D array), so I need structuring elements of increasing radii. The memory requirements also increase exponentially and I cannot find a way around it. Is there a simple solution to this problem so that I can use structuring elements of even greater radii? The image size is 200X200X200. TIA

Traceback (most recent call last):
  File "R3.py", line 124, in <module>
    output_image = skimage.morphology.binary_opening(image, ball)
  File "/usr/lib/python2.7/dist-packages/skimage/morphology/binary.py", line 117, in binary_opening
    eroded = binary_erosion(image, selem)
  File "/usr/lib/python2.7/dist-packages/skimage/morphology/binary.py", line 41, in binary_erosion
    ndimage.convolve(binary, selem, mode='constant', cval=1, output=conv)
  File "/usr/lib/python2.7/dist-packages/scipy/ndimage/filters.py", line 696, in convolve
    origin, True)
  File "/usr/lib/python2.7/dist-packages/scipy/ndimage/filters.py", line 544, in _correlate_or_convolve
    _nd_image.correlate(input, weights, output, mode, cval, origins)
MemoryError
1

There are 1 best solutions below

0
On

A volume of dimensions 200x200x200 is pretty small. A granulometry is made of sequential openings, so you just need 2 more volumes for the computation: one temporary between the erosion and the dilation, and one more for the final results. Which means three volumes total. And the structuring element should be a list of coordinates, so nothing too big.

Consequently, there is absolutely not reason you cannot perform a granulometry on your computer for a volume of such dimensions. The only explanation for the exponential memory use would be that the intermediate results are not erased.