medfilt2 filter expects input to be two-dimensional
我想将过滤器
您的图像很可能是带有 RGB 帧的彩色图像。
参见示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 | % load an image img = imread('peppers.png'); % add some noise img_noisy = imnoise(img, 'salt & pepper', 0.02); figure; imshow(img_noisy); % apply medfilt2 on each color img_filtered = img_noisy; for c = 1 : 3 img_filtered(:, :, c) = medfilt2(img_noisy(:, :, c), [3, 3]); end figure; imshow(img_filtered); |
看起来像:
尝试将 rgb 转换为灰色 (
1 2 3 4 | img = imread('4.02.04_salt&pepper.tif'); img = rgb2gray(img); % add this line blur = medfilt2(img); imshow(blur); |