본문 바로가기

JSP환경에서 OpenCV없는 컬러영상처리

히스토그램처리

스트레칭

원본 사진 --> 결과 사진

public void strechImage(){
	//스트레칭
	outH = inH;
	outW = inW;
	outImage = new int[3][outH][outW];
	//** Image Processing Algorithm **
	int LOW = inImage[0][0][0],HIGH=inImage[0][0][0];
	for(int rgb=0;rgb<3;rgb++){
		for(int i=0;i<inH;i++)
			for(int k=0;k<inW;k++){
				if(LOW>inImage[rgb][i][k])
					LOW = inImage[rgb][i][k];
				if(HIGH<inImage[rgb][i][k])
					HIGH=inImage[rgb][i][k];
			}
	}
	for(int rgb=0;rgb<3;rgb++){
		for(int i=0;i<inH;i++){
			for(int k=0;k<inW;k++){
				double outa = (double)((inImage[rgb][i][k]-LOW)*255/(HIGH-LOW));
				if(outa<0.0)
					outa=0;
				else if(outa>255.0)
					outa=255;
				else
					outa=(int)outa;
				outImage[rgb][i][k] = (int)outa;
			}
		}
	}
}

 


엔드 -인

원본 사진 --> 결과 사진

public void endInImage(){
	//엔드-인
	outH = inH;
	outW = inW;
	outImage = new int[3][outH][outW];

	//** Image Processing Algorithm **

	int LOW = inImage[0][0][0],HIGH=inImage[0][0][0];
	for(int rgb=0;rgb<3;rgb++){
		for(int i=0;i<inH;i++)
			for(int k=0;k<inW;k++){
				if(LOW>inImage[rgb][i][k])
					LOW = inImage[rgb][i][k];
				if(HIGH<inImage[rgb][i][k])
					HIGH=inImage[rgb][i][k];
			}
	}
	LOW+=50;
	HIGH+=50;
	for(int rgb=0;rgb<3;rgb++){
		for(int i=0;i<inH;i++){
			for(int k=0;k<inW;k++){
				double outa = (double)((inImage[rgb][i][k]-LOW)*255/(HIGH-LOW));
				if(outa<0.0)
					outa=0;
				else if(outa>255.0)
					outa=255;
				else
					outa=(int)outa;
				outImage[rgb][i][k] = (int)outa;
			}
		}
	}
}

평활화

원본 사진 --> 결과 사진

public void equalizeImage(){
	//평활화
	outH=inH;
	outW=inW;

	outImage = new int[3][outH][outW];
	
	int histoR[] = new int[256];
	int histoG[] = new int[256];
	int histoB[] = new int[256];
	
	for(int i=0;i<256;i++){
		histoR[i]=0;
		histoG[i]=0;	
		histoB[i]=0;
	}
		

	for(int i=0;i<inH;i++)
		for(int k=0;k<inW;k++){
			histoR[inImage[0][i][k]]++;
			histoG[inImage[1][i][k]]++;
			histoB[inImage[2][i][k]]++;
		}


	int sumHistoR[] = new int[256];
	int sumHistoG[] = new int[256];
	int sumHistoB[] = new int[256];
	
	for(int i=0;i<256;i++){
		sumHistoR[i]=0;
		sumHistoG[i]=0;
		sumHistoG[i]=0;
	}

	int sumValueR=0;
	int sumValueG=0;
	int sumValueB=0;
	

	for(int i=0;i<256;i++){
		sumValueR += histoR[i];
		sumHistoR[i]=sumValueR;
		
		sumValueG += histoG[i];
		sumHistoG[i]=sumValueG;
		
		sumValueB += histoB[i];
		sumHistoB[i]=sumValueB;

	}

	double normalHistoR[] = new double[256];
	double normalHistoG[] = new double[256];
	double normalHistoB[] = new double[256];
	
	for(int i=0;i<256;i++){
		normalHistoR[i]=0.0;
		normalHistoG[i]=0.0;
		normalHistoB[i]=0.0;
	}

	for(int i=0;i<256;i++){
		double normalR = sumHistoR[i]*(1.0/(inH*inW))*255.0;
		normalHistoR[i] = normalR;
		double normalG = sumHistoG[i]*(1.0/(inH*inW))*255.0;
		normalHistoG[i] = normalG;
		double normalB = sumHistoB[i]*(1.0/(inH*inW))*255.0;
		normalHistoB[i] = normalB;
	}
	for(int rgb=0;rgb<3;rgb++){
		for(int i=0;i<inH;i++){
			for(int k=0;k<inW;k++){
				outImage[0][i][k]=(int)normalHistoR[inImage[0][i][k]];
				outImage[1][i][k]=(int)normalHistoG[inImage[1][i][k]];
				outImage[2][i][k]=(int)normalHistoB[inImage[2][i][k]];
			}
		}
}
	
}

 

'JSP환경에서 OpenCV없는 컬러영상처리' 카테고리의 다른 글

RGB-->HSV, HSV-->RGB  (0) 2022.09.29
화소영역처리  (0) 2022.09.29
기하학처리  (0) 2022.09.29
화소점처리  (0) 2022.09.29
JSP에서 이미지 받아오기  (0) 2022.09.29