- 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 - Hit & Miss 變換
- Mahotas - 標記最大值陣列
- Mahotas - 影像平均值
- Mahotas - SURF 密集點
- Mahotas - SURF 積分影像
- Mahotas - Haar 變換
- 突出影像最大值
- 計算線性二值模式
- 獲取標籤邊界
- 反轉 Haar 變換
- Riddler-Calvard 方法
- 標記區域的大小
- Mahotas - 模板匹配
- 加速魯棒特徵
- 移除邊界標記
- Mahotas - Daubechies 小波
- Mahotas - Sobel 邊緣檢測
Mahotas - Riddler-Calvard 方法
Riddler-Calvard 方法是一種用於將影像分割為前景和背景區域的技術。它對影像畫素進行分組,以在計算閾值時最小化組內方差。
組內方差衡量的是畫素值在一個組內的分散程度。組內方差低表示畫素值彼此接近,而組內方差高表示畫素值分散。
Mahotas 中的 Riddler-Calvard 方法
在 Mahotas 中,我們使用 `thresholding.rc()` 函式使用 Riddler-Calvard 技術計算影像的閾值。該函式的工作方式如下:
它計算兩個叢集(前景和背景)的均值和方差。均值是所有畫素的平均值,方差是畫素分散程度的度量。
接下來,它選擇一個最小化組內方差的閾值。
然後,它將每個畫素分配給方差較小的叢集。
步驟 2 和 3 連續重複,直到計算出閾值。然後使用此值將影像分割為前景和背景。
`mahotas.thresholding.rc()` 函式
`mahotas.thresholding.rc()` 函式以灰度影像作為輸入,並返回使用 Riddler-Calvard 技術計算的閾值。
然後將灰度影像的畫素與閾值進行比較,以建立二值影像。
語法
以下是 Mahotas 中 `rc()` 函式的基本語法:
mahotas.thresholding.rc(img, ignore_zeros=False)
其中:
`img` - 輸入灰度影像。
`ignore_zeros (可選)` - 一個標誌,指定是否忽略零值畫素(預設為 false)。
示例
在下面的示例中,我們使用 `mh.thresholding.rc()` 函式查詢閾值。
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 = mh.colors.rgb2gray(image).astype(np.uint8)
# Calculating threshold value using Riddler-Calvard method
rc_threshold = mh.thresholding.rc(image)
# Creating image from the threshold value
final_image = image > rc_threshold
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original image
axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying the threshold image
axes[1].imshow(final_image, cmap='gray')
axes[1].set_title('Riddler-Calvard Threshold Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
以下是上述程式碼的輸出:
忽略零值畫素
我們還可以透過忽略零值畫素來找到 Riddler-Calvard 閾值。零值畫素是指強度值為 0 的畫素。
它們通常代表影像的背景畫素,但在某些影像中,它們也可能代表噪聲。
在灰度影像中,零值畫素由顏色“黑色”表示。
為了在 Mahotas 中計算閾值時排除零值畫素,我們可以將 `ignore_zeros` 引數設定為布林值“True”。
示例
在下面提到的示例中,我們在使用 Riddler-Calvard 方法計算閾值時忽略值為零的畫素。
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('nature.jpeg')
# Converting it to grayscale
image = mh.colors.rgb2gray(image).astype(np.uint8)
# Calculating threshold value using Riddler-Calvard method
rc_threshold = mh.thresholding.rc(image, ignore_zeros=True)
# Creating image from the threshold value
final_image = image > rc_threshold
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original image
axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying the threshold image
axes[1].imshow(final_image, cmap='gray')
axes[1].set_title('Riddler-Calvard Threshold Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
執行上述程式碼後,我們將得到以下輸出: