user_jt
user_jt

Reputation: 259

Blurring an image with a non-uniform filter

I am new on Stackoverflow and this is my first question, so please be patient with me.

I want to blur an image with a non uniform filter.However, I have not fully understood what is a non-uniform filter and I would like to ask what does exactly an non-uniform filter do and how can that be intepreted in terms of a code. I want to implement this in Matlab. Hereby is an example of my code.

A non-uniform kernel would be that

init= imread('cameraman.jpg');
initial = rgb2gray(init);
sigma=3;
H_filt = fspecial('gaussian',[5 5], sigma);

or would be restricted to only one dimension?

init= imread('cameraman.jpg');
initial = rgb2gray(init);
sigma=3;
H_filt = fspecial('gaussian',[5 1], sigma);

Thanks in advance fellows!!

Upvotes: 1

Views: 2244

Answers (2)

sansuiso
sansuiso

Reputation: 9379

Non uniform blur kernels

A non-uniform blur kernel is a kernel that is not constant over the whole image.

To take some examples:

  • out-of-focus blur kernel size depends on the distance between the camera and the scene point (usually referred to as Z). This phenomenon can be exploited by shape-from-defocus algorithms;
  • a moving object in a static scene can be subject to motion blur, while there is obviously no blur in the static parts. Different moving objects can indeed have different motion blurs;
  • a camera lens usually produces better (sharper) images in its center with respect to its borders.

How to generate a non uniformly blurred image

It depends on how many blur kernels your image has, and what kind of blur you want to emulate.

  • Defocus blur (function of the camera-scene point distance) can be simulated by ray tracing software.
  • If you wan to generate non-uniform blur by post-processing (convolution), then you need to:
    1. Get the blur kernel for the pixel at hand (i,j): for example sigma_ij = f(i,j)
    2. Convolve your input image (the sharp, clean one) by this blur kernel: H_ij = fspecial('gaussian', [some large size], sigma_ij])
    3. Write the result to your output image: I_final[i,j] = I_blurred_with_Hij[i,j]
    4. Proceed to the next pixel.

In some cases, you can cut this greedy loop with correct assumptions (blur size limit, only two or 3 possible blurs in the image...).

Upvotes: 3

Royi
Royi

Reputation: 4953

Usually they mean a filter which isn't constant for each pixel -> It is not uniform spatially.
Try to implement a Gaussian Blur which its Standard Deviation is different at each pixel.

A fast way to do so is using colfilt.

If you need more help let me know.

Upvotes: 1

Related Questions