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

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]

98d11bfed732b94863164f803aa40b78.png

2. Sobel Gradient

[图2]

f08b7975b2ce6e292d7dd1e6cebea9eb.png

3. Laplace Gradient

[图3]

6b3b1144b77ef33ce0a377acbce929d0.png

关键的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

for(j=0;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

for(j=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

for(j=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自定义控件超链接文本LinkTextView的实现

Android自定义控件LinkTextView的实现@author:郑海波http://blog.csdn.net/nuptboyzhb/相关博客:http://blog.csdn.net/nuptboyzhb/article/details/7880916功能:设计一个TextView,当

android简单网页浏览器的开发

android简单网页浏览器的开发@author:郑海波http://blog.csdn.net/nuptboyzhb/功能概要:1.用WebView控件实现简单浏览器的开发2.实现了网页浏览器的简单功能。3.能

基于web的android图像处理示例(Win7+Apache+PHP+Matlab+Android)

本文将介绍C/S模式的图像处理系统。C/S的框架已经在[1]中作了简单的介绍。[2]中介绍了如何搭建基于android和WAMP5的B/S模式的本机测试平台。本系统是在[4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值