1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | # Auto segmentation using multi-otsu, https://www.youtube.com/watch?v=YdhhiXDQDl4&list=PLZsOBAyNTZwYx-7GylDo3LSYpSompzsqW&index=36
# https://github.com/bnsreenu/python_for_microscopists/blob/master/115_auto_segmentation_using_multiotsu.py
import matplotlib.pyplot as plt
import numpy as np
from skimage import data, io, img_as_ubyte
from skimage.filters import threshold_multiotsu
from skimage.color import rgb2gray
# Read an image
image=io.imread("D:/Mask/IMG_0252.JPG")
image=rgb2gray(image)
# image=Image.open("D:/Mask/IMG_0252.JPG").convert('L')
# Apply multi-Otsu threshold
thresholds=threshold_multiotsu(image, classes=2)
# Digitize (segment) original image into multiple classes
# np.digitize assign values 0, 1, 2, 3, ... to pixels in each class
regions=np.digitize(image, bins=thresholds)
output=img_as_ubyte(regions)
plt.imsave("D:/Mask/otsu_segment.jpg", output)
|
No comments:
Post a Comment