1 Replies - 11780 Views - Last Post: 12 August 2012 - 10:07 AM Rate Topic: -----

#1 bakalaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-August 12

Average filter in Matlab

Posted 10 August 2012 - 12:08 PM

Hi everyone.
I'm trying to split a greyscale image (that has 'Salt and pepper noise') into 3x3 blocks, then take the average of each block
and scale the original image with its respective block. The result should remove most of the noise and smoothen the image.

For now this is just testing a single block on the image. The average is too large, so all pixels turn white.
I do not know how to apply this average in the correct way. Any ideas would be greatly appreciated.

A = imread("noisypeppers.tif");
[r,c] = size(A);

n = 3;
M = zeros(n,n);
m = [];

for i = 1:n
	for j = 1:n
		m = [m;A(i,j)];
	end
end
m = sum(m)/n*n;
M(:,:)/> = m;

for i = 1:n
	for j = 1:n
		A(i,j) = M(i,j)*A(i,j);
	end
end

imshow(A)



Is This A Good Question/Topic? 0
  • +

Replies To: Average filter in Matlab

#2 mufasa  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 12-February 10

Re: Average filter in Matlab

Posted 12 August 2012 - 10:07 AM

If you want to use a filter to remove some noise form an image Matlab already has a lot of these functions built in. For a mean filter (what it sounds like you're looking for) you can just do the following:

A=imread("noisypeppers.tif");
meanFilter = fspecial('average', [3 3]);
toShow = imfilter(A, meanFilter);
imshow(toShow);



Is that somewhat what you were looking for? You can check out this link for other filters: filters.

Hope that helps!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1