Noise removal using filters

I have to remove the noise using Component median filtering and vector median filtering ,can any one tell wehere i can get codes please

Réponses (1)

Vidhi Agarwal
Vidhi Agarwal le 9 Juin 2025

0 votes

Hi @FIR,
Component Median Filter applies the median filter independently to each color channel (R, G, B), and Vector Median Filter Considers each pixel as a vector (R,G,B) and selects the pixel in the window with the minimum total distance (usually Euclidean distance) to all others.
Sample code for component median filter is given below:
function output = componentMedianFilter(I, windowSize)
% I: RGB image
% windowSize: odd integer (e.g., 3)
output = zeros(size(I));
for c = 1:3 % R, G, B
output(:,:,c) = medfilt2(I(:,:,c), [windowSize windowSize]);
end
output = uint8(output);
end
following is the sample code for Vector Median filter:
function output = vectorMedianFilter(I, windowSize)
% I: RGB image
% windowSize: odd integer (e.g., 3)
[rows, cols, ~] = size(I);
pad = floor(windowSize / 2);
paddedI = padarray(double(I), [pad pad], 'symmetric');
output = zeros(size(I));
for i = 1:rows
for j = 1:cols
% Extract window
window = paddedI(i:i+2*pad, j:j+2*pad, :);
% Reshape to Nx3 matrix (N = windowSize^2)
vectors = reshape(window, [], 3);
% Compute pairwise L2 distances
D = pdist2(vectors, vectors);
totalDist = sum(D, 2);
% Find vector with minimal total distance
[~, idx] = min(totalDist);
output(i, j, :) = vectors(idx, :);
end
end
output = uint8(output);
end
To understand to more about "medfilt2" refer to the following documentation: https://www.mathworks.com/help/images/ref/medfilt2.html
Hope this helps!

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by