📜  Python Mahotas 中的标记图像函数

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

Python Mahotas 中的标记图像函数

在本文中,我们将了解如何从 mahotas 中的二元函数中获取标记函数。标记图像是整数图像,其中值对应于不同区域。即,区域 1 是具有值 1 的所有像素,区域 2 是具有值 2 的像素,依此类推。按照惯例,区域 0 是背景,通常以不同方式处理。
为此,我们将使用 mahotas.label 方法

示例 1:

Python3
# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
 
# creating region
# numpy.ndarray
regions = np.zeros((8, 8), bool)
 
# setting 1 value to the region
regions[:3, :3] = 1
regions[6:, 6:] = 1
 
# getting labelled function
labelled, nr_objects = mh.label(regions)
 
# showing the image with interpolation = 'nearest'
imshow(labelled, interpolation ='nearest')
show()


Python3
# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
 
# creating region
# numpy.ndarray
regions = np.zeros((10, 10), bool)
 
# setting 1 value in the region
regions[1, 1] = 1
regions[6, 6] = 1
regions[4, 4] = 1
regions[9, 9] = 1
 
# getting labelled function
labelled, nr_objects = mh.label(regions)
 
# showing the image with interpolation = 'nearest'
imshow(labelled, interpolation ='nearest')
show()


输出 :

示例 2:

Python3

# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
 
# creating region
# numpy.ndarray
regions = np.zeros((10, 10), bool)
 
# setting 1 value in the region
regions[1, 1] = 1
regions[6, 6] = 1
regions[4, 4] = 1
regions[9, 9] = 1
 
# getting labelled function
labelled, nr_objects = mh.label(regions)
 
# showing the image with interpolation = 'nearest'
imshow(labelled, interpolation ='nearest')
show()

输出 :