Android图像处理系统1.4图像的锐化-边缘检测
2012-08-30 20:37
381 查看
Android图像处理系统1.4图像的锐化-边缘检测
图像的锐化-边缘检测:(Robert Gradient、Sobel Gradient、Laplace
Gradient)
@author:郑海波
相关博客:
1.http://blog.csdn.net/nuptboyzhb/article/details/7925994
2.http://blog.csdn.net/nuptboyzhb/article/details/7926407
1. Robert Gradient
[图1]
2. Sobel Gradient
[图2]
3. Laplace Gradient
[图3]
关键的Java代码
图像的锐化-边缘检测:(Robert Gradient、Sobel Gradient、Laplace
Gradient)
@author:郑海波
相关博客:
1.http://blog.csdn.net/nuptboyzhb/article/details/7925994
2.http://blog.csdn.net/nuptboyzhb/article/details/7926407
1. Robert Gradient
[图1]
2. Sobel Gradient
[图2]
3. Laplace Gradient
[图3]
关键的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; }
相关文章推荐
- Android图像处理系统1.4图像的锐化-边缘检测
- android图像边缘检测 锐化处理有一个函数编译不过
- 数字图像处理--图像锐化和边缘检测
- 在Android平台上利用opencv进行图像处理之边缘检测、灰度变换、缩小
- python 简单图像处理(11) 空间域图像锐化(边缘检测)
- python 简单图像处理(11) 空间域图像锐化(边缘检测)
- 基础图像处理之混合空间增强——(Java:拉普拉斯锐化、Sobel边缘检测、均值滤波、伽马变换)
- 关于android系统图像特效处理之锐化效果
- 图像处理中各种边缘检测的微分算子简单比较(Sobel,Robert, Prewitt,Laplacian,Canny)
- Atitit 图像处理 halcon类库的使用 范例边缘检测 attilax总结
- 图像处理之应用卷积– 轧花与边缘检测
- 图像处理常用边缘检测算子
- 图像处理理论(二)——形态学、边缘检测、图像金字塔
- 【OpenCV3图像处理】边缘检测:Sobel算子,Laplace算子,Canny算子
- 【图像处理】图像边缘检测
- 图像处理之Canny边缘检测
- 图像边缘检测与边缘增强处理——(Roberts、prewitt、sobel)
- 图像锐化(增强)和边缘检测
- 图像锐化(增强)和边缘检测
- 黑马程序员之图像处理中的边缘检测