-
Supports one seed or many seeds as the input of RegionGrowth algorithm
-
Supports 2d region growth: RegionGrowth.RegionGrow2D
- 4-neighbor
- 8-neighbor
-
Supports 3d region growth: RegionGrowth.RegionGrow3D
- 6-neighbor
- 26-neighbor
-
Supports adaptive thresholding method by taking (mean±3*std) of foreground pixel values as thresholds
-
Supports constant lower and upper thresholds
python setup.py build_ext
It will generate "RegionGrowth.xxx.pyd" in "./build" path, which can be imported in python.
import RegionGrowth
RegionGrowth.RegionGrow2D(img, masks, upperThreshold=255, lowerThreshold=0, neighborMode="8n").main(seeds, update=True)
img
: np.ndarray[np.uint8, ndim=2] or np.ndarray[np.uint8, ndim=3] (only writeable array is supported).masks
: same shape and type withimg
. determining whether pixels are required to be checked. If there are some given regions that doesn't contain foreground pixels, you can set corresponding masks to indicate that; otherwise, usemasks = np.ones_like(img)
.upperThreshold
andlowerThreshold
: constant thresholdsneighborMode
: RegionGrow2D supports"4n"
or"8n"
; RegionGrow3D supports"6n"
or"26n"
;seeds
: the coordinates of seeds[(y,x)]
update
: whether enable adaptive thresholding method by taking (mean±3*std) of foreground pixel values as thresholds.
import RegionGrowth
import numpy as np
from PIL import Image
if __name__ == "__main__":
img = Image.open("images/input.png").convert('L') # gray scale
img = np.array(img)
masks = np.ones_like(img)
seed_img = Image.open("images/random.png").convert('L')
seed_img = np.array(seed_img)
coords = np.where(seed_img>0)
seeds = np.stack(coords, axis=-1)
out_img = RegionGrowth.RegionGrow2D(img, masks, upperThreshold=255, lowerThreshold=0, neighborMode="8n").main(seeds, update=True)
out_img = Image.fromarray(np.asarray(out_img)*255)
out_img.save("outputs/result_growth_pyx.png")
2020-04-10