- 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到褐色轉換
- 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 - 二維拉普拉斯濾波器
- 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 - 伽馬校正拉伸
伽馬校正拉伸是指增強影像的整體對比度。這是透過增加伽馬值來實現的,伽馬值增加會擴充套件影像畫素的強度級別範圍。
伽馬校正拉伸的過程涉及將原始輸入值拉伸到新的更寬的取值範圍。
在Mahotas中進行伽馬校正拉伸
在Mahotas中,我們可以使用mahotas.stretch()函式進行影像的伽馬校正拉伸。
在伽馬校正中,大於1的伽馬值會增加影像的對比度,而小於1的伽馬值會降低對比度。
因此,透過拉伸伽馬值,影像的暗區會變得更暗,亮區會變得更亮,從而在不同的色調和細節之間產生更明顯的區別。
使用mahotas.stretch()函式
mahotas.stretch()函式接收影像作為輸入,並返回影像的銳化版本作為輸出。生成的影像具有增強的對比度和改進的細節可見性。
stretch()函式確定影像中的最小和最大強度值,並將它們轉換為全範圍的畫素值(對於8點陣圖像為0-255)。
語法
以下是Mahotas中mh.stretch()函式的基本語法:
mahotas.stretch(img, arg0=None, arg1=None, dtype=<class 'numpy.uint8'>)
其中,
image - 輸入影像。
arg0 (可選) - 輸出的最小值(預設值為0)。
arg1 (可選) - 輸出的最大值(預設值為255)。
dtype (可選) - 輸出影像的資料型別(預設為uint8)。
示例
在下面的示例中,我們使用mh.stretch()函式來增加灰度影像的對比度:
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('sun.png')
# Converting to grayscale
gray_image = mh.colors.rgb2gray(image)
# Decreasing gamma value
corrected_gamma = 3.2
# Applying stretch gamma correction image
stretch_gamma_corrected = mh.stretch(gray_image, corrected_gamma)
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original image
axes[0].imshow(gray_image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying Stretched gamma corrected image
axes[1].imshow(stretch_gamma_corrected, cmap='gray')
axes[1].set_title('Stretched Gamma Corrected Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
以下是上述程式碼的輸出:
RGB影像的伽馬校正拉伸
我們也可以使用stretch()函式在mahotas中對RGB影像執行伽馬校正拉伸。stretch函式中使用的伽馬值決定了對比度增強的程度。
然後,我們可以透過將其乘以255(RGB影像的最大強度)將其拉伸的影像轉換回RGB顏色空間。
示例
以下示例顯示了增加RGB影像對比度的方法:
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('nature.jpeg')
# Applying stretched gamma correction
stretched_gamma_corrected = mh.stretch(image, 3)
# Converting the image back to RGB
stretched_gamma_corrected = stretched_gamma_corrected * 255
# Creating subplots to display images
fig, axes = mtplt.subplots(1, 2)
# Displaying the original RGB image
axes[0].imshow(image)
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying the stretched image
axes[1].imshow(stretched_gamma_corrected)
axes[1].set_title('Stretched Gamma Corrected Image')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()
輸出
上述程式碼的輸出如下:
互動式伽馬校正拉伸滑塊
互動式伽馬校正拉伸滑塊是一個GUI元素,允許使用者透過拖動滑塊來動態調整伽馬值以更改對比度。
- 要在Mahotas中使用互動式滑塊進行伽馬校正拉伸,首先建立一個用於調整伽馬值的滑塊。
- 然後,實現一個函式,在移動滑塊時檢索新的伽馬值並將其應用於影像的伽馬校正拉伸。
- 最後,將函式連線到滑塊的值更改事件,以便在移動滑塊時自動呼叫它。
語法
以下是建立互動式滑塊的基本語法:
from matplotlib.widgets import Slider Slider(slider_axis, name, min_value, max_value, valint)
其中,
slider_axis - 定義滑塊位置和尺寸的列表。
name - 滑塊的名稱。
mini_value - 滑塊可以到達的最小值。
max_value - 滑塊可以到達的最大值。
valint - 滑塊的起始值。
示例
在這個例子中,我們使用互動式滑塊來增加對比度:
import mahotas as mh
import numpy as np
import matplotlib.pyplot as mtplt
from matplotlib.widgets import Slider
# Loading the image
image = mh.imread('tree.tiff')
# Creating a figure and axes for the plot
fig, axis = mtplt.subplots()
# Displaying the original image
axis.imshow(image)
axis.set_title('Stretching Gamma Correction')
axis.set_axis_off()
# Creating a slider for stretched gamma adjustment
slider_axis = mtplt.axes([0.2, 0.05, 0.6, 0.03])
stretched_gamma_slider = Slider(slider_axis, 'Stretched Gamma', 0.1, 5.0,
valinit=1.0)
# Updating the stretched gamma correction and plot on change of slider value
def update_stretched_gamma(val):
stretched_gamma = stretched_gamma_slider.val
corrected_image = mh.stretch(image, stretched_gamma)
corrected_image = corrected_image * 255
axis.imshow(corrected_image)
fig.canvas.draw_idle()
stretched_gamma_slider.on_changed(update_stretched_gamma)
# Showing the figure
mtplt.show()
輸出
生成的輸出如下: