i have to implement Adaptive Center-Weighted Median Filter (ACWM) for removal of RVIN ,but dont know how to do it.details of this filter are as follows:
It devises a novel adaptive operator, which forms estimates based on the differences
between the current pixel and the outputs of center-weighted median
(CWM) filters with varied center weights. It employs the switching scheme
based on the impulse detection mechanisms. It utilizes the center-weighted median
filter that have varied center weights to define a more general operator, which
realizes the impulse detection by using the differences defined between the outputs
of CWM filters and the current pixel of concern. The ultimate output is
switched between the median and the current pixel itself.
Please help me if u can.I will be thankful.....
|
|
0
|
|
|
|
Reply
|
arti
|
1/9/2011 12:46:04 PM |
|
Should be easy to implement with nlfilter(). How can we help? Do you
need to learn the basics such as how to use a "for" loop or or how to
take the median something?
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
1/9/2011 2:42:07 PM
|
|
this is not working whats the problem?
% ACWMF algorithm implementation
I=imread('eight.tif');
function [y, noise_matrix] = acwmf(I);
% Threshold parameters
delta = [40 25 10 5];
x = double(I);
image_size = size(I);
B = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
% Compute filter output
m = medfilt2(x,[3 3],'symmetric');
%Compute differences
d = abs(x-m);
d0 = d(:)';
clear d;
B(10,:) = x(:)';
B(11,:) = x(:)';
m1 = median(B);
d1 = abs(x(:)'-m1);
B(12,:) = x(:)';
B(13,:) = x(:)';
m1=median(B);
d2 = abs(x(:)'-m1);
B(14,:) = x(:)';
B(15,:) = x(:)';
m1=median(B);
d3 = abs(x(:)'-m1);
clear B;
% Compute MAD values
B_x = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
for i = 1:9
B(i,:) = abs(B_x(i,:) - m(:)');
end
MAD = median(B);
clear B;
% Compute threshold values
s = 0.1;
T1 = (MAD * s) + delta(1);
T2 = (MAD * s) + delta(2);
T3 = (MAD * s) + delta(3);
T4 = (MAD * s) + delta(4);
x2 = x(:);
% Detect noisy pixels
F = find((d0>T1)|(d1>T2)|(d2>T3)|(d3>T4));
noise_matrix = zeros(image_size);
noise_matrix(F) = 1;
% Replace noisy pixels
x2(F) = m(F);
clear F m d0 d1 d2 d3 T x;
y = uint8(col2im(x2,[1 1],image_size,'sliding'));
|
|
0
|
|
|
|
Reply
|
arti
|
1/17/2011 3:19:05 PM
|
|
It ran for me with no error messages. What was your problem?
By the way, you don't need a semicolon at the end of this line:
function [y, noise_matrix] = acwmf(I);
and, if you put this all into a single m-file, you'll have to give a
function name for the first part of the code where you read in your
image and call acwmf, like this:
function test_awcmf()
I=imread('eight.tif');
[y, noise_matrix] = acwmf(I)
function [y, noise_matrix] = acwmf(I)
% code for acwmf.....
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
1/17/2011 4:13:13 PM
|
|
after running this code am getting this error:
Too many input arguments.
Error in ==> acwmf at 8
[y, noise_matrix] = acwmf(I);
---------------------------------------------------
function test_awcmf()
I=imread('eight.tif');
[y, noise_matrix] = acwmf(I);
function[y, noise_matrix] = abc(I)
% x1 - input image
function awcmf()
% Threshold parameters
delta = [40 25 10 5];
x = double('eight.tif');
image_size = size('eight.tif');
B = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
% Compute filter output
m = medfilt2(x,[3 3],'symmetric');
%Compute differences
d = abs(x-m);
d0 = d(:)';
clear d;
B(10,:) = x(:)';
B(11,:) = x(:)';
m1 = median(B);
d1 = abs(x(:)'-m1);
B(12,:) = x(:)';
B(13,:) = x(:)';
m1=median(B);
d2 = abs(x(:)'-m1);
B(14,:) = x(:)';
B(15,:) = x(:)';
m1=median(B);
d3 = abs(x(:)'-m1);
clear B;
% Compute MAD values
B_x = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
for i = 1:9
B(i,:) = abs(B_x(i,:) - m(:)');
end
MAD = median(B);
clear B;
% Compute threshold values
s = 0.1;
T1 = (MAD * s) + delta(1);
T2 = (MAD * s) + delta(2);
T3 = (MAD * s) + delta(3);
T4 = (MAD * s) + delta(4);
x2 = x(:);
% Detect noisy pixels
F = find((d0>T1)|(d1>T2)|(d2>T3)|(d3>T4));
noise_matrix = zeros(image_size);
noise_matrix(F) = 1;
% Replace noisy pixels
x2(F) = m(F);
clear F m d0 d1 d2 d3 T x;
y = uint8(col2im(x2,[1 1],image_size,'sliding'));
whats the problem?
|
|
0
|
|
|
|
Reply
|
arti
|
1/21/2011 2:55:24 PM
|
|
On Jan 21, 9:55=A0am, "arti gautam" <arti.gau...@rediffmail.com> wrote:
> after running this code am getting this error:
[snip]
> whats the problem?
------------------------------------------------
Look at these lines in your code:
[y, noise_matrix] =3D acwmf(I);
function[y, noise_matrix] =3D abc(I)
Now, can you tell me why you named your acwmf function "abs" instead
of "acwmf"?
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
1/21/2011 4:19:01 PM
|
|
its by mistake ,actually function name is acwmf,but still I am getting the same error....
|
|
0
|
|
|
|
Reply
|
arti
|
1/22/2011 10:28:07 AM
|
|
On Jan 22, 5:28=A0am, "arti gautam" <arti.gau...@rediffmail.com> wrote:
> its by mistake ,actually function name is acwmf,but still =A0I am getting=
the same error....
------------------------------------------------------
arti:
Look again at your code:
function test_awcmf()
I=3Dimread('eight.tif');
[y, noise_matrix] =3D acwmf(I);
function[y, noise_matrix] =3D abc(I)
% x1 - input image
function awcmf()
Notice, there are three function definitions. OK, maybe "abc" was
supposed to be "awcmf", but then you still have the third function
definition of awcmf() that does not take an argument at all. Yet,
this is how you're calling it:
[y, noise_matrix] =3D acwmf(I); % Note input parameter of "I"
Not only that, but the awcmf() that you did define actually reads in
its *own* image rather than taking one from the calling routine via
the arg list.
Then you do nonsense like this:
x =3D double('eight.tif');
I presume you want x to be the image array corresponding to the
standard demo image file "eight.tif" - well that won't do it since
you're merely converting a string literal into a double array.
Please get rid of function statements you don't need, and make sure
that the input and output arguments match what you're calling it
with. Now look at the line:
image_size =3D size('eight.tif');
This won't get you the size of the image, it will give you [1 9] which
is the size of that character array.
Try this corrected code. I have no idea if you implemented the
algorithm correctly, but at least it runs and produces a couple of
images.
% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.
function test_awcmf()
grayImage=3Dimread('eight.tif');
[y, noise_matrix] =3D acwmf(grayImage);
subplot(2,2,1);
imshow(grayImage, []);
title('Original Image', 'FontSize', 20);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
subplot(2,2,2);
imshow(y, []);
title('y', 'FontSize', 20);
subplot(2,2,3);
imshow(noise_matrix, []);
title('noise matrix', 'FontSize', 20);
%----------------------------------------------------------
function[y, noise_matrix] =3D acwmf(x)
% Threshold parameters
delta =3D [40 25 10 5];
image_size =3D size(x);
B =3D im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
% Compute filter output
m =3D medfilt2(x,[3 3],'symmetric');
%Compute differences
d =3D abs(x-m);
d0 =3D d(:)';
clear d;
B(10,:) =3D x(:)';
B(11,:) =3D x(:)';
m1 =3D median(B);
d1 =3D abs(x(:)'-m1);
B(12,:) =3D x(:)';
B(13,:) =3D x(:)';
m1=3Dmedian(B);
d2 =3D abs(x(:)'-m1);
B(14,:) =3D x(:)';
B(15,:) =3D x(:)';
m1=3Dmedian(B);
d3 =3D abs(x(:)'-m1);
clear B;
% Compute MAD values
B_x =3D im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
for i =3D 1:9
B(i,:) =3D abs(B_x(i,:) - m(:)');
end
MAD =3D median(B);
clear B;
% Compute threshold values
s =3D 0.1;
T1 =3D (MAD * s) + delta(1);
T2 =3D (MAD * s) + delta(2);
T3 =3D (MAD * s) + delta(3);
T4 =3D (MAD * s) + delta(4);
x2 =3D x(:);
% Detect noisy pixels
F =3D find((d0>T1)|(d1>T2)|(d2>T3)|(d3>T4));
noise_matrix =3D zeros(image_size);
noise_matrix(F) =3D 1;
% Replace noisy pixels
x2(F) =3D m(F);
clear F m d0 d1 d2 d3 T x;
y =3D uint8(col2im(x2,[1 1],image_size,'sliding'));
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
1/22/2011 2:09:31 PM
|
|
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <df78d4db-3961-4883-afd9-8a77cb42a2c5@m13g2000yqb.googlegroups.com>...
> On Jan 22, 5:28 am, "arti gautam" <arti.gau...@rediffmail.com> wrote:
> > its by mistake ,actually function name is acwmf,but still I am getting the same error....
>
> ------------------------------------------------------
> arti:
> Look again at your code:
> function test_awcmf()
> I=imread('eight.tif');
> [y, noise_matrix] = acwmf(I);
>
> function[y, noise_matrix] = abc(I)
> % x1 - input image
> function awcmf()
>
> Notice, there are three function definitions. OK, maybe "abc" was
> supposed to be "awcmf", but then you still have the third function
> definition of awcmf() that does not take an argument at all. Yet,
> this is how you're calling it:
> [y, noise_matrix] = acwmf(I); % Note input parameter of "I"
> Not only that, but the awcmf() that you did define actually reads in
> its *own* image rather than taking one from the calling routine via
> the arg list.
> Then you do nonsense like this:
> x = double('eight.tif');
> I presume you want x to be the image array corresponding to the
> standard demo image file "eight.tif" - well that won't do it since
> you're merely converting a string literal into a double array.
> Please get rid of function statements you don't need, and make sure
> that the input and output arguments match what you're calling it
> with. Now look at the line:
> image_size = size('eight.tif');
> This won't get you the size of the image, it will give you [1 9] which
> is the size of that character array.
>
> Try this corrected code. I have no idea if you implemented the
> algorithm correctly, but at least it runs and produces a couple of
> images.
>
> % IMPORTANT: The newsreader may break long lines into multiple lines.
> % Be sure to join any long lines that got split into multiple single
> lines.
> % These can be found by the red lines on the left side of your
> % text editor, which indicate syntax errors, or else just run the
> % code and it will stop at the split lines with an error.
>
> function test_awcmf()
> grayImage=imread('eight.tif');
> [y, noise_matrix] = acwmf(grayImage);
> subplot(2,2,1);
> imshow(grayImage, []);
> title('Original Image', 'FontSize', 20);
> % Enlarge figure to full screen.
> set(gcf, 'Position', get(0,'Screensize'));
> subplot(2,2,2);
> imshow(y, []);
> title('y', 'FontSize', 20);
> subplot(2,2,3);
> imshow(noise_matrix, []);
> title('noise matrix', 'FontSize', 20);
>
> %----------------------------------------------------------
> function[y, noise_matrix] = acwmf(x)
> % Threshold parameters
> delta = [40 25 10 5];
>
> image_size = size(x);
> B = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
>
> % Compute filter output
> m = medfilt2(x,[3 3],'symmetric');
>
> %Compute differences
> d = abs(x-m);
> d0 = d(:)';
> clear d;
> B(10,:) = x(:)';
> B(11,:) = x(:)';
> m1 = median(B);
> d1 = abs(x(:)'-m1);
> B(12,:) = x(:)';
> B(13,:) = x(:)';
> m1=median(B);
> d2 = abs(x(:)'-m1);
> B(14,:) = x(:)';
> B(15,:) = x(:)';
> m1=median(B);
> d3 = abs(x(:)'-m1);
> clear B;
>
> % Compute MAD values
> B_x = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
>
> for i = 1:9
> B(i,:) = abs(B_x(i,:) - m(:)');
> end
> MAD = median(B);
>
> clear B;
>
> % Compute threshold values
> s = 0.1;
> T1 = (MAD * s) + delta(1);
> T2 = (MAD * s) + delta(2);
> T3 = (MAD * s) + delta(3);
> T4 = (MAD * s) + delta(4);
>
> x2 = x(:);
>
> % Detect noisy pixels
> F = find((d0>T1)|(d1>T2)|(d2>T3)|(d3>T4));
>
> noise_matrix = zeros(image_size);
> noise_matrix(F) = 1;
>
> % Replace noisy pixels
> x2(F) = m(F);
> clear F m d0 d1 d2 d3 T x;
> y = uint8(col2im(x2,[1 1],image_size,'sliding'));
|
|
0
|
|
|
|
Reply
|
arti
|
1/25/2011 3:17:02 PM
|
|
Thanks sir.Now I have to calculate PSNR for this filter,I have done some modifications in this code but after running got this error:
Undefined function or variable 'rows'.
Error in ==> im1 at 29
mse = sum(sum(mseImage)) / (rows * columns);
--------------------------------------------------------------------------------------
function test_awcmf()
grayImage=imread('eight.tif');
[y, noisyImage] = acwmf(grayImage);
subplot(2,3,1);
imshow(grayImage, []);
title('Original Image', 'FontSize', 20);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
noisyImage=imnoise(grayImage,'salt & pepper',0.10);
subplot(2,3,2);
imshow(noisyImage, []);
title('noisyImage', 'FontSize', 20);
% subplot(2,3,3);
% imshow(y, []);
% title('filtered Image', 'FontSize', 20);
mseImage = (double(grayImage) - double(noisyImage)) .^ 2;
subplot(2, 3, 3);
imshow(mseImage, []);
title('MSE Image before filtering');
mse = sum(sum(mseImage)) / (rows * columns);
PSNR = 10 * log10( 256^2 / mse);
message = sprintf('The mean square error is %.2f \nThe PSNR = %.2f',mse, PSNR);
msgbox(message);
subplot(2,3,4);
imshow(y, []);
title('filtered Image', 'FontSize', 20);
MSEImage = (double(grayImage) - double(y)) .^ 2;
subplot(2,3,5 );
imshow(MSEImage, []);
title('MSE Image after filtering');
mse = sum(sum(MSEImage)) / (rows * columns);
PSNR = 10 * log10( 256^2 / mse);
message = sprintf('The mean square error after filtering is %.2f \nThe PSNR = %.2f',mse, PSNR);
msgbox(message);
%----------------------------------------------------------
function[y, noisyImage] = acwmf(x)
% Threshold parameters
delta = [40 25 10 5];
image_size = size(x);
B = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
% Compute filter output
m = medfilt2(x,[3 3],'symmetric');
%Compute differences
d = abs(x-m);
d0 = d(:)';
clear d;
B(10,:) = x(:)';
B(11,:) = x(:)';
m1 = median(B);
d1 = abs(x(:)'-m1);
B(12,:) = x(:)';
B(13,:) = x(:)';
m1=median(B);
d2 = abs(x(:)'-m1);
B(14,:) = x(:)';
B(15,:) = x(:)';
m1=median(B);
d3 = abs(x(:)'-m1);
clear B;
% Compute MAD values
B_x = im2col(padarray(x,[1 1],'symmetric','both'),[3 3],'sliding');
for i = 1:9
B(i,:) = abs(B_x(i,:) - m(:)');
end
MAD = median(B);
clear B;
% Compute threshold values
s = 0.1;
T1 = (MAD * s) + delta(1);
T2 = (MAD * s) + delta(2);
T3 = (MAD * s) + delta(3);
T4 = (MAD * s) + delta(4);
x2 = x(:);
% Detect noisy pixels
F = find((d0>T1)|(d1>T2)|(d2>T3)|(d3>T4));
noisyImage = zeros(image_size);
noisyImage(F) = 1;
% Replace noisy pixels
x2(F) = m(F);
clear F m d0 d1 d2 d3 T x;
y = uint8(col2im(x2,[1 1],image_size,'sliding'));
|
|
0
|
|
|
|
Reply
|
arti
|
1/25/2011 3:21:03 PM
|
|
i want to know the source of adaptive center weighted median filter to make in my reference. please help me
|
|
0
|
|
|
|
Reply
|
viraj_2k (1)
|
11/29/2011 5:31:08 AM
|
|
|
10 Replies
570 Views
(page loaded in 0.273 seconds)
|