图像的点运算
来源:互联网 发布:linux如何安装rpm包 编辑:程序博客网 时间:2024/06/05 04:25
利用点运算进行两个图像的融合:
采用基本的公式:A(u,v)=a*B(u,v)+(1-a)*C(u,v);
0≤a≤1,当a=0时,C是不透明的因此C将B整个图像进行遮挡了,当a=1时,B是不透明的,因此B将整个图像进行遮挡了。
两个图像融合的案例:
activity:
public class ImageJAndroidActivity extends Activity {
ImageView sourceImage;
ImageView destinationImage;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==1){
destinationImage.setImageBitmap((Bitmap)msg.obj);
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sourceImage=(ImageView) findViewById(R.id.source);
destinationImage=(ImageView) findViewById(R.id.destination);
}
//两幅图片的融合
public void remove(View v){
Bitmap bitmap1=BitmapFactory.decodeResource(getResources(),R.drawable.gg);
Bitmap bitmap2=BitmapFactory.decodeResource(getResources(),R.drawable.jj);
int width=bitmap1.getWidth();
int height=bitmap1.getHeight();
int[] pixel1=new int[width*height];
int[] pixel2=new int[width*height];
int[] newPixel=new int[width*height];
bitmap1.getPixels(pixel1, 0, width, 0, 0, width, height);
bitmap2.getPixels(pixel2, 0, width, 0, 0, width, height);
for(int y=0;y<height;y++){
for(int x=0;x<width;x++){
int a=(pixel1[y*width+x]>>16&0xff);
int red=(int)(0.7*(pixel1[y*width+x]>>16&0xff)+0.3*(pixel2[y*width+x]>>16&0xff));
int green=(int)(0.7*(pixel1[y*width+x]>>8&0xff)+0.3*(pixel2[y*width+x]>>8&0xff));
int blue=(int)(0.7*(pixel1[y*width+x]&0xff)+0.3*(pixel2[y*width+x]&0xff));
newPixel[y*width+x]=a<<24|red<<16|green<<8|blue;
}
}
Bitmap newBitmap=Bitmap.createBitmap(width, height, Config.RGB_565);
newBitmap.setPixels(newPixel, 0, width, 0, 0, width, height);
destinationImage.setImageBitmap(newBitmap);
}
两幅图片如下:
融合之后 的效果为:
两个图片进行合成:
原来的图片是:
现在要达到的效果是将上面图片的白色背景去掉(透明度为0)
public class ImageJAndroidActivity extends Activity {
ImageView sourceImage;
ImageView destinationImage;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==1){
destinationImage.setImageBitmap((Bitmap)msg.obj);
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sourceImage=(ImageView) findViewById(R.id.source);
destinationImage=(ImageView) findViewById(R.id.destination);
}
//图像 的点运算
//两幅图像的合成
public void remove(View v){
Bitmap bitmap1=BitmapFactory.decodeResource(getResources(),R.drawable.gg);
Bitmap bitmap2=BitmapFactory.decodeResource(getResources(),R.drawable.s);
int width1=bitmap1.getWidth();
int height1=bitmap1.getHeight();
int width2=bitmap2.getWidth();
int height2=bitmap2.getHeight();
int[] pixel1=new int[width1*height1];
int[] pixel2=new int[width2*height2];
bitmap1.getPixels(pixel1, 0, width1, 0, 0, width1, height1);
bitmap2.getPixels(pixel2, 0, width2, 0, 0, width2, height2);
for(int y=0;y<height2;y++){
for(int x=0;x<width2;x++){
//两个图片的像素进行融合
if(pixel2[y*width2+x]!=Color.WHITE){
int a=(pixel2[y*width2+x]>>24&0xff);
int red=(int)(1*(pixel2[y*width2+x]>>16&0xff));
int green=(int)(1*(pixel2[y*width2+x]>>8&0xff));
int blue=(int)(1*(pixel2[y*width2+x]&0xff));
pixel1[(y+100)*width1+(x+20)]=a<<24|red<<16|green<<8|blue;//这里写成width1刚好换行的时候吻合
}
}
}
Bitmap newBitmap=Bitmap.createBitmap(width1, height1,Config.RGB_565);
newBitmap.setPixels(pixel1, 0, width1,0 ,0, width1, height1);
destinationImage.setImageBitmap(newBitmap);
}
最终达到的效果是:
- 图像的点运算
- 图像的点运算
- 图像的点运算
- 图像的点运算
- 图像的运算--点运算
- 【笔记】图像点运算
- 图像点运算
- 图像点运算
- 图像点运算
- OpenCV图像处理 图像的点运算 ( 灰度直方图 )
- 图像操作之点运算
- (5)Air Band数字图像处理基础-图像的点运算
- 【图像】软件使用--matlab点运算
- photoshop图像点运算算法揭秘
- 图像的基本运算
- 图像的运算
- 图像的基本运算
- 图像的基本运算
- iOS打包成.ipa文件
- 那啥,,矩阵乘法,矩阵快速幂模板
- 解决:Win7、VS2010、OpenCV2.3.1出现“丢失tbb_debug.dll”错误
- 黑马程序员——————关于多维数组问题
- Fergus的Removing Camera Shake from a Single Photograph的附录部分的一些推导
- 图像的点运算
- Buy Tickets
- 用Ant实现Java项目的自动构建和部署
- 开发日记,_WinMain@16无法解析的外部符号
- xhEditor编辑器入门基础
- centos6.5 basic server 环境 安装desktop
- 2440 Ubuntu建立交叉编译环境(root权限下)
- 公共信息模型CIM
- 【案例分享】仿QQ5.0侧滑菜单ResideMenu