blurring an image by creating a kernel
조회 수: 70 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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
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!