使用MATLAB估計噪聲影像中的高斯噪聲


在數字影像中,高斯噪聲是一種服從正態分佈或高斯分佈的噪聲。在數字影像中,高斯噪聲表現為畫素強度值的隨機變化。高斯噪聲的估計是數字影像處理中一項重要的任務,用於執行去噪、影像恢復等各種操作。

數字影像中高斯噪聲的估計方法

我們可以使用多種方法來估計數字影像中的高斯噪聲。以下是幾種常用的高斯噪聲估計方法。

  • 標準差法

  • 直方圖分析法

讓我們透過示例詳細討論這兩種方法。

使用標準差法估計高斯噪聲

在數字影像處理中,標準差法是估計高斯噪聲最簡單的方法。它透過查詢畫素強度值的標準差來估計影像中的高斯噪聲。

下面解釋了使用標準差法估計數字影像中高斯噪聲的分步過程。

  • 步驟(1) - 讀取包含高斯噪聲的輸入影像。

  • 步驟(2) - 根據需要將影像轉換為灰度影像。

  • 步驟(3) - 將影像轉換為雙精度資料型別以進行計算。

  • 步驟(4) - 透過計算影像畫素強度的標準差來估計高斯噪聲。

  • 步驟(5) - 顯示估計的高斯噪聲。

  • 步驟(6) - 顯示噪聲影像和去噪影像,以便進行視覺分析。

在MATLAB中,透過標準差法估計高斯噪聲是一個六步的簡單方法。

示例

讓我們舉個例子來了解使用MATLAB估計高斯噪聲的程式碼實現。

% MATLAB code to estimate gaussian noise using standard deviation method
% Read the noisy image
noisy_img = imread('Noisy_Image.jpg');

%Convert the input noisy image to grayscale
gray_img = rgb2gray(noisy_img);

% Convert the gray image to double data type
gray_img = im2double(gray_img);

% Estimate the Gaussian noise using standard deviation
estimated_noise = std2(gray_img);

% Display the estimated gaussian noise in the image
disp(['Estimated Gaussian Noise in the Image is: ' num2str(estimated_noise)]);

% Remove the noise from the image
denoised_img = imgaussfilt(gray_img, 2);

% Display the noisy and denoised images
figure;
subplot(1, 2, 1);
imshow(gray_img);
title('Noisy Image');

subplot(1, 2, 2);
imshow(denoised_img);
title('Denoised Image');

輸出

Estimated Gaussian Noise in the Image is: 0.25054

解釋

在這個MATLAB示例中,我們使用標準差法估計了影像中的高斯噪聲。

  • 在程式碼中,我們首先使用“imread”函式讀取噪聲影像。然後,我們分別使用“rgb2gray”和“im2double”函式將輸入影像轉換為灰度影像和雙精度資料型別以進行計算。

  • 之後,我們使用“std2”函式估計影像中的高斯噪聲。此函式計算噪聲影像的畫素強度值的標準差。

  • 接下來,我們使用“disp”函式顯示影像中估計的高斯噪聲。

  • 在下一步中,我們還使用高斯濾波器去除高斯噪聲,並顯示噪聲影像和去噪影像以進行視覺比較。

這就是我們如何在MATLAB中使用標準差法估計高斯噪聲的方法。

使用直方圖分析法估計高斯噪聲

在MATLAB中,我們可以透過分析影像的直方圖來估計數字影像中的高斯噪聲。在這種方法中,我們分析影像中畫素強度值的分佈。然後,我們可以使用這些估計值來對影像進行去噪。

下面解釋了使用直方圖分析法估計影像中高斯噪聲的步驟。

  • 步驟(1) - 使用“imread”函式讀取噪聲影像。

  • 步驟(2) - 將輸入影像轉換為灰度影像以進行直方圖分析。

  • 步驟(3) - 計算並顯示影像的直方圖。

  • 步驟(4) - 擬合噪聲影像的高斯分佈。

  • 步驟(5) - 確定噪聲影像擬合高斯分佈的均值和標準差。

  • 步驟(6) - 顯示估計的高斯噪聲,即噪聲影像的均值和標準差。

  • 步驟(7) - 對影像進行去噪。

  • 步驟(8) - 顯示噪聲影像和去噪影像以進行視覺比較。

示例

讓我們舉個例子來了解這些步驟在估計影像中高斯噪聲時的實現。

% MATLAB code to estimate gaussian noise using histogram analysis
% Read the noisy image
noisy_img = imread('noisy_image.jpg');

% Convert to the noisy image to grayscale
gray_img = rgb2gray(noisy_img);

% Compute the histogram of the noisy image
[counts, binLocations] = imhist(gray_img);

% Display the histogram of noisy image
figure;
bar(binLocations, counts);
title('Histogram of Noisy Image');
xlabel('Pixel Intensity');
ylabel('Frequency');

% Fit gaussian distribution to pixel intensity values
g = fitdist(gray_img(:), 'Normal');

% Estimate the mean value and standard deviation
mean_value = g.mu;
std_dev = g.sigma;

% Display estimated gaussian noise parameters
fprintf('Estimated Mean Value: %.2f
', mean_value); fprintf('Estimated Standard Deviation: %.2f
', std_dev); % Denoise the image using the gaussian filter denoised_img = imgaussfilt(gray_img, 1.5); % Display the noisy and denoised images figure; subplot(1, 2, 1); imshow(noisy_img); title('Noisy Image'); subplot(1, 2, 2); imshow(denoised_img, []); title('Denoised Image');

輸出

執行此程式碼後,將產生以下輸出-

直方圖 -

噪聲引數 -

Estimated Mean Value: 187.94
Estimated Standard Deviation: 12.03

噪聲影像和去噪影像 -

此示例演示了使用直方圖分析法逐步驟估計影像中高斯噪聲的過程。

結論

這就是關於使用MATLAB估計噪聲影像中高斯噪聲的所有內容。高斯噪聲的估計是數字影像處理中的一項關鍵任務。它有助於對噪聲影像進行去噪。MATLAB提供了多種方法來估計噪聲影像中的高斯噪聲。但最常用的方法是標準差法和直方圖分析法。在本教程中,我透過MATLAB程式設計示例詳細解釋了這兩種方法。

更新於:2023年10月5日

瀏覽量:244

啟動您的職業生涯

透過完成課程獲得認證

開始學習
廣告