使用MATLAB進行數字影像處理中的去噪技術


在數字影像處理中,去噪是一個減少或去除數字影像中不需要的噪聲的過程。此過程的主要目標是增強影像的視覺質量。

在討論數字影像處理中不同的去噪技術之前,讓我們首先概述去噪的基礎知識。

什麼是數字影像處理中的去噪?

在數字影像中,任何不需要的變異都被稱為噪聲。數字影像中的噪聲可能由於不同的原因產生,例如環境條件、硬體故障、傳輸錯誤等。從影像中去除這種不需要的噪聲的過程稱為**去噪**。

  • 去噪主要用於提高數字影像的視覺質量。去噪使數字影像能夠準備進行分析和顯示。

  • 有效的去噪技術是在減少不需要的噪聲的同時保留影像所有重要特徵的技術。

  • 在數字影像中,可能存在不同型別的噪聲,例如高斯噪聲、椒鹽噪聲、斑點噪聲等。為了去除特定型別的噪聲,使用特定的去噪技術。

現在讓我們討論使用MATLAB進行數字影像處理的不同型別的去噪技術。

使用MATLAB進行數字影像處理中的去噪技術

MATLAB提供各種型別的去噪技術來去除或減少數字影像中不需要的噪聲。下面將透過MATLAB中的示例解釋一些常用的數字影像處理去噪技術。

使用中值濾波器去噪

中值濾波器被認為是數字影像處理中最簡單的去噪技術。此技術用於減少或去除數字影像中的椒鹽噪聲。

在MATLAB中,使用“medfilt2()”函式將中值濾波器應用於影像。

語法

denoised_img = medfilt2(noisy_img, filter_size);

下面解釋了使用中值濾波器對影像進行去噪的分步過程。

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

  • **步驟(2)** - 使用“rgb2gray”函式將輸入的噪聲影像轉換為灰度影像。

  • **步驟(3)** - 使用“medfilt2()”函式透過中值濾波器進行去噪。

  • **步驟(4)** - 使用“imshow”函式顯示去噪後的影像。

示例

讓我們來看一個示例,以瞭解這些步驟在MATLAB中的實現 -

% MATLAB code to perform denoising using median filter
% Read the noisy image
noisy_img = imread('noisy_image.jpg');	% Replace the URL with noisy image

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

% Perform denoising using the median filter
denoised_img = medfilt2(gray_img, [3, 3]);

% 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');

輸出

執行此程式碼時,它將產生以下**輸出** -

使用高斯濾波器去噪

在數字影像處理中,高斯濾波是另一種常用的去噪技術。此去噪技術用於去除數字影像中的高斯噪聲。

要將高斯濾波器應用於數字影像,我們在MATLAB中使用“imgaussfilt”函式。

語法

denoised_img = imgaussfilt(noisy_img, standard_deviation);

在MATLAB中使用高斯濾波器對影像進行去噪涉及以下步驟。

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

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

  • **步驟(3)** - 使用高斯濾波器進行去噪。

  • **步驟(4)** - 使用“imshow”函式顯示去噪後的影像。

示例

讓我們在MATLAB中舉一個例子來理解使用高斯濾波器進行去噪 -

% MATLAB code to perform denoising using Gaussian filter
% Read the noisy image
noisy_img = imread('noisy_image.jpg');	% Replace the URL with noisy image

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

% Perform denoising using the median filter
sigma = 2;	% Adjust standard deviation as per noise characteristics
denoised_img = imgaussfilt(gray_img, sigma);

% 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');

輸出

執行此程式碼時,它將產生以下**輸出** -

使用維納濾波器去噪

在數字影像處理中,還有一種名為“維納濾波器”的去噪技術,用於去除影像中的噪聲。這是一種基於反捲積的去噪技術。

在MATLAB中,有一個內建函式“wiener2”,用於透過維納濾波進行去噪。

語法

denoised_img = wiener2(noisy_img, filterSize);

透過維納濾波器進行去噪的步驟與上述技術相同。

示例

這是一個使用MATLAB中的維納濾波器演示去噪的示例 -

% MATLAB code to perform denoising using Wiener filter
% Read the noisy image
noisy_img = imread('noisy_image.jpg');

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

% Perform denoising using the Wiener filter
denoised_img = wiener2(gray_img, [5, 5]);

% 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');

輸出

執行此程式碼時,它將產生以下**輸出** -

非區域性均值 (NLM) 去噪技術

在數字影像處理中,有一種名為非區域性均值 (NLM) 的去噪技術,用於去除影像中不需要的噪聲。這種去噪技術在保留影像細節的同時有效地減少影像中的不需要的噪聲。

在MATLAB中,我們可以透過使用“imnlmfilt”函式透過NLM技術進行去噪。

語法

denoised_img = imnlmfilt(noisy_img, 'DegreeOfSmoothing', value, 'SearchWindowSize', WindowSize);

這裡,引數“DegreeOfSmoothing”控制降噪過程中的平滑程度,引數“SearchWindowSize”指定濾波器視窗的大小。

示例

這是一個顯示透過非區域性均值去噪技術進行去噪所涉及步驟的示例。

% MATLAB code to perform denoising using NLM technique
% Read the noisy image
noisy_img = imread('Noisy_Image.jpg');

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

% Perform denoising using Non-Local Means (NLM)
denoised_img = imnlmfilt(gray_img, 'DegreeOfSmoothing', 30, 'SearchWindowSize', 11);

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

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

輸出

執行此程式碼時,它將產生以下**輸出** -

結論

總之,去噪意味著去除數字影像中不需要的內容。在MATLAB中,我們有不同型別的去噪技術。在本教程中,我透過示例解釋了使用MATLAB進行數字影像處理中所有常用的去噪技術。

更新於:2023年10月5日

322 次瀏覽

啟動您的職業生涯

透過完成課程獲得認證

開始學習
廣告