MATLAB中的平衡對比增強技術


在數字影像處理中,對比度增強是一種用於提高影像視覺質量的關鍵技術。對比度增強技術調整畫素的強度,以增加亮度級別的範圍,並突出影像中明亮和黑暗區域之間的差異。

MATLAB 提供多種對比度增強技術,但在本文中,我們將重點關注平衡對比度增強技術,並瞭解其在 MATLAB 程式設計中的實現。

什麼是平衡對比度增強?

在 MATLAB 中,平衡對比度增強技術是一種改進數字影像對比度比的現代方法。此技術同時增強區域性和全域性對比度,從而達到平衡。因此,此技術可提供高視覺質量和改進的可解釋性。

平衡對比度增強技術基於以下所示的拋物線函式

y = a * (x - b).^2 + c

其中,y 是輸出影像,x 是輸入影像,a、b 和 c 是三個係數,分別由“輸出影像的最小強度值”、“輸出影像的最大強度值”和“輸出影像的平均值”匯出。

下面的 MATLAB 程式展示了在 MATLAB 中實現“平衡對比度增強”技術。

示例

% MATLAB program to demonstrate the balance contrast enhancement technique.
% Read the input image that has to be enhanced
img = imread('https://tutorialspoint.tw/assets/questions/media/14304-1687425236.jpg');
% Display the original input image
figure, subplot(1, 2, 1), imshow(img); title('Original Image');
% Convert the input image from 8-bit unsigned integer format to double format for processing
img1 = double(img);
% Calculate different statistics of the input image
Imin = min(img1(:)); 		% Minimum intensity value of input image
Imax = max(img1(:));		% Maximum intensity value of input image
Imean = mean(img1(:));		% Mean intensity value of input image
Imssum = mean(img1(:).^2);	% Mean square sum of intensity value of input image
% Define the desired characteristics of the output image
Omin = 0; % Minimum intensity value of output image
Omax = 255; % Maximum intensity value of output image
Omean = 120; % Mean intensity value of output image
% Calculate the numerator and denominator to compute the coefficient “b”
bnum = Imax.^2 * (Omean - Omin) - Imssum * (Omax - Omin) + Imin.^2 * (Omax - Omean);
bden = 2 * (Imax * (Omean - Omin) - Imean * (Omax - Omin) + Imin * (Omax - Omean));
% Compute the value of the coefficient “b”
b = bnum/bden;
% Calculate the coefficient “a” of the parabolic function
a = (Omax - Omin)/((Imax - Imin) * (Imax + Imin - 2 * b));
% Calculate the coefficient “c” of the parabolic function
c = Omin - a * (Imin - b).^2;
% Apply the parabolic function to the input image “img1” to obtain the output image “img2”
img2 = a * (img1 - b).^2 + c;
% convert the output image back to the 8-bit unsigned integer format
img2 = uint8(img2);
% Display the enhanced image with a title Enhanced Image
subplot(1,2, 2), imshow(img2); title('Enhanced Image');

輸出

結論

在這個 MATLAB 程式中,我們首先使用“imread”函式輸入影像並將其儲存在變數“img”中。接下來,我們呼叫“figure”、“subplot”和“imshow”函式以顯示標題為“原始影像”的原始輸入影像。

之後,我們將輸入影像從 8 位無符號整數格式轉換為浮點格式以允許分數計算,並將此轉換後的影像儲存在新變數“img1”中。然後,我們計算輸入影像的不同特徵,例如最小強度 (Imin)、最大強度 (Imax)、平均強度 (Imean) 和強度的均方和 (Imssum)。

接下來,我們指定輸出影像的不同特徵,例如最小強度 (Omin)、最大強度 (Omax) 和平均強度 (Omean)。然後,我們計算拋物線函式的分子 (bnum)、分母 (bden) 和係數 b。

之後,我們計算拋物線函式的係數“a”和“c”的值。然後,我們將引數“a”、“b”、“c”、“img1”的值代入拋物線函式,以從輸入影像“img1”獲得輸出影像“img2”。

最後,我們使用“subplot”、“imshow”函式顯示增強的輸出影像,標題為“增強影像”。

這就是我們在 MATLAB 中實現影像平衡對比度增強技術的方法。

更新於:2023年7月18日

瀏覽量:137

開啟您的職業生涯

完成課程獲得認證

開始學習
廣告