Matlab alpha trimmed filter

I am implementing this but i am getting the result full blank help me with this I have to create the filter manually and apply using for loop I am only allowed to use sort function I am not allowed to use the build in functions I have attached the picture please help me with this Pic :

4 Comments

Rashid - please post the code that you have written so that we can better understand where the problem exists.
d1=8;
d2=8;
n=5;
I = imread('pout.tif');
I = double(I(:,:,1))/255;
% images, 1. whitenoise, 2. salt&pepper, 3. white and s&p.
img = imnoise(I,'gaussian',0,0.005);
if (isa(img,'uint8'))
% force img to be bouble between 0.0 .. 1.0
img=double(img)/255;
else
% assume img is double in range 0..1
end
% create a blank array for output
img_alpha = zeros(size(img));
% --- YOUR CODE TO GO HERE ---
% NOTE: your solution does NOT have to deal with values near the image boundary
for r=1:size(img,1)
for c=1:size(img,2)
if r-n < 1 | n+r >= size(I,1) | c-n < 1 | c+n > size(I,2)
img_alpha(r,c)=img(r,c);
else
fromrow=abs(r-n);
torow=r+n;
fromcol=abs(c-n);
tocol=c+n;
neig=img(fromrow:torow,fromcol:tocol);
localval=neig(:);
s=sort(localval);
sumofval=0;
for i=d1+1:size(s,1)-d2
sumofval=sumofval+s(i);
end
avg=(1/(n*n)-(d1+d2))*sumval;
img_alpha(r,c)=avg;
end
end
end
imshow(img_alpha);
Rashid Hussain
Rashid Hussain on 14 Aug 2016
Edited: Image Analyst on 14 Aug 2016
Please tell me whether I am doing right or wrong.
I am not allowed to use built-in functions, and you can see the pictures for problem description. Thanks

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Aug 2016
sumval is a different variable than sumofval. Try using sumofval instead, and then the code will not throw an error.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 13 Aug 2016

Answered:

on 14 Aug 2016

Community Treasure Hunt

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

Start Hunting!