📜  Mahotas – 检查两个图像是否代表相同的标签

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

Mahotas – 检查两个图像是否代表相同的标签

在本文中,我们将了解如何检查这两个图像是否代表 mahotas 中的相同标签。为此,我们将使用来自核分割基准的荧光显微镜图像。我们可以在下面给出的命令的帮助下获取图像

mahotas.demos.nuclear_image()

下面是nuclear_image

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

注意:这个的输入应该是被标记的过滤图像对象

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

image = image[:, :, 0]

示例 1:

Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
# loading nuclear image
f1 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f1 = f1[:, :, 0]
 
 
# setting gaussian filter
f1 = mahotas.gaussian_filter(f1, 4)
 
# setting threshold value
f1 = (f1> f1.mean())
 
# creating a labeled image
labeled1, n_nucleus1 = mahotas.label(f1)
 
# showing the labeled image
print("Labelled 1 Image")
imshow(labeled1)
show()
 
# loading nuclear image
f2 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f2 = f2[:, :, 0]
 
# setting gaussian filter
f2 = mahotas.gaussian_filter(f2, 4)
 
# setting threshold value
f2 = (f2> f2.mean())
 
# creating a labeled image
labeled2, n_nucleus2 = mahotas.label(f2)
 
 
# showing the labeled image
print("Labelled 2 Image")
imshow(labeled2)
show()
 
# c hecking if both the labeled images are same
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
 
# printing check
print("Same Labelling : "+ str(check))


Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
# loading nuclear image
f1 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f1 = f1[:, :, 0]
 
 
# setting gaussian filter
f1 = mahotas.gaussian_filter(f1, 4)
 
# setting threshold value
f1 = (f1> f1.mean())
 
# creating a labeled image
labeled1, n_nucleus1 = mahotas.label(f1)
 
# showing the labeled image
print("Labelled 1 Image")
imshow(labeled1)
show()
 
# loading nuclear image
f2 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f2 = f2[:, :, 0]
 
# setting gaussian filter
f2 = mahotas.gaussian_filter(f2, 4)
 
# setting threshold value
f2 = (f2> f2.mean())
 
# creating a labeled image
labeled2, n_nucleus2 = mahotas.label(f2)
 
# removing border
labeled2 = mahotas.labeled.remove_bordering(labeled2)
 
 
# showing the labeled image
print("Labelled 2 Image")
imshow(labeled2)
show()
 
# checking if both the labeled images are same
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
 
# printing check
print("Same Labelling : "+ str(check))


输出 :

Same Labelling : True

示例 2:

Python3

# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
# loading nuclear image
f1 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f1 = f1[:, :, 0]
 
 
# setting gaussian filter
f1 = mahotas.gaussian_filter(f1, 4)
 
# setting threshold value
f1 = (f1> f1.mean())
 
# creating a labeled image
labeled1, n_nucleus1 = mahotas.label(f1)
 
# showing the labeled image
print("Labelled 1 Image")
imshow(labeled1)
show()
 
# loading nuclear image
f2 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f2 = f2[:, :, 0]
 
# setting gaussian filter
f2 = mahotas.gaussian_filter(f2, 4)
 
# setting threshold value
f2 = (f2> f2.mean())
 
# creating a labeled image
labeled2, n_nucleus2 = mahotas.label(f2)
 
# removing border
labeled2 = mahotas.labeled.remove_bordering(labeled2)
 
 
# showing the labeled image
print("Labelled 2 Image")
imshow(labeled2)
show()
 
# checking if both the labeled images are same
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
 
# printing check
print("Same Labelling : "+ str(check))

输出 :

Same Labelling : False