blurring an image by creating a kernel

71 Ansichten (letzte 30 Tage)
Ayesha
Ayesha am 15 Okt. 2014
Kommentiert: Image Analyst am 15 Okt. 2014
Hello,
I have an image which I need to blur by creating a filter explicitly but I seem to forget the basic math behind deblurring using the 2D kernel along both the directions. The kernel needs be around 45 degreeish. Below is my first attempt in designing the blur (motion) kernel H which doesn't seem to work where motion along x is 20 and motion along y is 50.
a=linspace(-0.2,0.2,size(image,2));
b=linspace(-0.2,0.2,size(image,1));
[a1,b1]=meshgrid(a,b);
H=((1./(pi*a1*20)).*sin(pi*a1*20).*exp(-1i*pi*a1*50))+((1./(pi*a1*20)).*cos(pi*a1*20).*exp(-1i*pi*a1*50));
I know I am doing something majorly wrong. Any help would be appreciated.

Antworten (1)

Image Analyst
Image Analyst am 15 Okt. 2014
Bearbeitet: Image Analyst am 15 Okt. 2014
kernel = ones(50, 20)/(50*20);
blurredImage = imfilter(grayImage, kernel);
That will blur it by 50 vertically and 20 horizontally. I don't know what you mean with that 45 degree comment.
  2 Kommentare
Ayesha
Ayesha am 15 Okt. 2014
Thanks for your reply but that doesn't work for me due to mismatch between the filter and image dimension. So previously, I was using something like this:
img=double(imread('image.jpg'));
a=linspace(-0.2,0.2,size(img,2));
b=linspace(-0.2,0.2,size(img,1));
[a1,b1]=meshgrid(a,b);
h=(1./(pi*a1*90)).*sin(pi*a1*90).*exp(-1i*pi*a1*90) %filter with motion
%rate=90
This works very well and now I would like to build on the same but with 10 and 50 motion rates. I know there are alternative but I ma specifically interested in creating my own filter to blur the image.
Image Analyst
Image Analyst am 15 Okt. 2014
How does that work well? All that does is to create a complex image the same size as the original image. How is that going to blur the original image? You need to have a smaller kernel and then slide it across the image. This is what imfilter() and conv2() do. To blur 50 pixels vertically and 30 pixels you can use a kernel like I showed. If you want to blur/smear the image in a 45 degree direction, use code that Mohammad gave. I don't understand the 30 and 50 stuff though. As you know 50 high by 30 wide is NOT 45 degrees. So please explain that discrepancy.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by