상하미러링
-서버오류인지 상하미러링과 좌우미러링이 반대로 된다...
public void lrImage(){
//영상 좌우 반전
outH = inH;
outW = inW;
outImage = new int[3][outH][outW];
//** Image Processing Algorithm **
for(int i=0;i<inH;i++){
for(int k=0;k<inW;k++){
outImage[0][i][k]=inImage[0][inH-i-1][k];
outImage[1][i][k]=inImage[1][inH-i-1][k];
outImage[2][i][k]=inImage[2][inH-i-1][k];
}
}
}
좌우미러링
public void lrImage(){
//영상 좌우 반전
outH = inH;
outW = inW;
outImage = new int[3][outH][outW];
//** Image Processing Algorithm **
for(int i=0;i<inH;i++){
for(int k=0;k<inW;k++){
outImage[0][i][k]=inImage[0][inH-i-1][k];
outImage[1][i][k]=inImage[1][inH-i-1][k];
outImage[2][i][k]=inImage[2][inH-i-1][k];
}
}
}
영상이동
-x축 이동과 y축이동이 반대로 되어 코드를 수정했다. 입력 받은 x와 y를 바꾸어 더해 주었다.
public void swapImage(){
//영상이동
int x = Integer.parseInt(para1);
int y = Integer.parseInt(para2);
outH = inH;
outW = inW;
outImage = new int[3][outH][outW];
//** Image Processing Algorithm **
for(int rgb=0;rgb<3;rgb++){
for(int i=0;i<inH;i++){
for(int k=0;k<inW;k++){
if((i+x)<outH && (k+y)<outW)
outImage[rgb][i+x][k+y]=inImage[rgb][i][k];
else break;
}
}
}
}
시계방향회전
public void rotateImage(){
int CenterH, CenterW, newH, newW , Val;
double Radian, PI;
// PI = 3.14159265358979;
PI = Math.PI;
int degree = Integer.parseInt(para1);
Radian = -degree * PI / 180.0;
outH = (int)(Math.floor((inW) * Math.abs(Math.sin(Radian)) + (inH) * Math.abs(Math.cos(Radian))));
outW = (int)(Math.floor((inW) * Math.abs(Math.cos(Radian)) + (inH) * Math.abs(Math.sin(Radian))));
CenterH = outH / 2;
CenterW = outW / 2;
outImage = new int[3][outH][outW];
for (int rgb = 0; rgb < 3; rgb++) {
for (int i = 0; i < outH; i++) {
for (int k = 0; k < outW; k++) {
newH = (int)((i - CenterH) * Math.cos(Radian) - (k - CenterW) * Math.sin(Radian) + inH / 2);
newW = (int)((i - CenterH) * Math.sin(Radian) + (k - CenterW) * Math.cos(Radian) + inW / 2);
if (newH < 0 || newH >= inH) {
//Val = 255;
outImage[0][i][k] = 55;
outImage[1][i][k] = 59;
outImage[2][i][k] = 68;
} else if (newW < 0 || newW >= inW) {
//Val = 255;
outImage[0][i][k] = 55;
outImage[1][i][k] = 59;
outImage[2][i][k] = 68;
} else {
Val = inImage[rgb][newH][newW];
outImage[rgb][i][k] = Val;
}
}
}
}
}
반시계방향회전
public void spinImage(){
int CenterH, CenterW, newH, newW , Val;
double Radian, PI;
// PI = 3.14159265358979;
PI = Math.PI;
int degree = Integer.parseInt(para1);
Radian = -degree * PI / 180.0;
outH = (int)(Math.floor((inW) * Math.abs(Math.cos(Radian)) + (inH) * Math.abs(Math.sin(Radian))));
outW = (int)(Math.floor((inW) * Math.abs(Math.cos(Radian)) + (inH) * Math.abs(Math.sin(Radian))));
CenterH = outH / 2;
CenterW = outW / 2;
outImage = new int[3][outH][outW];
for (int rgb = 0; rgb < 3; rgb++) {
for (int i = 0; i < outH; i++) {
for (int k = 0; k < outW; k++) {
newH = (int)((i - CenterH) * Math.cos(Radian) + (k - CenterW) * Math.sin(Radian) + inH / 2);
newW = (int)(-(i - CenterH) * Math.sin(Radian) + (k - CenterW) * Math.cos(Radian) + inW / 2);
if (newH < 0 || newH >= inH) {
//Val = 255;
outImage[0][i][k] = 55;
outImage[1][i][k] = 59;
outImage[2][i][k] = 68;
} else if (newW < 0 || newW >= inW) {
//Val = 255;
outImage[0][i][k] = 55;
outImage[1][i][k] = 59;
outImage[2][i][k] = 68;
} else {
Val = inImage[rgb][newH][newW];
outImage[rgb][i][k] = Val;
}
}
}
}
}
영상축소
원본 사진
|
V
결과 사진
public void zoomOutImage(){
//영상 축소
int scale = Integer.parseInt(para1);
outH = (int)inH/scale;
outW = (int)inW/scale;
outImage = new int[3][outH][outW];
//** Image Processing Algorithm **
for(int rgb=0;rgb<3;rgb++){
for(int i=0;i<inH;i++){
for(int k=0;k<inW;k++){
outImage[rgb][(int)(i/scale)][(int)(k/scale)]=inImage[rgb][i][k];
}
}
}
}
영상확대
원본 사진
|
V
결과 사진
public void zoomInImage(){
//영상 확대
int scale = Integer.parseInt(para1);
outH = inH*scale;
outW = inW*scale;
outImage = new int[3][outH][outW];
//** Image Processing Algorithm **
for(int rgb=0;rgb<3;rgb++){
for(int i=0;i<inH;i++){
for(int k=0;k<inW;k++){
outImage[rgb][i*scale][k*scale]=inImage[rgb][i][k];
}
}
}
}
영상확대(백워딩)
원본 사진
|
V
결과 사진
public void zoomInImage2(){
//영상확대(백워딩)
int scale = Integer.parseInt(para1);
outH = inH*scale;
outW = inW*scale;
outImage = new int[3][outH][outW];
//** Image Processing Algorithm **
for(int rgb=0;rgb<3;rgb++){
for(int i=0;i<outH;i++){
for(int k=0;k<outW;k++){
outImage[rgb][i][k]=inImage[rgb][(int)(i/scale)][(int)(k/scale)];
}
}
}
}
'JSP환경에서 OpenCV없는 컬러영상처리' 카테고리의 다른 글
히스토그램처리 (0) | 2022.09.29 |
---|---|
화소영역처리 (0) | 2022.09.29 |
화소점처리 (0) | 2022.09.29 |
JSP에서 이미지 받아오기 (0) | 2022.09.29 |
JSP클라이언트 코드 (0) | 2022.09.29 |