Realization of mean filter algorithm based on MATLAB

Source: Internet
Author: User

In the image acquisition and generation of the inevitable introduction of noise, image noise refers to the image data in the unnecessary or unnecessary interference information, which causes us to extract the image information interference, so to be de-noise processing, the common method of noise removal is mean filter, median filter, Gaussian filter, etc. This article is to achieve the mean filter.

The method of mean filtering is to generate the image data with a 3x3 matrix or other templates such as 5x5, and then the matrix template is processed. A template is given to the target pixel on the image, which includes the neighboring pixels around it (8 pixels around the center of the target pixel to form a filter template that removes the target pixel itself) and replaces the original pixel value with the average of the entire pixel in the template. In plain words, the nine numbers are averaged to replace the middle number. In the FPGA we simply sum the eight points around the target pixels and divide them by 8 for the sake of simplicity, instead of the target pixel points.

MATLAB has a variety of functions for digital image processing support, all kinds of filtering and edge detection can be implemented with a few lines of function, but Bo master the basic principle of learning algorithms, so do not use the function of the filter principle to write code. This design is in the previous RGB turn gray gray image to filter processing.

adding noise pollution functions

g = Imnoise (i,type,parameters)

G=imnoise (f, ' salt & Pepper ', d) pollute the image f with salt and pepper noise, where d is the noise density (that is, the percentage of the image area that includes the noise value). As a result, approximately d*numel (f) pixels are affected. The default noise density is 0.05.

This design only uses the processing of salt and pepper noise, so only the addition of this kind of noise is recorded.

Mean filter code
1%Mean Filter2 CLC;3 clear All;4 close all;5 6Rgb_data = Imread ('lena.jpg');7 8R_data = Rgb_data (:,:,1);9G_data = Rgb_data (:,:,2);TenB_data = Rgb_data (:,:,3); One  A%imshow (rgb_data); -  -[Row,col, DIM] =size (rgb_data); the  -Y_data =zeros (row,col); -Cb_data =zeros (row,col); -Cr_data =zeros (row,col); +Gray_data =Rgb_data; -  +  forR =1: ROW A      forc =1: COL atY_data (r, c) =0.299*r_data (R, C) +0.587*g_data (R, c) +0.114*B_data (R, c); -Cb_data (r, c) =-0.172*r_data (R, C)-0.339*g_data (R, c) +0.511*b_data (R, c) + -; -Cr_data (r, c) =0.511*r_data (R, C)-0.428*g_data (R, c)-0.083*b_data (R, c) + -; - End - End -  inGray_data (:,:,1)=Y_data; -Gray_data (:,:,2)=Y_data; toGray_data (:,:,3)=Y_data; +  - Figure ; the imshow (gray_data); *  $%Gray Mean FilterPanax Notoginseng  -Gray_data =im2double (gray_data); theIMGN = Imnoise (Gray_data,'Salt & Pepper',0.05);  +  A%IMGN =Gray_data; the  + Figure ; - imshow (IMGN); $  $  forR =2:1: row-1 -      forc =2:1: col-1 -Mean_img (r,c) = (IMGN (r1, C-1) + IMGN (r1, c) + IMGN (R-1, c+1) + IMGN (R, C1) + IMGN (r, c) + IMGN (R, c+1) + IMGN (r+1, C-1) + IMGN (r+1, c) + IMGN (r+1, c+1)) /9; the End - EndWuyi  the Figure ; -Imshow (MEAN_IMG);
Comparison of picture results before and after processing

Gray Lena

Mean_filter Lena

From the picture before and after processing can see the processing of the picture blurred some, this is because the mean filter is to smooth the image, the pixel value of high pixels will be pulled low, the pixel value of low pixels will be pulled high, tend to an average, so the image will be blurred some.

Lena after adding salt and pepper noise

Add salt and pepper noise after mean_filter Lena

Salt and pepper noise (salt & pepper noise) is a common noise in digital images, the so-called salt and pepper, the pepper is black, is white, salty noise is the random appearance of black and white pixels on the image. Salt and pepper noise is a noise caused by signal pulse strength. Here we can see that the mean filter is the image smoothing, but the salt and pepper noise basically no effect, to the salt and pepper noise processing will be used median filter, Bo master next to do.

Please specify the source: Ninghechuan (Ning River)

Personal Subscription Number: Open Source FPGA

If you want to receive a personal blog post in time, you can scan the QR code on the left (or long press the QR code) to follow your personal subscription number

Know Id:ninghechuan

Micro Bo Id:ninghechuan

Original address: www.cnblogs.com/ninghechuan/p/9526100.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.