【发布时间】:2020-05-24 00:08:22
【问题描述】:
我正在尝试从图像中分割出组织斑点。我做了一些初步的预处理,得到了以下结果。我担心的是边界上的噪音。如果我用水平/垂直内核侵蚀,我也会在中间丢失一些数据。我不确定什么是更好的实现结果,或者我应该通过不同的方法进行细分。
这是示例图片:
import numpy as np
import os
import matplotlib.pyplot as plt
from skimage import io
from skimage.filters import threshold_mean
from skimage.exposure import adjust_sigmoid, adjust_gamma
from skimage.morphology import opening
from skimage import morphology
import scipy.ndimage as ndi
def create_binary_mask(path_to_file):
file = io.imread(path_to_file)
#APPLY FILTERS FOR BETTER THRESHOLD
img_med = ndi.median_filter(file, size=20) #REDUCE NOISE
adjusted_gamma = adjust_gamma(img_med, 1.8, 2) #INCREASE GAMMA
adjusted_sigmoid = adjust_sigmoid(adjusted_gamma, 0.01) #INCREASE CONTRAST
#DO THE MEAN THRESHOLD
thresh = threshold_mean(adjusted_sigmoid)
binary = adjusted_sigmoid > thresh
#REMOVE SMALL NOISE WITHIN THE IMAGE
disk = morphology.disk(radius=7)
opening = morphology.binary_opening(binary, disk)
fig, axis = plt.subplots(1,4, figsize=(10,10))
axis[0].imshow(file, cmap='gray')
axis[0].set_title('Original File')
axis[1].imshow(adjusted_sigmoid, cmap='gray')
axis[1].set_title('Adjusted Sigmoid')
axis[2].imshow(binary, cmap='gray')
axis[2].set_title('Mean Threshold')
axis[3].imshow(opening, cmap='gray')
axis[3].set_title('After opening')
plt.savefig('results.png')
plt.show()
path_to_file = "sample_img.png"
create_binary_mask(path_to_file)
【问题讨论】:
-
为什么不给我们看未经处理的图像?
-
图中原始文件为未经处理的图片。
-
你说“我做了一些初步的预处理,得到了以下结果。”
标签: python numpy opencv image-processing scikit-image