zoukankan      html  css  js  c++  java
  • 图片处理边缘高亮

    1、算法

    r = Math.sqrt((r- rightr)^2 + (r-bottomr)^2)*2

    g = Math.sqrt((g- rightg)^2 + (g-bottomg)^2)*2

    b = Math.sqrt((b- rightb)^2 + (b-bottomb)^2)*2

    2、代码实现

     public Bitmap render(Bitmap bitmap)
      {
        if(bitmap == null)return null;
    
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
    
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels ,0 , width , 0 , 0 , width , height);
    
        int rectTop = 0;
        int rectBottom = height-1;
        int rectLeft = 0;
        int rectRight = width-1;
    
        for(int i=rectTop ; i<rectBottom ; i++)
        {
          for(int j=rectLeft ; j<rectRight ; j++)
          {
            int pixel = pixels[i*width +j];
            int leftPixel = pixels[i*width +j+1];
            int bottomPixel = pixels[i*width +j +width];
            int r = (pixel & 0x00ff0000)>>16;
            int g = (pixel & 0x0000ff00)>>8;
            int b = (pixel & 0x000000ff);
    
            int leftR = (leftPixel & 0x00ff0000)>>16;
            int leftG = (leftPixel & 0x0000ff00)>>8;
            int leftB = (leftPixel & 0x000000ff);
    
            int bottomR = (bottomPixel & 0x00ff0000)>>16;
            int bottomG = (bottomPixel & 0x0000ff00)>>8;
            int bottomB = (bottomPixel & 0x000000ff);
            r = algorithm(r , leftR , bottomR);
            g = algorithm(g , leftG , bottomG);
            b = algorithm(b , leftB , bottomB);
            pixels[i*width +j] = (pixel & 0xff000000) + (r<<16)+ (g<<8) +b;
          }
        }
    
        return Bitmap.createBitmap(pixels ,width , height , Config.ARGB_8888);
      }
                                        
    public int algorithm(int value , int leftValue , int bottomValue)
    {
    
      int pixel = (int)(Math.pow(value-bottomValue , 2) + Math.pow(value-leftValue , 2) ) ;
      pixel = (int)(Math.sqrt(pixel) * 2);
      if(pixel<0)
      {
        pixel = 0;
      }
    
      if(pixel>255)
      {
        pixel = 255;
      }
      return pixel;
    }
  • 相关阅读:
    cmd 进入mysql 小技巧
    【scikit-learn】交叉验证及其用于參数选择、模型选择、特征选择的样例
    向txt文件中写入换行
    CTabCtrl的使用
    unicode下数据之间的转换
    下载数据库包
    python3.5.1语法
    配置Python+selenium+firefox自动化测试
    使用Tesseract OCR识别验证码
    white的配置使用
  • 原文地址:https://www.cnblogs.com/lipeil/p/2696663.html
Copyright © 2011-2022 走看看