Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 为什么在直方图均衡化(scikit图像)和大津mahotas方法之后,有些图像会出现大的白色方块?_Image Processing_Scikit Image_Mahotas - Fatal编程技术网

Image processing 为什么在直方图均衡化(scikit图像)和大津mahotas方法之后,有些图像会出现大的白色方块?

Image processing 为什么在直方图均衡化(scikit图像)和大津mahotas方法之后,有些图像会出现大的白色方块?,image-processing,scikit-image,mahotas,Image Processing,Scikit Image,Mahotas,我使用直方图均衡化和自适应从灰度图像擦除照明: 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 ex

我使用直方图均衡化和自适应从灰度图像擦除照明:

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)
导入scipy
将numpy作为np导入
导入pymorph作为pm
作为mh导入mahotas
从撇渣进口形态学
从撇渣进口io
从matplotlib导入pyplot作为plt
从skimage导入数据中,img_as_float
从撇渣进口风险
mhgray=io.imread(路径)
mhgray=mhgray[:,:,0]
#thresh=mh.大津(binimg)
#灰色=(binimg
但在测试之后,我使用大津方法:

thresh = mh.otsu(binimg) 
gray =( binimg< thresh)
thresh=mh.otsu(binimg)
灰色=(binimg
下一个示例的阈值为:16329

源图像:

直方图均衡化和自适应后:

大津法之后:

thresh = mh.otsu(binimg) 
gray =( binimg< thresh)

大津之前的图像是uint16数组,大津之后的图像是布尔的numpy数组

在本文中,我建议使用直方图均衡化来避免照明问题

是灰色背景的吗?
我如何修复它?

您有没有理由不使用skimage的内置大津功能

import numpy as np
import pylab as plt
from skimage import io, color, filter, exposure


img = color.rgb2gray(io.imread('7AEJTuA.jpg'))
img_rescale = exposure.rescale_intensity(img, out_range=(0, 1))

threshold = filter.threshold_otsu(img_rescale)

plt.gray()
plt.imshow(img_rescale < threshold)
plt.show()
将numpy导入为np
导入pylab作为plt
从skimage导入io、颜色、过滤器、曝光
img=color.rgb2gray(io.imread('7AEJTuA.jpg'))
img\U重缩放=曝光。重缩放强度(img,超出范围=(0,1))
阈值=过滤器。阈值\u大津(img\u重新缩放)
plt.gray()
plt.imshow(img_重新缩放<阈值)
plt.show()

您还可以查看
skimage.filter.rank.otsu
作为替代…

向上述示例中添加一个膨胀命令:

import numpy as np
import pylab as plt
from skimage import io, color, filter, exposure, morphology


img = color.rgb2gray(io.imread('7AEJTuA.jpg'))

threshold = filter.threshold_otsu(img)

img_bw = img < threshold

img_bw_thick = morphology.dilation(img_bw, morphology.disk(6))

plt.gray()
f, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(img)
ax1.imshow(img_bw_thick)
plt.show()
将numpy导入为np
导入pylab作为plt
从撇渣导入io、颜色、过滤器、曝光、形态
img=color.rgb2gray(io.imread('7AEJTuA.jpg'))
阈值=过滤器。阈值\u大津(img)
img_bw=img<阈值
img_bw_thick=形态学.扩张(img_bw,形态学.圆盘(6))
plt.gray()
f、 (ax0,ax1)=plt.子批次(1,2)
ax0.imshow(img)
ax1.imshow(img\u bw\u厚)
plt.show()
我看到下图:


请提供输入图像的副本。抱歉:源图像:另一个图像:结果是:我只转移了问题,因为我的代码的下一行是:img=mh.morph.close(img,disko),现在图像像这样::Black image。如果我使用scikit DILLATION:img=DILLATION(img,disk(6)),结果总是黑色的!在扩展之前,我有一个uint16数组,在它是uint8之后:“警告:从uint16转换到uint8时可能会丢失精度。”我通过以下方式转换类型:gray=np.array(gray,dtype=np.uint16),但始终是黑色的!是的,你不能像那样缩放图像--你需要使用
img\u as\u float
img\u as\u ubyte
img\u as\u uint
等等,这会返回正确的类型和范围。我看不到你所说的黑色图像。我已经在上面的代码中添加了一个扩张命令,并按照预期看到了扩张的图像。我会发布一个新的答案,这样我可以附加图片,虽然它应该作为注释放在这里