How do I use the FIR filter on an image?
5 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Image Analyst
on 18 May 2017
Make up your 2-D kernel, then pass it in to imfilter().
2 Comments
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');
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!