"57" Android image engraved, Yang engraved, sketch effect processing

Source: Internet
Author: User

Introduction I participate in the development of the wok too paper-cut app using the image processing related technology about wok too paper-cut, each big Android store can be downloaded, the following stickers out the link of Xiaomi store

Wok too paper-cut download

Software effects


How to achieve the above image processing effect 1. Initialize the Gaussian matrix
ProcessFactory.IniGauss_2(ProcessFactory.gauss_radius);  //初始化高斯矩阵
2. Convert to Grayscale
Bitmap bmpGrayscale=ProcessFactory.toGray2(activity.imageBmp);  //转化为灰度图
3. Inverse color
Bitmap bmpGauss=ProcessFactory.toInverse(bmpGrayscale); //反色
4. Gaussian Blur
bmpGauss=ProcessFactory.toGauss(bmpGauss); //高斯模糊
5. Processing color dodge Generate sketch map Tocolordodge () function
/**     * 处理颜色减淡     * @param bmpGauss 高斯模糊完毕的图像     * @param bmpGrayscale 灰度图像     * @return     */     // 在原先的灰度图上做颜色减淡,使用反色高斯图辅助```
    bmpPapercut=ProcessFactory.toColorDodge(bmpGauss,bmpGrayscale);    // TODO bmpColorDodge 图即为素描图
6.papercut processing
bmpPapercut=ProcessFactory.toPapercut(bmpPapercut);
7. Expansion treatment
ProcessFactory.toPengzhang(bmpPapercut);fori0i2i++)        {            bmpPapercut = ProcessFactory.toPengzhang(bmpPapercut);        }
8. Corrosion Treatment
fori0i2i++)        {            bmpPapercut = ProcessFactory.toFushi(bmpPapercut);        }
9.frame processing
Bitmap min_img = ProcessFactory.toFramed(bmpPapercut);
At the end of the algorithm, the processing algorithm of engraving is described below 1. Initializing the Gaussian matrix
ProcessFactory.IniGauss_2(ProcessFactory.gauss_radius);  //初始化高斯矩阵
2. Convert to Grayscale
Bitmap bmpGrayscale=ProcessFactory.toGray2(activity.imageBmp);  //转化为灰度图
3. Inverse color
Bitmap bmpGauss=ProcessFactory.toInverse(bmpGrayscale); //反色
4. Gaussian Blur
bmpGauss=ProcessFactory.toGauss(bmpGauss); //高斯模糊
5. Processing color dodge Generate sketch map Tocolordodge () function
/**     * 处理颜色减淡     * @param bmpGauss 高斯模糊完毕的图像     * @param bmpGrayscale 灰度图像     * @return     */     // 在原先的灰度图上做颜色减淡,使用反色高斯图辅助```
    bmpPapercut=ProcessFactory.toColorDodge(bmpGauss,bmpGrayscale);    // TODO bmpColorDodge 图即为素描图
