import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.util.*;
import java.io.*;
/**
*ImageXor is an algorithm to apply logical XOR/XNOR between two images
*@author:Judy Robertson, SELLIC OnLine
*@author:Neil Brown, DAI
*@author:Timothy Sharman
*@see code.iface.imagexor
*/
public class ImageXor extends Thread{
//the width of the input images in pixels
private int i1_w;
private int i2_w;
//the width and height of the output image
private int d_w;
private int d_h;
private int[] dest_1d;
private boolean is_colored;
/**
*Constructs a new Image Xor
*@param firstwidth The width of the iorst input image
*@param secondwidth The width of the second input image
*/
public ImageXor(int firstwidth, int secondwidth){
i1_w = firstwidth;
i2_w = secondwidth;
}
/**
*Applies the image XOR operator on the specified image arrays, with the specified offset and scale value
*@param src1_1d The first source image as a pixel array
*@param src2_1d The second source image as a pixel array
*@param XNOR Boolean to indicate wether we should XNOR rather than XOR
*@param width width of the destination image in pixels
*@param height height of the destination image in pixels
*@param oset The offset value
*@param scale The scale value
*@return A pixel array containing the X(N)OR of the two input images
*/
//Bob's image xor algorithm..
/*a) assume the image is grey level (hence RR=GG=BB)
b) use value &0x000000ff to get the BB value
c) do this for both input images
d) apply the operation (eg XOR)
e) add oset and then scale
f) clip to lie from 0 to 255. Call this value 0xCD
g) create int value 0xffCDCDCD
*/
public int [] doXor(int [] src1_1d, int [] src2_1d, boolean XNOR,
int width, int height, float oset, float scale){
int place1 = -1;
int place2 = -1;
int src1rgb = 0;
int src2rgb = 0;
int result = 0;
//Get size of image and make 1d_arrays
d_w = width;
d_h = height;
dest_1d = new int[d_w*d_h];
boolean firstwider = false;
boolean secondwider = false;
int wrap;
if (i1_w > d_w){
wrap = ((i1_w + 1) - d_w);
firstwider = true;
} else if (i2_w > d_w){
wrap = ((i2_w + 1) - d_w);
secondwider = true;
} else {
wrap = 0;
}
//if you know there is no wrap around, you can save yourself some time
if (wrap == 0) {
for (int i=0; i< dest_1d. length ; i++){
src2rgb = src2_1d[i] & 0x000000ff;
src1rgb = src1_1d[i] & 0x000000ff;
/* Due to Java not having unsigned ints, the ~ will always give a
negative result. As we a dealing with only the bottom 8 bits of
the int, I will just mask out the bottom bits. Neil.
*/
if (XNOR) {
result = (int) ((scale * (float)(~(src1rgb ^ src2rgb) & 0xff))+oset);
} else {
result = (int) ((scale * (float) ( src1rgb ^ src2rgb )) + oset);
}
//clip to 0 ... 256
if (result < 0){
result = 0;
} else if (result > 255){
result = 255;
}
//create an int value for dest_1d
dest_1d[i ] = 0xff000000 | (result + (result << 16) + (result << 8));
}
return dest_1d;
}
else {
for (int i=0; i< dest_1d. length ; i++){
//we might need to skip out some pixels which aren't in the overlap area
if ((i %d_w ) == 0 ) {
if ( i == 0 ){
place1 = 0;
place2 = 0;
} else if (secondwider) {
place2 = place2 + wrap;
place1 ++;
} else {
place1 = place1 + wrap;
place2 ++;
}
} else{
place2 ++;
place1 ++;
}
src2rgb = src2_1d[place2] & 0x000000ff;
src1rgb = src1_1d[place1] & 0x000000ff;
/* Due to Java not having unsigned ints, the ~ will always give a
negative result. As we a dealing with only the bottom 8 bits of
the int, I will just mask out the bottom bits. Neil.
*/
if (XNOR) {
result = (int) ((scale * (float) (~(src1rgb ^ src2rgb) & 0xff))+ oset);
} else {
result = (int) ((scale * (float) ( src1rgb ^ src2rgb )) + oset);
}
//clip to 0 ... 256
if (result < 0){
result = 0;
} else if (result > 255){
result = 255;
}
//create an int value for dest_1d
dest_1d[i ] = 0xff000000 | (result + (result << 16) + (result << 8));
}
return dest_1d;
}
}
/**
*XORs the specified input image by the constant, also adds offset
*
*@param src1_1d The input pixel array
*@param constant The constant value to AND every pixel in the input array by
*@param XNOR Boolean to indicate wether we should XNOR rather than XOR
*@param width width of the destination image in pixels
*@param height height of the destination image in pixels
*@param oset The offset value
*@param scale The scale value
*@return A pixel array with the constant value X(N)ORed with every pixel in the input array
*/
public int [] doXor(int [] src1_1d, int constant, boolean XNOR,
int width, int height, float oset, float scale ){
//Get size of image and make 1d_arrays
d_w = width;
d_h = height;
dest_1d = new int[d_w*d_h];
int src1rgb;
int result = 0;
/* Due to Java not having unsigned ints, the ~ will always give a
negative result. As we a dealing with only the bottom 8 bits of
the int, I will just mask out the bottom bits. Neil.
*/
//now do the XOR on the input image
for (int i=0; i< src1_1d. length; i++){
src1rgb = src1_1d[i] & 0x000000ff;
if(XNOR) {
result = (int) (( scale * ((float) (~(src1rgb ^ constant) &0xff))) + oset);
} else {
result = (int) (( scale * ((float) ( src1rgb ^ constant ))) + oset);
}
if (result > 255){
result = 255;
}
if (result < 0){
result = 0;
}
dest_1d[i] = 0xff000000 | (result + (result << 16) + (result << 8));
}
return dest_1d;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java-face人脸识别程序(代码) (122个子文件)
ImageXor.class 1KB
logo.gif 8KB
logo.gif 8KB
jidan.gif 2KB
jidan.gif 2KB
xianhua.gif 2KB
xianhua.gif 2KB
message.gif 1KB
message.gif 1KB
find.gif 1KB
find.gif 1KB
edit.gif 1KB
edit.gif 1KB
email.gif 1KB
email.gif 1KB
profile.gif 1KB
profile.gif 1KB
postnew.gif 975B
postnew.gif 975B
reply.gif 971B
reply.gif 971B
votenew.gif 950B
votenew.gif 950B
reply_a.gif 710B
reply_a.gif 710B
refresh.gif 664B
refresh.gif 664B
ofMale.gif 632B
ofMale.gif 632B
reply(1).gif 509B
reply(1).gif 509B
nextthread.gif 459B
nextthread.gif 459B
prethread.gif 456B
prethread.gif 456B
friend.gif 418B
friend.gif 418B
face18.gif 392B
face18.gif 392B
level10.gif 377B
level10.gif 377B
face9.gif 374B
face9.gif 374B
face8.gif 374B
face8.gif 374B
face12.gif 373B
face12.gif 373B
face1.gif 372B
face1.gif 372B
face17.gif 368B
face17.gif 368B
face15.gif 366B
face15.gif 366B
face6.gif 364B
face6.gif 364B
face14.gif 363B
face14.gif 363B
face11.gif 358B
face11.gif 358B
face13.gif 357B
face16.gif 357B
face16.gif 357B
face13.gif 357B
face5.gif 355B
face5.gif 355B
face10.gif 347B
face10.gif 347B
face4.gif 345B
face4.gif 345B
face7.gif 340B
face7.gif 340B
face3.gif 329B
face3.gif 329B
face2.gif 312B
face2.gif 312B
Forum_nav.gif 280B
Forum_nav.gif 280B
emailtofriend.gif 279B
emailtofriend.gif 279B
pag.gif 261B
pag.gif 261B
printpage.gif 249B
printpage.gif 249B
fav_add.gif 245B
fav_add.gif 245B
saveas.gif 227B
saveas.gif 227B
ip.gif 212B
ip.gif 212B
treeview.gif 186B
treeview.gif 186B
msg_no_new_bar.gif 177B
msg_no_new_bar.gif 177B
fav_add1.gif 159B
fav_add1.gif 159B
report.gif 152B
report.gif 152B
navspacer.gif 56B
navspacer.gif 56B
机器视觉论坛--ImageXor_java.htm 53KB
共 122 条
- 1
- 2
sophiasy
- 粉丝: 113
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页