How do I use the FIR filter on an image?

5 views (last 30 days)
I've hit a roadblock in my code and am unsure of how to proceed, whether I'm missing an entire step involving the filter function or not. This is the code I have currently... Any help is very much appreciated.
clc, clear
Pic = imread('barbara.png');
Pic = double(Pic);
[x,y] = size(Pic);
n1 = 0:x;
n2 = 0:y;
n3 = n2.';
n = n3*n1;
x = 1;
h = x*(n)-x*(n-1)
K = filter([1,-1],1,h);
Y=conv2(K,K,Pic,'same');
figure(1) Disp = uint8(Y);
imshow(Disp)

Answers (1)

Image Analyst
Image Analyst on 18 May 2017
Make up your 2-D kernel, then pass it in to imfilter().
  2 Comments
Just another student
Just another student on 18 May 2017
Sorry I'm not sure what you mean by this, could you please elaborate?
Image Analyst
Image Analyst on 18 May 2017
imfilter is a function that will multiply and sum a small matrix as it slides over the image. For example if you wanted to get an image where each pixel is the result of subtracting the prior pixel's value from the current pixel's value, you could do this:
kernel = [1, -1];
outputImage = imfilter(grayImage, kernel);
Or you could flip the kernel and use convolution:
kernel = [-1, 1];
outputImage = conv2(grayImage, kernel, 'same');

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!