📜  Mahotas – 二值图像中对象的周长

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

Mahotas – 二值图像中对象的周长

在本文中,我们将了解如何在 mahotas 中获取二进制图像中对象的周长。为此,我们将使用来自核分割基准的荧光显微镜图像。我们可以在下面给出的命令的帮助下获取图像

mhotas.demos.nuclear_image()

下面是nuclear_image

如果一个像素的值为 1 并且在其邻域中至少有一个零值像素,则该像素是对象周长的一部分。默认情况下,一个像素的邻域是 4 个最近的像素,但如果我们可以将其设置为 8,那么将考虑 8 个最近的像素。
为此,我们将使用 mahotas.labelled.bwperim 方法

注意: this 的输入应该是被标记的过滤图像对象
为了过滤图像,我们将获取图像对象 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
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()
 
# getting perimeters
relabelled = mahotas.labelled.bwperim(labelled)
 
 
# showing the image
print("Perimeters Image")
imshow(relabelled)
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()
  
# getting perimeters
relabeled = mahotas.labelled.bwperim(labelled, 8)
 
 
# showing the image
print("Perimeters Image")
imshow(relabelled)
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()
  
# getting perimeters
relabeled = mahotas.labelled.bwperim(labelled, 8)
 
 
# showing the image
print("Perimeters Image")
imshow(relabelled)
show()

输出 :