The image obtained through the mobile phone has some noises, that is, the image denoising. In simple terms, a matrix is used to move a pixel in a grayscale image, with some logic to eliminate the outliers in the grayscale image, the noise. The main methods of denoising are mean filter, median filter, adaptive wiener filter, morphological noise filter and Gaussian filter.
Image Gaussian filtering is used to calculate smooth template in two-dimensional space using normal distribution (Gaussian function), and it is used to do convolution operation with gray image to achieve the purpose of filtering denoising. If the standard deviation of the normal distribution, n is the size of the template, the element on the template is calculated as:
Depending on the characteristics of the normal distribution, the larger the resulting image becomes blurred. Theoretically speaking, the gray level of the image is not 0 of the points should constitute the convolution matrix and the original image to do the transformation, that is, the calculation of each pixel has to include the whole picture. However, when calculating the discrete approximation of the Gaussian function in practice, the pixel values outside the distance can be regarded as ineffective, that is, the template size is (6*sigma+1) * (6*sigma+1)
。 In this paper, the template matrix is selected, the larger the Sigma value, the more blurred. From the obtained template matrix and the original gray image convolution operation can be removed from the image of some of the noise.
Therefore, Gaussian blur is generally divided into the following four steps:
1. Get the Gaussian template matrix:
Public float[] Get2dkernaldata (intNfloatSigma) { intsize = 2 * n + 1; floatSIGMA22 = 2 * Sigma *Sigma; floatSigma22pi = (float) Math.PI *Sigma22; float[] Kernaldata =New float[Size][size]; intRow = 0; for(inti =-N; I <= N; i++) { intColumn = 0; for(intj =-N; J <= N; J + +) { floatXdistance = i *i; floatYdistance = J *J; Kernaldata[row][column]= (float) Math. exp (-(xdistance + ydistance)/sigma22)/Sigma22pi; Column++; } row++; } returnKernaldata; }
View Code
2. Get Gray matrix
Public int[][]getgraymatrix (Bitmap bt) {inthdjz[][]=New int[H][w]; for(inti=0;i) for(intj=0;j<w;j++) { intargb=Bt.getpixel (J, I); intr = (argb >>) & 0xFF; intg = (ARGB >> 8) & 0xFF; intb = (argb >> 0) & 0xFF; intGraypixel = (int) (R + G + B)/3; HDJZ[I][J]=Graypixel; } returnHDJZ; }
View Code
3. Convolution operation
Public int[] GS (int[] HD,intSizefloatSigma) { float[] GS =get2dkernaldata (size, sigma); intOutmax = 0; intInmax = 0; for(intx = size; x < w-size; X + +) for(inty = size; Y < h-size; y++) { floatHC1 = 0; if(Hd[y][x] >Inmax) Inmax=Hd[y][x]; for(intK =-size; K < size + 1; k++) for(intj =-size; J < size + 1; J + +) {HC1= gs[size + k][j + size] * hd[y + j][x + K] +HC1; } Hd[y][x]= (int) (HC1); if(Outmax <hc1) Outmax= (int) (HC1); } floatRate = Inmax/Outmax; for(intx = size; x < w-size; X + +) for(inty = size; Y < h-size; y++) {Hd[y][x]= (int) (Hd[y][x] *Rate ); } returnHD; }
View Code
4, the gray matrix will be obtained to create a grayscale map
//Create a grayscale graph from a grayscale matrix PublicBitmap Creategrayimage (int[][]HDJZ] { intH=hdjz.length; intW = hdjz[0].length; Bitmap BT=Bitmap.createbitmap (W, H, Image.getconfig ()); for(inti=0;i) for(intj=0;j<w;j++) { intGrayvalue=Hdjz[i][j]; intcolor = ((0xFF <<) + (Grayvalue << +) + (Grayvalue << 8) +grayvalue); Bt.setpixel (j, I, color); } returnBT; }
View Code
Gaussian blur of images