pygorpho.flat¶
Mathematical morphology with flat (binary) structuring elements.
-
pygorpho.flat.
morph
(vol, strel, op, block_size=[256, 256, 256])[source] Morphological operation with flat 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
,ERODE
,OPEN
,CLOSE
,TOPHAT
,CLOSE
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.flat.morph(vol, strel, pg.DILATE)
-
pygorpho.flat.
dilate
(vol, strel, block_size=[256, 256, 256])[source] Dilation with flat 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.
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.flat.dilate(vol, strel)
-
pygorpho.flat.
erode
(vol, strel, block_size=[256, 256, 256])[source] Erosion with flat 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 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.flat.erode(vol, strel)
-
pygorpho.flat.
open
(vol, strel, block_size=[256, 256, 256])[source] Opening with flat 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.flat.open(vol, strel)
-
pygorpho.flat.
close
(vol, strel, block_size=[256, 256, 256])[source] Closing with flat 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.flat.close(vol, strel)
-
pygorpho.flat.
tophat
(vol, strel, block_size=[256, 256, 256])[source] Top-hat transform with flat 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.flat.tophat(vol, strel)
-
pygorpho.flat.
bothat
(vol, strel, block_size=[256, 256, 256])[source] Bot-hat transform with flat 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.flat.bothat(vol, strel)
-
pygorpho.flat.
linear_morph
(vol, line_steps, line_lens, op, block_size=[256, 256, 512])[source] Morphological operation with flat line segment structuring elements.
Performs a morphological operation volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operation is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to apply operation to. Must be convertible to numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- op – Operation to perform for all line segments. 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 15 x 21 box structuring element vol = np.zeros((100,100,100)) vol[50, 50, 50] = 1 lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 15, 21] res = pg.flat.linear_morph(vol, lineSteps, lineLens, pg.DILATE)
References
[H92] (1, 2, 3, 4, 5, 6, 7) M. Van Herk, “A fast algorithm for local minimum and maximum filters on rectangular and octagonal kernels,” Pattern Recognition Letters 13. (pp. 517-521). 1992. [GW93] (1, 2, 3, 4, 5, 6, 7) J. Gil and M Werman, “Computing 2-D min, median, and max filters,” IEEE Transactions on Pattern Analysis and Machine Intelligence 24. (pp. 504-507). 1993.
-
pygorpho.flat.
linear_dilate
(vol, line_steps, line_lens, block_size=[256, 256, 512])[source] Dilation with flat line segment structuring elements.
Erodes volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operations is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to dilate. Must be convertible to a numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- 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.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple dilation with an 11 x 15 x 21 box structuring element vol = np.zeros((100,100,100)) vol[50, 50, 50] = 1 lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 15, 21] res = pg.flat.linear_dilate(vol, lineSteps, lineLens)
-
pygorpho.flat.
linear_erode
(vol, line_steps, line_lens, block_size=[256, 256, 512])[source] Erosion with flat line segment structuring elements.
Erodes volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operations is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to erode. Must be convertible to a numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- 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 erosion.
Return type: numpy.array
Example
import numpy as np import pygorpho as pg # Simple erosion with an 11 x 15 x 21 box structuring element vol = np.ones((100,100,100)) vol[50, 50, 50] = 0 lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 15, 21] res = pg.flat.linear_erode(vol, lineSteps, lineLens)
-
pygorpho.flat.
linear_open
(vol, line_steps, line_lens, block_size=[256, 256, 512])[source] Opening with flat line segment structuring elements.
Opens volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operations is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to open. Must be convertible to a numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- 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 lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 11, 11] res = pg.flat.linear_open(vol, lineSteps, lineLens)
-
pygorpho.flat.
linear_close
(vol, line_steps, line_lens, block_size=[256, 256, 512])[source] Closing with flat line segment structuring elements.
Closes volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operations is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to close. Must be convertible to a numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- 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 lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 11, 11] res = pg.flat.linear_close(vol, lineSteps, lineLens)
-
pygorpho.flat.
linear_tophat
(vol, line_steps, line_lens, block_size=[256, 256, 512])[source] Top-hat transform with flat line segment structuring elements.
Top-hat transforms volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operations is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to top-hat transform. Must be convertible to a numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- 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 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.ones((100, 100, 100)) vol[10:15,10:15,48:53] = 0 # Small box vol[60:80,60:80,40:60] = 0 # Big box lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 11, 11] res = pg.flat.linear_tophat(vol, lineSteps, lineLens)
-
pygorpho.flat.
linear_bothat
(vol, line_steps, line_lens, block_size=[256, 256, 512])[source] Bot-hat transform with flat line segment structuring elements.
Bot-hat transforms volume with a sequence of flat line segments. Line segments are parameterized with a (integer) step vector and a length giving the number of steps. The operations is the same for all line segments.
The operations are performed using the van Herk/Gil-Werman algorithm [H92] [GW93].
Parameters: - vol – Volume to bot-hat transform. Must be convertible to a numpy array of at most 3 dimensions.
- line_steps – Step vector or sequence of step vectors. A step vector must have integer coordinates and control the direction of the line segment.
- line_lens – Length or sequence of lengths. Controls the length of the line segments. A length of 0 leaves the volume unchanged.
- 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 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 lineSteps = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] lineLens = [11, 11, 11] res = pg.flat.linear_tophat(vol, lineSteps, lineLens)