📜  Mahotas – Riddler-Calvard 方法

📅  最后修改于: 2022-05-13 01:54:25.764000             🧑  作者: Mango

Mahotas – Riddler-Calvard 方法

在本文中,我们将了解如何在 mahotas 中实现谜语 calvard 方法。这是大津方法的替代方案。 Ridler 和 Calvard 算法使用迭代聚类方法。首先要进行阈值的初始估计(例如平均图像强度)。高于和低于阈值的像素分别分配给对象和背景类。

在本教程中,我们将使用“luispedro”图像,下面是加载它的命令。

mahotas.demos.load('luispedro')

下面是 luispedro 图像

为此,我们将使用 mahotas.rc 方法

注意:输入图像应被过滤或加载为灰色

为了过滤图像,我们将获取图像对象 numpy.ndarray 并在索引的帮助下对其进行过滤,下面是执行此操作的命令

image = image[:, :, 0]

示例 1:

Python3
# importing required libraries
import mahotas
import mahotas.demos
import numpy as np
from pylab import imshow, gray, show
from os import path
 
# loading the image
photo = mahotas.demos.load('luispedro')
 
# showing original image
print("Original Image")
imshow(photo)
show()
 
# loading image as grey
photo = mahotas.demos.load('luispedro', as_grey = True)
 
# converting image type to unit8
# because as_grey returns floating values
photo = photo.astype(np.uint8)
 
# riddler calvard
T_rc = mahotas.rc(photo)
 
# printing otsu value
print("R C value : " + str(T_rc))
 
print("Image threshold using riddler calvard method")
# showing image
# image values should be greater than T_rc value
imshow(photo > T_rc)
show()


Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
 
# loading image
img = mahotas.imread('dog_image.png')
     
 
# setting filter to the image
img = img[:, :, 0]
 
imshow(img)
show()
 
 
# riddler calvard
T_rc = mahotas.rc(img)
 
# printing otsu value
print("R C value : " + str(T_rc))
 
print("Image threshold using riddler calvard method")
# showing image
# image values should be greater than T_rc value
imshow(img > T_rc)
show()


输出 :

示例 2:

Python3

# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
 
# loading image
img = mahotas.imread('dog_image.png')
     
 
# setting filter to the image
img = img[:, :, 0]
 
imshow(img)
show()
 
 
# riddler calvard
T_rc = mahotas.rc(img)
 
# printing otsu value
print("R C value : " + str(T_rc))
 
print("Image threshold using riddler calvard method")
# showing image
# image values should be greater than T_rc value
imshow(img > T_rc)
show()

输出 :