Computer vision 对我的图像应用多Otsu阈值

Computer vision 对我的图像应用多Otsu阈值,computer-vision,image-segmentation,Computer Vision,Image Segmentation,我有这张图片如下所示 在这里,我试图通过基于强度的Otsu技术定义区分双峰类的阈值,然后将直方图中的阈值可视化。到目前为止,我已经编写了以下代码: import matplotlib.pyplot as plt import numpy as np from skimage import data, io, img_as_ubyte from skimage.filters import threshold_multiotsu # Read an image image = io.imrea

我有这张图片如下所示

在这里,我试图通过基于强度的
Otsu
技术定义区分双峰类的阈值,然后将直方图中的阈值可视化。到目前为止,我已经编写了以下代码:

import matplotlib.pyplot as plt
import numpy as np

from skimage import data, io, img_as_ubyte
from skimage.filters import threshold_multiotsu

# Read an image
image = io.imread("Fig_1.png")


# Apply multi-Otsu threshold 
thresholds = threshold_multiotsu(image,classes=5)

# 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)  #Convert 64 bit integer values to uint8
          
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(10, 3.5))

# Plotting the original image.
ax[0].imshow(image, cmap='gray')
ax[0].set_title('Original')
ax[0].axis('off')

# Plotting the histogram and the two thresholds obtained from
# multi-Otsu.
ax[1].hist(image.ravel(), bins=255)
ax[1].set_title('Histogram')
for thresh in thresholds:
    ax[1].axvline(thresh, color='r')

# Plotting the Multi Otsu result.
ax[2].imshow(regions, cmap='gray')
ax[2].set_title('Multi-Otsu result')
ax[2].axis('off')

plt.subplots_adjust()

plt.show()
这给了我以下的结果。在这里,正如您所看到的,Multi-Otsu结果是完全黑色的,并且没有显示图中存在的两类对象

我选择了
classes=5
,但这是双峰的,因此把
classes=3
也给了我同样的结果

关于如何纠正这个问题有什么建议吗?提前谢谢


它是全黑的,还是像你展示的那样全黑?我希望输出的值在0-4范围内,都非常接近黑色。否。我想以这样一种方式展示,我可以清楚地看到图像中存在的两类对象。你知道怎么做吗?或者我遗漏了什么?是否可以增加值以便我可以看到对象?你需要更改图像的显示方式。查看
imshow
的文档。