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
답변 (1개)
Vidhi Agarwal
2025년 6월 9일
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!
카테고리
도움말 센터 및 File Exchange에서 Image Category Classification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!