Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement radial blur with OpenCV

We would like to correct for field curvature introduced by a lens in a digital camera. We plan to use a digital unsharp mask Instead of applying a Gaussian blur we would like to try a radial blur, so the sharpening has more impact toward the edges of the image.

What is simplest way to create a radial blur using OpenCV ?

like image 660
Mark Hampton Avatar asked Sep 30 '11 07:09

Mark Hampton


People also ask

How do you do a radial blur?

To apply radial blur in Photoshop, load an image and then select the duplicate background layer. Go to Filter>Blur and select the Radial Blur option. Once the Radial Blur dialogue window appears, select the Blur method with either Spin or Zoom blur.

How do I create a motion blur in OpenCV?

To customize a motion blur in a specific vector direction, e.g. diagonally, simply place the 1's along the vector to create the filter. Consider the following image of a car. Code: Python code for applying a motion blur effect on the image. # Specify the kernel size.

How do I blur an image in OpenCV?

To average blur an image, we use the cv2. blur function. This function requires two arguments: the image we want to blur and the size of the kernel. As Lines 22-24 show, we blur our image with increasing sizes kernels.

How do you blur an image in Python cv2?

To make an image blurry, you can use the GaussianBlur() method of OpenCV. The GaussianBlur() uses the Gaussian kernel. The height and width of the kernel should be a positive and an odd number. Then you have to specify the X and Y direction that is sigmaX and sigmaY respectively.


1 Answers

The answer above is close but missing a few key elements that took me a bit to figure out. I've changed the maps so that they are correctly calculating the zoom and shrink and added/subtracted them from the x and y at each position (otherwise you will just end up remapping your image to a tiny square. Also I changed the /blur to *blur otherwise your maps will contain very large numbers and just not come out right (extremely large multiples of each position).

float center_x = width/2; //or whatever
float center_y = height/2;
float blur = 0.002; //blur radius per pixels from center. 2px blur at 1000px from center
int iterations = 5;

Mat growMapx, growMapy;
Mat shrinkMapx, shrinkMapy;
for(int x = 0; x < width; x++) {
  for(int y = 0; y < height; y++) {
    growMapx[x,y] = x+((x - center_x)*blur);
    growMapy[x,y] = y+((y - center_y)*blur);
    shrinkMapx[x,y] = x-((x - center_x)*blur);
    shrinkMapy[x,y] = y-((y - center_y)*blur);
  }
}

Mat tmp1, tmp2;
for(int i = 0; i < iterations; i++)  {
  remap(src, tmp1, growMapx, growMapy, CV_INTER_LINEAR); // enlarge
  remap(src, tmp2, shrinkMapx, shrinkMapy, CV_INTER_LINEAR); // shrink
  addWeighted(tmp1, 0.5, tmp2, 0.5, 0, src); // blend back to src
}
like image 61
Derek Patterson Avatar answered Sep 17 '22 22:09

Derek Patterson