Android图像处理系统1.4图像的锐化-边缘检测

图像的锐化-边缘检测:(Robert GradientSobel GradientLaplace Gradient)

@author:郑海波

相关博客:

1.http://blog.csdn.net/nuptboyzhb/article/details/7925994

2.http://blog.csdn.net/nuptboyzhb/article/details/7926407

1.Robert Gradient

[1]

Android图像处理系统1.4图像的锐化-边缘检测_第1张图片

2.Sobel Gradient

[2]

3.Laplace Gradient

[3]

Android图像处理系统1.4图像的锐化-边缘检测_第2张图片

关键的Java代码


/* * Robert算子梯度 *  */public Bitmap RobertGradient(Bitmap myBitmap){// Create new array    int width = myBitmap.getWidth();    int height = myBitmap.getHeight();    int[] pix = new int[width * height];    myBitmap.getPixels(pix, 0, width, 0, 0, width, height);    Matrix dataR=getDataR(pix, width, height);    Matrix dataG=getDataG(pix, width, height);    Matrix dataB=getDataB(pix, width, height);    //Matrix dataGray=getDataGray(pix, width, height);    /////////////////////////////////////////////////////////    dataR=eachRobertGradient(dataR,width,height);    dataG=eachRobertGradient(dataG,width,height);    dataB=eachRobertGradient(dataB,width,height);    ///////////////////////////////////////////////////////////////    // Change bitmap to use new array    Bitmap bitmap=makeToBitmap(dataR, dataG, dataB, width, height);    myBitmap = null;    pix = null;    return bitmap;}private Matrix eachRobertGradient(Matrix tempM,int width,int height){int i,j;for(i=0;i<width-1;i++){for(j=0;j<height-1;j++){int temp=Math.abs((int)tempM.get(i, j)-(int)tempM.get(i,j+1)) +Math.abs((int)tempM.get(i+1,j)-(int)tempM.get(i,j+1));tempM.set(i, j, temp);}}return tempM;}/* *Sobel算子锐化  */public Bitmap SobelGradient(Bitmap myBitmap){// Create new array    int width = myBitmap.getWidth();    int height = myBitmap.getHeight();    int[] pix = new int[width * height];    myBitmap.getPixels(pix, 0, width, 0, 0, width, height);    Matrix dataR=getDataR(pix, width, height);    Matrix dataG=getDataG(pix, width, height);    Matrix dataB=getDataB(pix, width, height);    Matrix dataGray=getDataGray(pix, width, height);    /////////////////////////////////////////////////////////    dataGray=eachSobelGradient(dataGray, width, height);    dataR=dataGray.copy();    dataG=dataGray.copy();    dataB=dataGray.copy();    ///////////////////////////////////////////////////////////////    // Change bitmap to use new array    Bitmap bitmap=makeToBitmap(dataR, dataG, dataB, width, height);    myBitmap = null;    pix = null;    return bitmap;}private Matrix eachSobelGradient(Matrix tempM,int width,int height){int i,j;Matrix resultMatrix=tempM.copy();for(i=1;i<width-1;i++){for(j=1;j<height-1;j++){int temp1=Math.abs(((int)tempM.get(i+1, j-1)+2*(int)tempM.get(i+1, j)+(int)tempM.get(i+1,j+1)) -(((int)tempM.get(i-1,j-1)+2*(int)tempM.get(i-1,j)+(int)tempM.get(i-1,j-1))));int temp2=Math.abs(((int)tempM.get(i-1, j+1)+2*(int)tempM.get(i, j+1)+(int)tempM.get(i+1,j+1)) -(((int)tempM.get(i-1,j-1)+2*(int)tempM.get(i,j-1)+(int)tempM.get(i+1,j-1))));int temp=temp1+temp2;resultMatrix.set(i, j, temp);}}return resultMatrix;}/* *Laplace 锐化  */public Bitmap LaplaceGradient(Bitmap myBitmap){// Create new array    int width = myBitmap.getWidth();    int height = myBitmap.getHeight();    int[] pix = new int[width * height];    myBitmap.getPixels(pix, 0, width, 0, 0, width, height);    Matrix dataR=getDataR(pix, width, height);    Matrix dataG=getDataG(pix, width, height);    Matrix dataB=getDataB(pix, width, height);    Matrix dataGray=getDataGray(pix, width, height);    /////////////////////////////////////////////////////////    dataGray=eachLaplaceGradient(dataGray,width,height);    dataR=dataGray.copy();    dataG=dataGray.copy();    dataB=dataGray.copy();    ///////////////////////////////////////////////////////////////    // Change bitmap to use new array    Bitmap bitmap=makeToBitmap(dataR, dataG, dataB, width, height);    myBitmap = null;    pix = null;    return bitmap;}private Matrix eachLaplaceGradient(Matrix tempM,int width,int height){int i,j;Matrix resultMatrix=tempM.copy();for(i=1;i<width-1;i++){for(j=1;j<height-1;j++){int temp=Math.abs(5*(int)tempM.get(i, j)-(int)tempM.get(i+1,j)-(int)tempM.get(i-1,j)-(int)tempM.get(i,j+1)-(int)tempM.get(i,j-1));resultMatrix.set(i, j, temp);}}return resultMatrix;}


更多相关文章

  1. Android 4.4 在启动到 ANDROID 闪光字的时候图像错乱的解决过程
  2. Android中的图形图像
  3. Android图像滤镜框架GPUImage从配置到应用
  4. 第1章 Android图像概述
  5. Android图像处理_浮雕效果

随机推荐

  1. Android(安卓)运行时找不到类:java.lang.N
  2. Handler,MessageQueue,Looper,你所不知道的A
  3. Android(安卓)INSTALL_FAILED_INSUFFICIE
  4. Android(安卓)emoji表情处理
  5. Android(安卓)ProgressBar设置转圈样式
  6. Android简单实现Socket通信,客户端连接服
  7. Android(安卓)RatingBar:评价条控件
  8. Android(安卓)Studio 1.5.1 JNI 编程
  9. WindowInsets 在View下的的分发(一)
  10. Android开发之自定义相机设定照片和预览