Mahotas – 突出图像最大值
在本文中,我们将了解如何在 mahotas 中突出显示图像的最大值。在距离图图像中可以最好地找到最大值,因为在标记图像中每个标签都是最大值,但在距离图中可以很容易地识别最大值。为此,我们将使用来自核分割基准的荧光显微镜图像。我们可以在下面给出的命令的帮助下获取图像
mahotas.demos.nuclear_image()
下面是nuclear_image
为此,我们将使用 mahotas.morph.regmax 方法
Syntax : mahotas.morph.regmax(img, Bc)
Argument : It takes image object and numpy ones array as argument
Return : It returns image object
注意: this 的输入应该是过滤后的图像或加载为灰色
为了过滤图像,我们将获取图像对象 numpy.ndarray 并在索引的帮助下对其进行过滤,下面是执行此操作的命令
image = image[:, :, 0]
示例 1:
Python3
# importing various libraries
import mahotas
import mahotas.demos
import mahotas as mh
import numpy as np
from pylab import imshow, show
# loading nuclear image
nuclear = mahotas.demos.nuclear_image()
# filtering image
nuclear = nuclear[:, :, 0]
# adding gaussian filter
nuclear = mahotas.gaussian_filter(nuclear, 4)
# setting threshold
threshed = (nuclear > nuclear.mean())
# creating distance map
dmap = mahotas.distance(threshed)
print("Distance Map")
# showing image
imshow(dmap)
show()
# numpy ones array
Bc = np.ones((3, 2))
# getting maxima
maxima = mahotas.morph.regmax(dmap, Bc = Bc)
# showing image
print("Maxima")
imshow(maxima)
show()
Python3
# importing required libraries
import numpy as np
import mahotas
from pylab import imshow, show
# loading image
img = mahotas.imread('dog_image.png')
# filtering the image
img = img[:, :, 0]
# setting gaussian filter
gaussian = mahotas.gaussian_filter(img, 15)
# setting threshold value
gaussian = (gaussian > gaussian.mean())
# creating a labelled image
labelled, n_nucleus = mahotas.label(gaussian)
# getting distance map
dmap = mahotas.distance(labelled)
# showing image
print("Distance Map")
imshow(dmap)
show()
# numpy ones array
Bc = np.ones((4, 1))
# getting maxima
maxima = mahotas.morph.regmax(dmap, Bc = Bc)
# showing image
print("Maxima")
imshow(maxima)
show()
输出 :
示例 2:
Python3
# importing required libraries
import numpy as np
import mahotas
from pylab import imshow, show
# loading image
img = mahotas.imread('dog_image.png')
# filtering the image
img = img[:, :, 0]
# setting gaussian filter
gaussian = mahotas.gaussian_filter(img, 15)
# setting threshold value
gaussian = (gaussian > gaussian.mean())
# creating a labelled image
labelled, n_nucleus = mahotas.label(gaussian)
# getting distance map
dmap = mahotas.distance(labelled)
# showing image
print("Distance Map")
imshow(dmap)
show()
# numpy ones array
Bc = np.ones((4, 1))
# getting maxima
maxima = mahotas.morph.regmax(dmap, Bc = Bc)
# showing image
print("Maxima")
imshow(maxima)
show()
输出 :