pygorpho.gen¶
Mathematical morphology with general (grayscale) structuring elements.
-
pygorpho.gen.
morph
(vol, strel, op, block_size=[256, 256, 256])[source] Morphological operation with general structuring element.
Parameters: - vol – Volume to apply operation to. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- op – Operation to perform. Must be either
DILATE
orERODE
fromconstants
. - block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of the operation.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple dilation with an 11 x 11 x 11 box structuring element vol = np.zeros((100, 100, 100)) vol[50, 50, 50] = 1 strel = np.ones((11, 11, 11)) res = pg.gen.morph(vol, strel, pg.DILATE)
-
pygorpho.gen.
dilate
(vol, strel, block_size=[256, 256, 256])[source] Dilation with general structuring element.
Parameters: - vol – Volume to dilate/erode. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of dilation/erosion.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple dilation with an 11 x 11 x 11 box structuring element vol = np.zeros((100, 100, 100)) vol[50, 50, 50] = 1 strel = np.ones((11, 11, 11)) res = pg.gen.dilate(vol, strel)
-
pygorpho.gen.
erode
(vol, strel, block_size=[256, 256, 256])[source] Erosion with general structuring element.
Parameters: - vol – Volume to dilate/erode. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of dilation/erosion.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple erosion with an 11 x 11 x 11 box structuring element vol = np.ones((100, 100, 100)) vol[50, 50, 50] = 0 strel = np.ones((11, 11, 11)) res = pg.gen.erode(vol, strel)
-
pygorpho.gen.
open
(vol, strel, block_size=[256, 256, 256])[source] Opening with general structuring element.
Parameters: - vol – Volume to open. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of opening.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple opening with an 11 x 11 x 11 box structuring element vol = np.zeros((100, 100, 100)) vol[10:15,10:15,48:53] = 1 # Small box vol[60:80,60:80,40:60] = 1 # Big box strel = np.ones((11, 11, 11)) res = pg.gen.open(vol, strel)
-
pygorpho.gen.
close
(vol, strel, block_size=[256, 256, 256])[source] Closing with general structuring element.
Parameters: - vol – Volume to close. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of closing.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple closing with an 11 x 11 x 11 box structuring element vol = np.ones((100, 100, 100)) vol[10:15,10:15,48:53] = 0 # Small box vol[60:80,60:80,40:60] = 0 # Big box strel = np.ones((11, 11, 11)) res = pg.gen.close(vol, strel)
-
pygorpho.gen.
tophat
(vol, strel, block_size=[256, 256, 256])[source] Top-hat transform with general structuring element.
Also known as a white top-hat transform. It is given by
tophat(x) = x - open(x)
.Parameters: - vol – Volume to top-hat transform. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of the top-hat transform.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple top-hat with an 11 x 11 x 11 box structuring element vol = np.zeros((100, 100, 100)) vol[10:15,10:15,48:53] = 1 # Small box vol[60:80,60:80,40:60] = 1 # Big box strel = np.ones((11, 11, 11)) res = pg.gen.tophat(vol, strel)
-
pygorpho.gen.
bothat
(vol, strel, block_size=[256, 256, 256])[source] Bot-hat transform with general structuring element.
Also known as a black top-hat transform. It is given by
bothat(x) = close(x) - x
.Parameters: - vol – Volume to bot-hat transform. Must be convertible to numpy array of at most 3 dimensions.
- strel – Structuring element. Must be convertible to numpy array of at most 3 dimensions.
- block_size – Block size for GPU processing. Volume is sent to the GPU in blocks of this size.
Returns: Volume of same size as vol with the result of the bot-hat transform.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple bot-hat with an 11 x 11 x 11 box structuring element vol = np.ones((100, 100, 100)) vol[10:15,10:15,48:53] = 0 # Small box vol[60:80,60:80,40:60] = 0 # Big box strel = np.ones((11, 11, 11)) res = pg.gen.bothat(vol, strel)