开发者

Image processing - Smoothing

I just want to开发者_如何学JAVA ask if there are resources you recommend that describe Image smoothing simply.

Thanks.


Like some of the commenters mentioned, image smoothing can mean a lot of things. Mainly though, when someone uses the term they mean blurring or low-pass filtering. These are usually used synonymously. Idea of blurring is intuitive to us as visual beings, but what does it really mean?

When using a camera lens out of focus it means that rays of light reflected from objects mix in our vision. This is an image representing focused vision:

Image processing - Smoothing

Here's a similar diagram representing blurred or non-focused vision:

Image processing - Smoothing

In order to reproduce this effect digitally, let's take every pixel of an image and replace it by an average of itself and its neighboring eight pixels:

Image processing - Smoothing

Above is an image of a single white pixel inside a 7x7 black square. Note that it’s a single white pixel, not a whole square of pixels, just very up blown up. In a standard 8-bit image representation, this is represented as the following

 0   0   0   0   0   0   0 
 0   0   0   0   0   0   0 
 0   0   0   0   0   0   0 
 0   0   0  255  0   0   0 
 0   0   0   0   0   0   0 
 0   0   0   0   0   0   0 
 0   0   0   0   0   0   0 

When we perform averaging, that is replacing each pixel with the average of all pixels in a 3x3 square around it (that includes the original pixel also, we get

 0   0   0   0   0   0   0 
 0   0   0   0   0   0   0 
 0   0  28  28  28   0   0 
 0   0  28  28  28   0   0 
 0   0  28  28  28   0   0 
 0   0   0   0   0   0   0 
 0   0   0   0   0   0   0 

Above numbers are integers, because so far we’ve only done integer operations, so let’s be consistent.

This may not look like much of a smoothing for now, but let’s look at another example. Below is a checkerboard image with altering 0 and 255 pixel values.

Image processing - Smoothing

Let’s now replace each pixel by an average of a 4x4 square where the original pixel is positioned as such:

 . . . . 
 . X . . 
 . . . . 
 . . . . 

Your see that because of the checkerboard pattern, the average value of each such square will be 255/2 = 127 (integer division again). The checkerboard pixel alterations are very drastic from pixel to pixel. Going from any pixel to its neighbor, we go from highest possible pixel value to the lowest possible one. This is known as high frequency content. When averaging, we remove this high frequency component, and therefore, in signal processing lingo, we’re performing high stop filtering or, synonymously, low pass filtering. Don’t worry about strange artifacts on the edges. They are there because when filtering on the edge of the image, we’re missing pixels to average over, so we assume everything beyond the image is just black.

Let’s perform the same kind of averaging on a regular grayscale image. Below is the famous Lenna image. Next to it is its averaged version using a 7x7 averaging mask. You can see that it’s smoothed or blurred.

Image processing - Smoothing

This was a very simplistic example of image smoothing via averaging. Averaging is only one special case of low-pass filtering. In general, we perform weighted averaging to achieve desired low-pass filter effects. For further reading, I suggest looking up filter theory and convolution.

I hope this helps.


Image Smoothing is usually synonymous with Low Pass Filtering or getting rid of the high frequencies.


Background - what is filtering:

Most people understand what filtering is intuitively. You take something and pass it through a filter and remove something and the output doesn't have the substance that you filtered out. In images/2d and 1d signals you can filter.

The way you implement filtering on a 2d or 1d image is to do a convolution of the input, x, and the filter, h, to create the output y.

Here is an example of convolution in the 1d that I wrote in 5 minutes and did not check for errors:

void conv(float *x, int x_len, float * h, int h_len, float * y, int y_len)
{
 int i;
 register double accum;
 for(i = 0; i < x_len-h_len-1; i++) {
  accum = 0;
  for(j = 0; j < h_len; j++) {
   accum += x[i+j] * h[j];
  }
  y[i] = accum;
 }
}

int main {
 float x[] = {...};
 int x_len = sizeof(x)/sizeof(x[0]);
 float h[] = {...};
 int h_len = sizeof(h)/sizeof(h[0]);
 float y[x_len-h_len-1] = {0};
 int y_len = x_len-h_len-1;

 conv(x,x_len,h,h_len,y,y_len);
}

Notice how the input signal x is filtered by h. Then the output is stored in y. For more info search convolution on google.


Low pass filtering:

Now that you know how to filter a 1d signal. You can do a low pass filter. To do a low pass filter you create a filter h that only lets the low frequencies through. The most simple low pass filter is a rectangle filter h = ones(1,N); h = h ./ N; (matlab code). A more complex filter is a gaussian filter (this is very commonly used in image processing. See Photoshop/Gimp and look for "gaussian blur"). There are infinitely ways to create a low pass filter.

To create a custom low pass filter use the Parks-McClellan_filter_design_algorithm to create a arbitrary specific low pass filter. For more information search google for "creating a low pass filter".


Finally to answer your question - Image smoothing:

To do image smoothing you do the same thing in 1d but everytime you see a single for loop you have a double for loop (because you are doing a 2d signal).

Creating the filter is also similar but instead of having a 1d array filter, h, your filter h is now two dimensional.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