필터 지우기
필터 지우기

blurring an image by creating a kernel

조회 수: 24 (최근 30일)
Ayesha
Ayesha 2014년 10월 15일
댓글: Image Analyst 2014년 10월 15일
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.

답변 (1개)

Image Analyst
Image Analyst 2014년 10월 15일
편집: Image Analyst 2014년 10월 15일
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
Ayesha
Ayesha 2014년 10월 15일
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 2014년 10월 15일
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.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by