6. Printing and engraving processing
bmpPapercut=ProcessFactory.toYinkePapercut(bmpPapercut);
7. Corrosion Treatment
fori0i2i++)            ProcessFactory.toFushi(bmpPapercut);
The end of the engraving, you can see that the first five steps of the engraved and the same tool class is processfactory, the above used to define all functions in the inside can find some key code to paste out, if further communication, please add me below
/** * Initialize the Gaussian matrix * @param fi * *     Public Static void inigauss_2(intFI) {ToOne =0;//Be sure to initialize this variable! GAUSS =New Double[(fi*2+1) * (fi*2+1)];intindex =0; for(intX=-fi; x<=fi; X + +) { for(intY=-fi; y<=fi; y++) {DoubleSqrtfi = Sigma*sigma;Doubleex = Math.pow (MATH.E, (-(Double) (x*x + y*y)/(2*(Double)) (SQRTFI));Doubleresult = ex/(Double)(2* Math.PI * Sqrtfi);                Gauss[index] = result;                ToOne + = result; index++;//messagebox.show (result. ToString ());}            } for(inti =0; I < index; i++) {Gauss[i] = gauss[i]/toOne;//system.out.println ("gauss[" +i+ "] =" + gauss[i]);}Doublesum =0; for(DoubleI:gauss) {sum + = i; }//system.out.println ("sum is" +sum);}/** * Take grayscale image function 1 * @param bmporiginal * @return * *     Public StaticBitmapToGray1(Bitmap bmporiginal) {intwidth = Bmporiginal.getwidth ();//Get the width of the bitmap        intHeight = bmporiginal.getheight ();//Gets the height of the bitmap        int[] pixels =New int[Width*height];//Create a group of pixel points by the size of the bitmapBmporiginal.getpixels (Pixels,0, Width,0,0, width, height);intAlpha = (pixels[0] &0xff000000) >> -;//int alpha = (byte) 0xFF;         for(inti =0; i < height; i++) { for(intj =0; J < width; J + +) {intPIXEL_SRC = Pixels[width * i + j];intRed = (PIXEL_SRC &0x00ff0000) >> -;intGreen = (PIXEL_SRC &0x0000FF00) >>8;intBlue = PIXEL_SRC &0x000000ff;//Note need to convert to float type first                intPixel_gray = (int)(((float) Red) *0.299+ ((float) Green) *0.587+ ((float) Blue) *0.114);intPixel_output = ((Alpha << -) &0xff000000) | ((Pixel_gray << -) &0x00ff0000) | ((Pixel_gray <<8) &0x0000FF00) | (Pixel_gray &0x000000ff);                 Pixels[width * i + j] = Pixel_output;         }} Bitmap Bmpgrayscale = Bitmap.createbitmap (width, height, config.argb_8888); Bmpgrayscale.setpixels (Pixels,0, Width,0,0, width, height);returnBmpgrayscale;//bmporiginal.setpixels (pixels, 0, width, 0, 0, width, height);        //return bmporiginal; }//public static Bitmap ToGray5 (Bitmap bmporiginal) {//int row;//int pixel;//int R, G, B, A = 255;//      //int width = bmporiginal.getwidth ();//Get the width of the bitmap//int height = bmporiginal.getheight ();//Get Bitmap high//int[] pixels = new Int[width*height];//Create a group of pixel points by the size of the bitmap//bmporiginal.getpixels (pixels, 0, width, 0, 0, width, height);//      //for (int i = 0; i < height; i++)//      { //row = width * I;//for (int j = 0; J < width; j + +)//          { //int pixel_src = Pixels[row + j];//              //R = (pixel_src & 0x00ff0000) >>;//G = (pixel_src & 0x0000FF00) >> 8;//B = PIXEL_SRC & 0x000000ff;//              //pixel = (int) (R * 0.299 + G * 0.587 + B * 0.114);//R = G = B = pixel;//              //pixel = (A << 24) | (R << 16) | (G << 8) | B //Pixels[row + j] = pixel;//          } //      } //Bitmap Bmpgrayscale = bitmap.createbitmap (width, height, config.argb_8888);//bmpgrayscale.setpixels (pixels, 0, width, 0, 0, width, height);//return bmpgrayscale;//  }    /** * Take grayscale image function 2 * @param bmporiginal * @return * *      Public StaticBitmapToGray2(Bitmap bmporiginal) {intwidth, height;        Height = bmporiginal.getheight ();            width = Bmporiginal.getwidth ();        Bitmap Bmpgrayscale = bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888); Canvas C =NewCanvas (Bmpgrayscale); Paint paint =NewPaint (); ColorMatrix cm =NewColorMatrix (); Cm.setsaturation (0); Colormatrixcolorfilter f =NewColormatrixcolorfilter (CM);        Paint.setcolorfilter (f); C.drawbitmap (Bmporiginal,0,0, paint);returnBmpgrayscale; }/** * Reverse color * @param bmporiginal * @return * *      Public StaticBitmapToinverse(Bitmap bmporiginal) {intwidth = Bmporiginal.getwidth ();//Get the width of the bitmap        intHeight = bmporiginal.getheight ();//Gets the height of the bitmap        int[] pixels =New int[Width*height];//Create a group of pixel points by the size of the bitmapBmporiginal.getpixels (Pixels,0, Width,0,0, width, height);intAlpha = (byte) ((pixels[0] &0xff000000) >> -); for(inti =0; i < height; i++) { for(intj =0; J < width; J + +) {intPIXEL_SRC = Pixels[width * i + j];intRed = ((Pixel_src &0x00ff0000) >> -);intGreen = ((Pixel_src &0x0000FF00) >>8);intBlue = (PIXEL_SRC &0x000000ff); Red =255-Red; Green =255-Green; Blue =255-Blue; PIXEL_SRC = (alpha<< -) | (Red << -) | (Green <<8) |                 Blue                 Pixels[width * i + j] = PIXEL_SRC;         }} Bitmap Bmpinverse = Bitmap.createbitmap (width, height, config.argb_8888); Bmpinverse.setpixels (Pixels,0, Width,0,0, width, height);returnBmpinverse;//bmporiginal.setpixels (pixels, 0, width, 0, 0, width, height);//return bmporiginal;}
My QR code is as follows, welcome to exchange discussion

You are welcome to pay attention to the "It question summary" subscription number. Every day to push the classic face test and interview tips, are dry! The QR code of the subscription number is as follows:

"57" Android image engraved, Yang engraved, sketch effect processing

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.