Mahotas – 去除带边框的标签
在本文中,我们将了解如何从 mahotas 中的标记图像中删除带边框的标签。边框标签是那些与边框接触的标签,我们可以借助 mahotas.label 方法从普通图像创建标记图像。
为此,我们将使用来自核分割基准的荧光显微镜图像。我们可以在下面给出的命令的帮助下获取图像
mhotas.demos.nuclear_image()
下面是nuclear_image
标记图像是整数图像,其中值对应于不同区域。即,区域 1 是所有值为 1 的像素,区域 2 是值为 2 的像素,依此类推
为此,我们将使用 mahotas.remove_bordering 方法
Syntax : mahotas.remove_bordering(labelled)
Argument : It takes labelled image object as argument
Return : It returns the labelled image without label at the borders
示例 1:
Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
# loading nuclear image
f = mahotas.demos.load('nuclear')
# setting filter to the image
f = f[:, :, 0]
# setting gaussian filter
f = mahotas.gaussian_filter(f, 4)
# setting threshold value
f = (f> f.mean())
# creating a labelled image
labelled, n_nucleus = mahotas.label(f)
# showing the labelled image
print("Labelled Image")
imshow(labelled)
show()
# removing border labels
labelled = mahotas.labelled.remove_bordering(labelled)
# showing the image
print("No border Label")
imshow(labelled)
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)
print("Labelled Image")
# showing the gaussian filter
imshow(labelled)
show()
# removing border labels
labelled = mahotas.labelled.remove_bordering(labelled)
# showing the image
print("No border Label")
imshow(labelled)
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)
print("Labelled Image")
# showing the gaussian filter
imshow(labelled)
show()
# removing border labels
labelled = mahotas.labelled.remove_bordering(labelled)
# showing the image
print("No border Label")
imshow(labelled)
show()
输出 :