我使用直方图均衡和自适应来消除灰度图像中的照明:
import scipy
import numpy as np
import pymorph as pm
import mahotas as mh
from skimage import morphology
from skimage import io
from matplotlib import pyplot as plt
from skimage import data, img_as_float
from skimage import exposure
mhgray = io.imread(path)
mhgray = mhgray[:,:,0]
#thresh = mh.otsu(binimg)
#gray =( binimg< thresh)
img = color.rgb2gray(mhgray)
#img = mhgray #binimg
#from skimage import exposure
#print dir(exposure)
# Contrast stretching
p2 = np.percentile(img, 2)
p98 = np.percentile(img, 98)
#img_rescale = exposure.rescale_intensity(img, in_range=(p2, p98))
img_rescale = exposure.rescale_intensity(img, out_range=(0, 255))
# Equalization
img_eq = exposure.equalize_hist(img)
# Adaptive Equalization
img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.03)
但在直方图均衡之后,我使用 otsu 方法:
thresh = mh.otsu(binimg)
gray =( binimg< thresh)
下一个示例的阈值是:16329
源图像:
直方图均衡和自适应后:
大津法后:
Otsu 之前的图像是一个 uint16 数组,Otsu 之后是一个 numpy 布尔数组。
在stackoverflow中建议我使用直方图均衡来避免照明问题。
是灰色背景吗?我该如何解决?