how i can implement these algorithm in matlab
显示 更早的评论
Adaptive median filter changes size of Sxy (the size of the neighborhood) during operation.
- Notation
Zmin = minimum gray level value in Sxy
Zmax = maximum gray level value in Sxy
Zmed = median of gray levels in Sxy
Zxy = gray level at coordinates (x, y)
Smax = maximum allowed size of Sxy
- Algorithm
Level A: A1 = Zmed - Zmin
A2 = Zmed - Zmax
if A1 > 0 AND A2 < 0, go to level B
else increase the window size
if window size < Smax, repeat level A
else output Zxy
Level B: B1 = Zxy - Zmin
B2 = Zxy - Zmax
if B1 > 0 AND B2 < 0, output Zxy
else output Zmed
采纳的回答
Image Analyst
2017-10-13
编辑:Image Analyst
2017-10-13
I use an adaptive median filter to do salt and pepper removal. You can easily adapt it to change the values from 0 and 255 to Zmin and Zmax. Let me know how it goes. Attach your adapted code if you run into problems.
9 个评论
thank you but these code for median filter i need one for adaptive filter i have code but not works
can you see
Oh, you didn't say that at first. But unfortunately, you forgot to attach your m-file and 'shyamgs.bmp'. I'll wait until then, since I can't fix your code unless I have your code.
Also explain what this extra edge processing does. How does that make the image better than a regular modified median filter?
Can you ask the author to add more comments? Like explain why there are weird lines in there like this:
ip_edge(i,j) = ip_edge(i,j);
how i can change the values from 0 and 255 to Zmin and Zmax.
in your cod
i am sorry I do not know how i can do these
Replace this line
% Find the noise. It will have a gray level of either 0 or 255.
noiseImage = (noisyImage == 0 | noisyImage == 255);
with this line:
% Find the noise. It will have a gray level of either less than Zmin or more than Zmax.
noiseImage = (noisyImage <= Zmin | noisyImage >= Zmax);
Again, attach your image and m-file.
Image Analyst
2017-10-13
编辑:Image Analyst
2017-10-13
Exactly what does "code but not works" mean? And I mean EXACTLY.
aliah aljohani
2017-10-13
编辑:aliah aljohani
2017-10-13
i mean these code not work it has some error at for ,if and end and i do not know how i can fixed these error
This gets rid of the error, so that now you can continue to figure out why your code doesn't get rid of salt and pepper noise like my code does.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
grayImage = imread('h1.jpg');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
subplot(2,2,1);
imshow(grayImage)
title('Original image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
drawnow;
% Add noise.
noiseFreeImage = imnoise(grayImage,'salt & pepper',.02);
subplot(2,2,2);
imshow(noiseFreeImage);
title('noisy image', 'FontSize', fontSize);
drawnow;
% Make failed attempt to denoise the image.
Smax = 9;
for col = 1:columns-2
for row = 1:rows-2
n = noiseFreeImage(row:row+2,col:col+2);
Zmin = min(n(:));
Zmax = max(n(:));
Zmed = median(n(:));
sx = 3;
sy = 3;
A1 = Zmed-Zmin;
A2 = Zmed-Zmax;
if (A1>0) && (A2<0)
B1 = Zxy-Zmin;
B2 = Zxy-Zmax;
if (B1>0) && (B2<0)
noiseFreeImage(row:row+2,col:col+2) = n(row, col);
break;
else
noiseFreeImage(row:row+2,col:col+2) = Zmed;
break;
end
else
sx = sx+2;
sy = sy+2;
if (sx > Smax) && (sy > Smax)
noiseFreeImage(row:row+2,col:col+2) = n(row, col);
end
end
end
end
subplot(2,2,3);
imshow(noiseFreeImage)
title('Denoised image', 'FontSize', fontSize);
Yes No errors found in the code Thank you very much for helping me
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Image Filtering 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

