int main(int argc, char **argv){
	mode = 1;
	cout << "Enter image name : "; cin >> fileName;
	cout << "===================MODE==================\n";
	cout << "(0)shows histogram \n(1)global histogram equalization \n(2)local histogram equalization (window size 3)\n";
	cout << "Please enter mode : "; cin >> mode;
	if (bmp.read(fileName)){
		inBuf = bmp.getData();
		imageX = bmp.getWidth();
		imageY = bmp.getHeight();
	}else{
		cout << "==============================\n";
		cout << "|- Please check image name -|\n";
		cout << "==============================\n";
		exit(0);
	}

	histogram = calculate_histogram(inBuf, imageX, imageY); // hitung histogram 
	if (mode != 0){
		if (mode == 1){
			strcpy_s(newFileName, "global_equalization_");
			strcat_s(newFileName, fileName);
			perform_histogram_equalization(histogram, imageX, imageY); // histrogram equalization
		}
		else{
			strcpy_s(newFileName, "local_equalization_");
			strcat_s(newFileName, fileName);
			local_histogram_equalization(histogram, imageX, imageY, WINDOW_SIZE);
		}
		bmp.save(newFileName, imageX, imageY, 1, outBuf); // save new image 
		equalHistogram = calculate_histogram(outBuf, imageX, imageY); // new histogram
	}

	histoScale = (float)(imageY - 1) / getMaxHistogram(histogram, HISTOGRAM_SIZE);

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(imageX, imageY);
	glutInitWindowPosition(10, 10);
	glutCreateWindow("Histogram");
	Initialize();
	glutDisplayFunc(Draw);
	glutMainLoop();

	
	return 0;
}
Пример #2
0
///////////////////////////////////////////////////////////////////////////////
// load a BMP as texture
///////////////////////////////////////////////////////////////////////////////
unsigned int ModelGL::loadTextureBmp(const char* fileName)
{
    int chans, x, y;
    void* buf;
    Image::Bmp bmp;

    bmp.read(fileName);
    x = bmp.getWidth();
    y = bmp.getHeight();
    chans = bmp.getBitCount() / 8;
    buf = (void*)bmp.getDataRGB();

    // gen texture ID
    GLuint texture;
    glGenTextures(1, &texture);

    // set active texture and configure it
    glBindTexture(GL_TEXTURE_2D, texture);

    // select modulate to mix texture with color for shading
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // if wrap is true, the texture wraps over at the edges (repeat)
    //       ... false, the texture ends at the edges (clamp)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    // build our texture mipmaps
    switch(chans)
    {
    case 1:
        gluBuild2DMipmaps(GL_TEXTURE_2D, chans, x, y, GL_LUMINANCE, GL_UNSIGNED_BYTE, buf);
        break;
    case 3:
        gluBuild2DMipmaps(GL_TEXTURE_2D, chans, x, y, GL_RGB, GL_UNSIGNED_BYTE, buf);
        break;
    case 4:
        gluBuild2DMipmaps(GL_TEXTURE_2D, chans, x, y, GL_RGBA, GL_UNSIGNED_BYTE, buf);
        break;
    }

    return texture;
}
int main(){
	ifstream inFile;
	re = 0;
	cout << "Enter Retain Quantize : ";  cin >> re;
	char quan = 'y';
	cout << "Do you want to quantize ? (y/n) : ";  cin >> quan;
	if (quan == 'n'){
		quantizebool = false;
		quality = 1;
	}else{
		cout << "Enter Step Size : ";  cin >> quality;
	}
	entropylimit = re;
	inFile.open("LENA.raw", ios::binary);         // binary mode
	if (!inFile.good()){

		return false;
	}

	
	inFile.read((char*)ori, dataSize);
	bmp.save("LENA.bmp", 512, 512, 1, ori); // save new image 
	/*int aMatrix[8][8] = {
		{52,55,61,66,70,61,64,73},
		{63,59,55,90,109,85,69,72},
		{62,59,68,113,144,104,66,73},
		{63,58,71,122,154,106,70,69},
		{67,61,68,104,126,88,68,70},
		{79,65,60,70,77,68,58,75},
		{85,71,64,59,55,61,65,83},
		{87,79,69,68,65,76,78,94}
	};*/

	for (int x = 0; x < 512 * 512; x++){
		comp[x] = 0;
	}
	for (int i = 0; i < 512;){
		for (int j = 0; j < 512;){
			//Build 8x8 block
			for (int k = 0; k < 8; k++){
				for (int l = 0; l < 8; l++){
					//Extract int Value from Image
					matInt[l][k] = (int)ori[getValue(l + j, k + i,512)];
					//cout << matInt[l][k] << " ";
				}
				//cout << "\n";
			}//end 8x8 block
			//return 0;
			DCT(matInt);
			zigzagOrder(DCTMatrix);
			Quantize(zigzag, quality, re);

			int localcounter = 0;
			for (int k = 0; k < 8; k++){
				for (int l = 0; l < 8; l++){
					if (localcounter<entropylimit){
						probData5[counterData][localcounter] = quantI[k][l];
						localcounter++;
					}
					//cout << matInt[l][k] << " ";
				}
				//cout << "\n";
			}//end 8x8 block
			counterData++;

			IQuantize(quantI, quality, re);
			izigzagOrder(IquantI);
			IDCT(izigzag);
		
			for (int k = 0; k < 8; k++){
				for (int l = 0; l < 8; l++){
					//Extract int Value from Image
					comp[getValue(l + j, k + i, 512)] = IDCTMatrix[l][k];
					//cout << matInt[l][k] << " ";
				}
				//cout << "\n";
			}//end 8x8 block
			
			
			
			
			j = (j + 8);
		}
		i = (i + 8);
	}
	calcEntropy(entropylimit);
	/*DCT(aMatrix);
	Quantize(DCTMatrix, 16);
	zigzagOrder(quantI);
	cout << "\n";
	izigzagOrder(zigzag);*/
	//IQuantize(izigzag, 16);
	//IDCT(IquantI);
	
	double m = mse(ori, comp, 512);
	cout << "MSE : "<< m<<endl;
	bmp.save("LENAcom.bmp", 512, 512, 1, comp); // save new image 
	return 0;
}