- 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 - Haralic 特徵
- 標記區域的權重
- Mahotas - Zernike 特徵
- Mahotas - Zernike 矩
- Mahotas - 排序濾波器
- Mahotas - 2D 拉普拉斯濾波器
- Mahotas - 多數濾波器
- Mahotas - 均值濾波器
- Mahotas - 中值濾波器
- Mahotas - Otsu 方法
- Mahotas - 高斯濾波
- Mahotas - Hit & Miss 變換
- Mahotas - 標記最大值陣列
- Mahotas - 影像均值
- Mahotas - SURF 密集點
- Mahotas - SURF 積分圖
- Mahotas - Haar 變換
- 突出顯示影像最大值
- 計算線性二值模式
- 獲取標籤邊界
- 反轉 Haar 變換
- Riddler-Calvard 方法
- 標記區域的大小
- Mahotas - 模板匹配
- 加速魯棒特徵
- 移除邊界標記
- Mahotas - Daubechies 小波
- Mahotas - Sobel 邊緣檢測
Mahotas - 影像標記
影像標記是指將類別(標籤)分配給影像的不同區域。標籤通常用整數值表示,每個值對應於特定類別或區域。
例如,讓我們考慮一個包含各種物體或區域的影像。每個區域都被分配一個唯一的值(整數)以將其與其他區域區分開來。背景區域的標籤值為 0。
在 Mahotas 中標記影像
在 Mahotas 中,我們可以使用 label() 或 labeled.label() 函式來標記影像。
這些函式透過為影像中不同的連通元件分配唯一的標籤或識別符號來將影像分割成不同的區域。每個連通元件是一組相鄰的畫素,它們共享一個共同的屬性,例如強度或顏色。
標記過程建立一個影像,其中屬於同一區域的畫素被分配相同的標籤值。
使用 mahotas.label() 函式
mahotas.label() 函式以影像作為輸入,其中感興趣的區域由前景(非零)值表示,背景由零表示。
該函式返回標記的陣列,其中每個連通元件或區域都被分配一個唯一的整數標籤。
label() 函式使用 8 連通性進行標記,這指的是影像中畫素之間的關係,其中每個畫素都與其周圍的八個鄰居(包括對角線)相連。
語法
以下是 mahotas 中 label() 函式的基本語法:
mahotas.label(array, Bc={3x3 cross}, output={new array})
其中:
array - 輸入陣列。
Bc (可選) - 用於連通性的結構元素。
output (可選) - 輸出陣列(預設為與 array 形狀相同的新的陣列)。
示例
在下面的示例中,我們使用 mh.label() 函式來標記影像。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image_rgb = mh.imread('sun.png')
image = image_rgb[:,:,0]
# Applying gaussian filtering
image = mh.gaussian_filter(image, 4)
image = (image > image.mean())
# Converting it to a labeled image
labeled, num_objects = mh.label(image)
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original RGB image
axes[0].imshow(image_rgb)
axes[0].set_title('RGB Image')
axes[0].set_axis_off()
# Displaying the labeled image
axes[1].imshow(labeled)
axes[1].set_title('Labeled Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
以下是上述程式碼的輸出:
使用 mahotas.labeled.label() 函式
mahotas.labeled.label() 函式為影像的不同區域分配從 1 開始的連續標籤。它與 mahotas.label() 函式類似,用於將影像分割成不同的區域。
如果你的標記影像具有非連續的標籤值,labeled.label() 函式會將標籤值更新為連續順序。
例如,假設我們有一個標記影像,其中四個區域的標籤分別為 2、4、7 和 9。labeled.label() 函式會將影像轉換為一個新的標記影像,其連續標籤分別為 1、2、3 和 4。
語法
以下是 mahotas 中 labeled.label() 函式的基本語法:
mahotas.labeled.label(array, Bc={3x3 cross}, output={new array})
其中:
array - 輸入陣列。
Bc (可選) - 用於連通性的結構元素。
output (可選) - 輸出陣列(預設為與 array 形狀相同的新的陣列)。
示例
以下示例演示瞭如何使用 mh.labeled.label() 函式將影像轉換為標記影像。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image_rgb = mh.imread('sea.bmp')
image = image_rgb[:,:,0]
# Applying gaussian filtering
image = mh.gaussian_filter(image, 4)
image = (image > image.mean())
# Converting it to a labeled image
labeled, num_objects = mh.labeled.label(image)
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original RGB image
axes[0].imshow(image_rgb)
axes[0].set_title('RGB Image')
axes[0].set_axis_off()
# Displaying the labeled image
axes[1].imshow(labeled)
axes[1].set_title('Labeled Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
以下是上述程式碼的輸出:
使用自定義結構元素
我們可以使用自定義結構元素和標籤函式根據需要分割影像。結構元素是一個奇數維的二元陣列,由 1 和 0 組成,它定義了影像標記過程中鄰域畫素的連線模式。
1 表示連線分析中包含的相鄰畫素,而 0 表示排除或忽略的鄰居。
例如,讓我們考慮自定義結構元素:[[1, 0, 0], [0, 1, 0], [0, 0, 1]]。 這個結構元素意味著對角線連線。這意味著對於影像中的每個畫素,在標記或分割過程中,只有對角線向上和向下畫素被認為是其鄰居。
示例
在這裡,我們定義了一個自定義結構元素來標記影像。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image_rgb = mh.imread('sea.bmp')
image = image_rgb[:,:,0]
# Applying gaussian filtering
image = mh.gaussian_filter(image, 4)
image = (image > image.mean())
# Creating a custom structuring element
binary_closure = np.array([[0, 1, 0],
[0, 1, 0],
[0, 1, 0]])
# Converting it to a labeled image
labeled, num_objects = mh.labeled.label(image, Bc=binary_closure)
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original RGB image
axes[0].imshow(image_rgb)
axes[0].set_title('RGB Image')
axes[0].set_axis_off()
# Displaying the labeled image
axes[1].imshow(labeled)
axes[1].set_title('Labeled Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figure
mtplt.show()
輸出
執行上述程式碼後,我們將得到以下輸出: