- Mahotas 教程
- Mahotas - 首頁
- Mahotas - 簡介
- Mahotas - 計算機視覺
- Mahotas - 歷史
- Mahotas - 特性
- Mahotas - 安裝
- Mahotas 處理影像
- Mahotas - 處理影像
- Mahotas - 載入影像
- Mahotas - 載入灰度影像
- Mahotas - 顯示影像
- Mahotas - 顯示影像形狀
- Mahotas - 儲存影像
- Mahotas - 影像的質心
- Mahotas - 影像卷積
- Mahotas - 建立 RGB 影像
- Mahotas - 影像的尤拉數
- Mahotas - 影像中零的比例
- Mahotas - 獲取影像矩
- Mahotas - 影像中的區域性最大值
- Mahotas - 影像橢圓軸
- Mahotas - 影像拉伸 RGB
- Mahotas 顏色空間轉換
- Mahotas - 顏色空間轉換
- Mahotas - RGB 到灰度轉換
- Mahotas - RGB 到 LAB 轉換
- Mahotas - RGB 到 Sepia 轉換
- Mahotas - RGB 到 XYZ 轉換
- Mahotas - XYZ 到 LAB 轉換
- Mahotas - XYZ 到 RGB 轉換
- Mahotas - 增加伽馬校正
- Mahotas - 拉伸伽馬校正
- Mahotas 標籤影像函式
- Mahotas - 標籤影像函式
- Mahotas - 影像標記
- Mahotas - 過濾區域
- Mahotas - 邊界畫素
- Mahotas - 形態學操作
- Mahotas - 形態學運算元
- Mahotas - 查詢影像均值
- Mahotas - 裁剪影像
- Mahotas - 影像的偏心率
- Mahotas - 影像疊加
- Mahotas - 影像的圓度
- Mahotas - 影像縮放
- Mahotas - 影像直方圖
- Mahotas - 影像膨脹
- Mahotas - 影像腐蝕
- Mahotas - 分水嶺演算法
- Mahotas - 影像開運算
- Mahotas - 影像閉運算
- Mahotas - 填充影像孔洞
- Mahotas - 條件膨脹影像
- Mahotas - 條件腐蝕影像
- Mahotas - 影像條件分水嶺演算法
- Mahotas - 影像中的區域性最小值
- Mahotas - 影像的區域最大值
- Mahotas - 影像的區域最小值
- Mahotas - 高階概念
- Mahotas - 影像閾值化
- Mahotas - 設定閾值
- Mahotas - 軟閾值
- Mahotas - Bernsen 區域性閾值化
- Mahotas - 小波變換
- 建立影像小波中心
- Mahotas - 距離變換
- Mahotas - 多邊形工具
- Mahotas - 區域性二值模式
- 閾值鄰域統計
- Mahotas - Haralick 特徵
- 標籤區域的權重
- Mahotas - Zernike 特徵
- Mahotas - Zernike 矩
- Mahotas - 排序濾波器
- Mahotas - 2D 拉普拉斯濾波器
- Mahotas - 多數濾波器
- Mahotas - 均值濾波器
- Mahotas - 中值濾波器
- Mahotas - Otsu 方法
- Mahotas - 高斯濾波
- Mahotas - 擊中擊不中變換
- Mahotas - 標籤最大陣列
- Mahotas - 影像的平均值
- Mahotas - SURF 密集點
- Mahotas - SURF 積分
- Mahotas - Haar 變換
- 突出顯示影像最大值
- 計算線性二值模式
- 獲取標籤的邊界
- 反轉 Haar 變換
- Riddler-Calvard 方法
- 標籤區域的大小
- Mahotas - 模板匹配
- 加速魯棒特徵
- 去除邊界標籤
- Mahotas - Daubechies 小波
- Mahotas - Sobel 邊緣檢測
Mahotas - 標籤區域的大小
標籤區域的大小指的是標記影像不同區域中存在的畫素數量。標記影像指的是為影像的不同區域(一組畫素)分配唯一標籤(值)的影像。
通常,影像有兩個主要區域:前景和背景。
每個區域的大小取決於影像中存在的區域總數。如果存在更多區域,則每個區域的大小將更小。
相反,如果存在較少的區域,則每個區域的大小將更大。
Mahotas 中標籤區域的大小
在 Mahotas 中,我們可以使用 **mahotas.labeled.labeled_size()** 函式來計算標記影像中每個區域的大小。該函式的工作方式如下:
它首先計算影像中標記區域的數量。
然後,它遍歷所有標記區域並計算每個區域中存在的畫素總數。
一旦遍歷完所有區域,該函式就會返回每個區域的大小。
mahotas.labeled.labeled_size() 函式
mahotas.labeled.labeled_size() 函式將標記影像作為輸入,並返回一個列表,其中包含每個區域以畫素為單位的大小。
我們可以遍歷該值列表以獲取每個區域的大小。
語法
以下是 Mahotas 中 labeled_size() 函式的基本語法:
mahotas.labeled.labeled_size(labeled)
其中,
**labeled** - 輸入的標記影像。
示例
在以下示例中,我們使用 mh.labeled.labeled_size() 函式查詢影像的標記區域的大小。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('sea.bmp')
# Labeling the image
labeled, num_objects = mh.label(image)
# Getting the sizes of labeled regions
labeled_size = mh.labeled.labeled_size(labeled)
# Printing the sizes of labeled regions
for i, labeled_size in enumerate(labeled_size, 1):
print(f"Size of Region {i} is = {labeled_size} pixels")
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 1)
# Displaying the original image
axes.imshow(image)
axes.set_title('Labeled Image')
axes.set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
以下是上述程式碼的輸出:
Size of Region 1 is = 4263 pixels Size of Region 2 is = 2234457 pixels
獲得的影像如下:
灰度影像中的大小
我們也可以找到灰度影像中標記區域的大小。灰度影像指的是隻有一個顏色通道的影像,其中每個畫素由單個強度值表示。
畫素的強度值決定了灰度的深淺。0 將導致黑色畫素,255 將導致白色畫素,而任何其他值將導致具有中間陰影的畫素。
在 Mahotas 中,要獲取灰度影像的標記區域的大小,我們首先使用 colors.rgb2gray() 函式將輸入的 RGB 影像轉換為灰度影像。
然後,我們標記灰度影像並遍歷每個區域以計算其大小。
示例
在下面提到的示例中,我們正在查詢灰度影像的標記區域的大小。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('sun.png')
# Converting it to grayscale image
image = mh.colors.rgb2gray(image)
# Labeling the image
labeled, num_objects = mh.label(image)
# Getting the sizes of labeled regions
labeled_size = mh.labeled.labeled_size(labeled)
# Printing the sizes of labeled regions
for i, labeled_size in enumerate(labeled_size, 1):
print(f"Size of Region {i} is = {labeled_size} pixels")
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 1)
# Displaying the original image
axes.imshow(image, cmap='gray')
axes.set_title('Original Image')
axes.set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
上述程式碼的輸出如下:
Size of Region 1 is = 8 pixels Size of Region 2 is = 1079032 pixels
生成的影像如下:
隨機布林影像中的大小
除了灰度影像之外,我們還可以獲取隨機布林影像中標記區域的大小。
隨機布林影像指的是每個畫素的值為 1 或 0 的影像,其中值為“1”的畫素稱為前景,值為“0”的畫素稱為背景。
在 Mahotas 中,我們首先使用 np.zeros() 函式生成特定尺寸的隨機布林影像。
生成的隨機影像最初將其所有畫素值設定為 0(僅包含背景區域)。然後,我們將整數值分配給影像的某些部分以建立不同的區域。
然後,我們標記影像並遍歷每個區域以獲取其以畫素為單位的大小。
示例
在這裡,我們正在獲取隨機生成的布林影像的不同標籤的大小。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Creating a random image
image = np.zeros((10,10), bool)
# Creating regions
image[:2, :2] = 1
image[4:6, 4:6] = 1
image[8:, 8:] = 1
# Labeling the image
labeled, num_objects = mh.label(image)
# Getting the sizes of labeled regions
labeled_size = mh.labeled.labeled_size(labeled)
# Printing the sizes of labeled regions
for i, labeled_size in enumerate(labeled_size, 1):
print(f"Size of Region {i} is = {labeled_size} pixels")
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 1)
# Displaying the original image
axes.imshow(image)
axes.set_title('Original Image')
axes.set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
執行上述程式碼後,我們將獲得以下輸出:
Size of Region 1 is = 88 pixels Size of Region 2 is = 4 pixels Size of Region 3 is = 4 pixels Size of Region 4 is = 4 pixels
獲得的影像如下所示: