// ------------------------------------------------------------------------ void LABHistogram2D::AddValue(CvScalar bgr) { double lab[3]; RGB2Lab(bgr.val[2], bgr.val[1], bgr.val[0], lab); if (lab[1] < a_min || lab[1] >= a_max || lab[2] < b_min || lab[2] >= b_max) return; int A = (int)((lab[1]-a_min)*a_bins/(a_max-a_min)); int B = (int)((lab[2]-b_min)*b_bins/(b_max-b_min)); float* value = cvGetHistValue_2D(h, A, B); (*value)++; }
void __fastcall TForm1::TabControl1Change(TObject *Sender) { switch( TabControl1 -> TabIndex ) { case 0: { TabControl1 -> Tabs -> Strings[ TabControl1 -> TabIndex ] = ExtractFileName( FileListBox1 -> FileName ); Image4 -> Picture -> LoadFromFile( FileListBox1 -> FileName ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } case 1: { char ToneOldFile[ 150 ]; strcpy( ToneOldFile, FileListBox1 -> FileName.c_str() ); sprintf( strrchr( ToneOldFile, '.' ), "_ToneOld.emf" ); if( !FileExists( ToneOldFile ) ) { char filename[ 150 ]; int LDomain[ 100 ]; int L_index; memset( LDomain, 0, sizeof( LDomain ) ); strcpy( filename, FileListBox1 -> FileName.c_str() ); ReadBMPData( filename ); for( int i = 0 ; i < imageHeight; i ++ ) for( int j = 0; j < imageWidth * 3; j += 3 ) { RGB2Lab( ImageDataBlock[ i ][ j + 0 ], ImageDataBlock[ i ][ j + 1 ], ImageDataBlock[ i ][ j + 2 ], &Lab_buf[ i ][ j + 0 ], &Lab_buf[ i ][ j + 1 ], &Lab_buf[ i ][ j + 2 ] ); L_index = ( int )( Lab_buf[ i ][ j + 0 ] + 0.5 ); LDomain[ L_index ] ++; } FILE *ToneOldData = fopen( "ToneOldData.dat", "w" ); // write L domain value in data file for( int i = 0; i <= 99; i ++ ) //if( LDomain[ i ] >= 300 ) fprintf( ToneOldData, "%d %d\n", i, LDomain[ i ] ); fclose( ToneOldData ); char PresentWorkingDirectory[ 150 ]; sprintf( PresentWorkingDirectory, "%s", ExtractFileDir( FileListBox1 -> FileName ) ); FILE *fp_domain_script = fopen( "histogram.dem", "w" ); fprintf( fp_domain_script, "cd '%s'\n", PresentWorkingDirectory ); fprintf( fp_domain_script, "set terminal emf\n" ); fprintf( fp_domain_script, "set xrange [ 0 : 100 ]\n" ); fprintf( fp_domain_script, "set xlabel 'L'\n" ); fprintf( fp_domain_script, "set ylabel 'intensity'\n" ); fprintf( fp_domain_script, "set grid\n" ); fprintf( fp_domain_script, "set output '%s'\n", ToneOldFile ); fprintf( fp_domain_script, "plot 'ToneOldData.dat' title '%s' with impulses 1 4\n", "ToneOld.dat" ); fclose( fp_domain_script ); char command[ 200 ]; sprintf( command, "%s\\gnuplot\\bin\\wgnuplot.exe histogram.dem", ExtractFileDrive( FileListBox1 -> FileName ) ); system( command ); remove( "histogram.dem" ); remove( "ToneOldData.dat" ); } Image4 -> Picture -> LoadFromFile( ToneOldFile ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } case 2: { char ToneOutPutFile[ 150 ]; strcpy( ToneOutPutFile, FileListBox1 -> FileName.c_str() ); sprintf( strrchr( ToneOutPutFile, '.' ), "_tone.bmp" ); if( !FileExists( ToneOutPutFile ) ) { char filename[ 150 ]; strcpy( filename, FileListBox1 -> FileName.c_str() ); ReadBMPData( filename ); MacroBlock block[ imageHeight / 16 ][ imageWidth / 16 ]; memset( block, 0, sizeof( block ) ); double LSum = 0; double aSum = 0; double bSum = 0; for( int i = 0; i < imageHeight / 16; i ++ ) for( int j = 0; j < imageWidth / 16; LSum = 0, aSum = 0, bSum = 0, j ++ ) { for( int k = i * 16; k <= ( i * 16 + 15 ); k ++ ) for( int m = j * 16 * 3; m <= ( j * 16 + 15 ) * 3; m += 3 ) { RGB2Lab( ImageDataBlock[ k ][ m + 0 ], ImageDataBlock[ k ][ m + 1 ], ImageDataBlock[ k ][ m + 2 ], &Lab_buf[ k ][ m + 0 ], &Lab_buf[ k ][ m + 1 ], &Lab_buf[ k ][ m + 2 ] ); LSum += Lab_buf[ k ][ m + 0 ]; aSum += Lab_buf[ k ][ m + 1 ]; bSum += Lab_buf[ k ][ m + 2 ]; } block[ i ][ j ].DCL = LSum / 256.0; block[ i ][ j ].DCa = aSum / 256.0; block[ i ][ j ].DCb = bSum / 256.0; } int num = 0; double L_sort[ Len_pri ]; // make Macroblock in one dimension for( int i = 1; i < imageHeight / 16 - 1; i ++ ) for( int j = 1; j < imageWidth / 16 - 1; j ++, num ++ ) L_sort[ num ] = block[ i ][ j ].DCL; // sort L from small to big exchange_sort( L_sort, Len_pri ); double WeightTotalFinal = 0; for( int i = 1; i < imageHeight / 16 - 1; i ++ ) for( int j = 1; j < imageWidth / 16 - 1; j ++ ) { block[ i ][ j ].WeightL = pow( block[ i ][ j ].DCL - block[ i - 1 ][ j - 1 ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i - 1 ][ j ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i - 1 ][ j + 1 ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i ][ j - 1 ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i ][ j + 1 ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i + 1 ][ j - 1 ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i + 1 ][ j ].DCL, 2 ) + pow( block[ i ][ j ].DCL - block[ i + 1 ][ j + 1 ].DCL, 2 ); block[ i ][ j ].Weighta = pow( block[ i ][ j ].DCa - block[ i - 1 ][ j - 1 ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i - 1 ][ j ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i - 1 ][ j + 1 ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i ][ j - 1 ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i ][ j + 1 ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i + 1 ][ j - 1 ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i + 1 ][ j ].DCa, 2 ) + pow( block[ i ][ j ].DCa - block[ i + 1 ][ j + 1 ].DCa, 2 ); block[ i ][ j ].Weightb = pow( block[ i ][ j ].DCb - block[ i - 1 ][ j - 1 ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i - 1 ][ j ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i - 1 ][ j + 1 ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i ][ j - 1 ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i ][ j + 1 ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i + 1 ][ j - 1 ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i + 1 ][ j ].DCb, 2 ) + pow( block[ i ][ j ].DCb - block[ i + 1 ][ j + 1 ].DCb, 2 ); block[ i ][ j ].WeightFinal = pow( block[ i ][ j ].WeightL * block[ i ][ j ].Weighta * block[ i ][ j ].Weightb, 0.5 ); WeightTotalFinal += block[ i ][ j ].WeightFinal; } double tone_L1; // every L of control point ( 0 ~ 100 ) double tone_L2; double tone_L3; double tone_L4; double tone_c1x = 10; // MacroBlock DCL weight sum accumulation ratio double tone_c2x = 30; double tone_c3x = 70; double tone_c4x = 90; double tone_wL1 = 0; // accumulate every DCL weight sum of control pointªºDCL weight sum, aim at final value double tone_wL2 = 0; double tone_wL3 = 0; double tone_wL4 = 0; // find out four ratios of WeightFinal, calculate corresponding DCL for( int p = 0; p < Len_pri; p ++ ) for( int i = 1; i < imageHeight / 16 - 1; i ++ ) for( int j = 1; j < imageWidth / 16 - 1; j ++ ) if( block[ i ][ j ].DCL == L_sort[ p ] ) { if( tone_wL1 < tone_c1x / 100 ) { tone_wL1 += block[ i ][ j ].WeightFinal / WeightTotalFinal; if( tone_wL1 >= tone_c1x / 100 ) tone_L1 = block[ i ][ j ].DCL; tone_wL2 += block[ i ][ j ].WeightFinal / WeightTotalFinal; tone_wL3 += block[ i ][ j ].WeightFinal / WeightTotalFinal; tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal; } else if( tone_wL1 >= tone_c1x / 100 && tone_wL2 < tone_c2x / 100 ) { tone_wL2 += block[ i ][ j ].WeightFinal / WeightTotalFinal; if( tone_wL2 >= tone_c2x / 100 ) tone_L2 = block[ i ][ j ].DCL; tone_wL3 += block[ i ][ j ].WeightFinal / WeightTotalFinal; tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal; } else if( tone_wL2 >= tone_c2x / 100 && tone_wL3 < tone_c3x / 100 ) { tone_wL3 += block[ i ][ j ].WeightFinal / WeightTotalFinal; if( tone_wL3 >= tone_c3x / 100 ) tone_L3 = block[ i ][ j ].DCL; tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal; } else if( tone_wL3 >= tone_c3x / 100 && tone_wL4 < tone_c4x / 100 ) { tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal; if( tone_wL4 >= tone_c4x / 100 ) tone_L4 = block[ i ][ j ].DCL; } } double tone_c1y = 20; // every L of control point should be adjust to value( 0 ~100 ) double tone_c2y = 40; double tone_c3y = 60; double tone_c4y = 80; // Tone Reproduction on L domain for( int p = 0; p < imageHeight; p ++ ) for( int q = 0; q < ( 3 * imageWidth ); q +=3 ) { if( Lab_buf[ p ][ q ] >= 0 && Lab_buf[ p ][ q ] < tone_L1 ) Lab_buf[ p ][ q ] = Lab_buf[ p ][ q ] * tone_c1y / tone_L1; else if( Lab_buf[ p ][ q ] >= tone_L1 && Lab_buf[ p ][ q ] < tone_L2 ) Lab_buf[ p ][ q ] = tone_c1y + ( Lab_buf[ p ][ q ] - tone_L1 ) * ( tone_c2y - tone_c1y ) / ( tone_L2 - tone_L1 ); else if( Lab_buf[ p ][ q ] >= tone_L2 && Lab_buf[ p ][ q ] < tone_L3) Lab_buf[ p ][ q ] = tone_c2y + ( Lab_buf[ p ][ q ] - tone_L2 ) * ( tone_c3y - tone_c2y ) / ( tone_L3 - tone_L2 ); else if( Lab_buf[ p ][ q ] >= tone_L3 && Lab_buf[ p ][ q ] < tone_L4 ) Lab_buf[ p ][ q ] = tone_c3y + ( Lab_buf[ p ][ q ] - tone_L3 ) * ( tone_c4y - tone_c3y ) / ( tone_L4 - tone_L3 ); else Lab_buf[ p ][ q ] = tone_c4y + ( Lab_buf[ p ][ q ] - tone_L4 ) * ( 100 - tone_c4y ) / ( 100 - tone_L4 ); // Lab to RGB Lab2RGB( Lab_buf[ p ][ q + 0 ], Lab_buf[ p ][ q + 1 ], Lab_buf[ p ][ q + 2 ], &ucImageOut[ p ][ q + 0 ], &ucImageOut[ p ][ q + 1 ], &ucImageOut[ p ][ q + 2 ] ); } FILE *outfp = fopen( ToneOutPutFile, "wb" ); fwrite( &header1, 14, 1, outfp ); fwrite( &header2, 40, 1, outfp ); for( int i = 0; i < imageHeight; i ++ ) fwrite( ucImageOut[ i ], 3 * imageWidth, 1, outfp ); fclose( outfp ); } Image4 -> Picture -> LoadFromFile( ToneOutPutFile ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } } }
void __fastcall TForm1::TabControl1Change(TObject *Sender) { switch( TabControl1 -> TabIndex ) { case 0: { if( !FileExists( "MeanFile.txt" ) || !FileExists( "standardDeviation.txt" ) ) { char filename[ 150 ]; MacroBlock MeanBlock[ imageHeight / 16 ][ imageWidth / 16 ]; MacroBlock block[ imageHeight / 16 ][ imageWidth / 16 ]; for( int n = 0; n < FileListBox1 -> Items -> Count; n ++ ) { memset( block, 0, sizeof( block ) ); memset( MeanBlock, 0, sizeof( MeanBlock ) ); sprintf( filename, "%s%s", ExtractFilePath( FileListBox1 -> FileName ), FileListBox1 -> Items -> Strings[ n ].c_str() ); ReadBMPData( filename ); double LSum = 0; for( int i = 0; i < imageHeight / 16; i ++ ) for( int j = 0; j < imageWidth / 16; LSum = 0, j ++ ) { for( int k = i * 16; k <= ( i * 16 + 15 ); k ++ ) for( int m = j * 16 * 3; m <= ( j * 16 + 15 ) * 3; m += 3 ) { RGB2Lab( ImageDataBlock[ k ][ m + 0 ], ImageDataBlock[ k ][ m + 1 ], ImageDataBlock[ k ][ m + 2 ], &Lab_buf[ k ][ m + 0 ], &Lab_buf[ k ][ m + 1 ], &Lab_buf[ k ][ m + 2 ] ); LSum += Lab_buf[ k ][ m + 0 ]; } block[ i ][ j ].DCL = LSum / 256.0; MeanBlock[ i ][ j ].DCL += block[ i ][ j ].DCL; AllDCL[ n ][ i ][ j ] = block[ i ][ j ].DCL; } } for( int i = 0; i < imageHeight / 16; i ++ ) for( int j = 0; j < imageWidth / 16; j ++ ) MeanBlock[ i ][ j ].DCL /= FileListBox1 -> Items -> Count; FILE *MeanFile = fopen( "MeanFile.txt", "w" ); for( int i = 0; i < imageHeight / 16; i ++ ) { for( int j = 0; j < imageWidth / 16; j ++ ) fprintf( MeanFile, "%f ", MeanBlock[ i ][ j ].DCL ); fprintf( MeanFile, "\n" ); } fclose( MeanFile ); for( int i = 0; i < 100; i ++ ) for( int j = 0; j < imageHeight / 16; j ++ ) for( int k = 0; k < imageWidth / 16; k ++ ) stddev[ j ][ k ] += pow( AllDCL[ i ][ j ][ k ] - MeanBlock[ j ][ k ].DCL, 2 ); for( int i = 0; i < imageHeight / 16; i ++ ) for( int j = 0; j < imageWidth / 16; j ++ ) stddev[ i ][ j ] = pow( stddev[ i ][ j ] / ( FileListBox1 -> Items -> Count - 1 ), 0.5 ); FILE *StandardDeviation = fopen( "standardDeviation.txt", "w" ); for( int i = 0; i < imageHeight / 16; i ++ ) { for( int j = 0; j < imageWidth / 16; j ++ ) fprintf( StandardDeviation, "%f ", stddev[ i ][ j ] ); fprintf( StandardDeviation, "\n" ); } fclose( StandardDeviation ); } break; } } }
void __fastcall TForm1::TabControl1Change(TObject *Sender) { switch( TabControl1 -> TabIndex ) { case 0: { TabControl1 -> Tabs -> Strings[ TabControl1 -> TabIndex ] = ExtractFileName( FileListBox1 -> FileName ); Image4 -> Picture -> LoadFromFile( FileListBox1 -> FileName ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } case 1: case 2: { char histogram_file[ 100 ]; char ec_file[ 100 ]; char PresentWorkingDirectory[ 100 ]; strcpy( histogram_file, FileListBox1 -> FileName.c_str() ); strcpy( ec_file, FileListBox1 -> FileName.c_str() ); sprintf( PresentWorkingDirectory, "%s", ExtractFileDir( FileListBox1 -> FileName ) ); if( TabControl1 -> TabIndex == 1 ) { sprintf( strrchr( histogram_file, '.' ), "_histogram.emf" ); if( FileExists( histogram_file ) ) { Image4 -> Picture -> LoadFromFile( histogram_file ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } } else // TabControl1 -> TabIndex == 2 { sprintf( strrchr( ec_file, '.' ), "_ec.emf" ); if( FileExists( ec_file ) ) { Image4 -> Picture -> LoadFromFile( ec_file ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } } FILE *fp_domain_data; FILE *fp_domain_script; int abDomain[ 185 ][ 203 ]; unsigned int a_index; unsigned int b_index; double aSum = 0; double bSum = 0; double aMean; double bMean; double offset; double aVariance; double bVariance; double radius; double intensity; memset( abDomain, 0, sizeof( abDomain ) ); ReadBMPData( FileListBox1 -> FileName.c_str() ); for( int i = 0; i < imageHeight; i++ ) for( int j = 0; j < imageWidth * 3; j += 3 ) { RGB2Lab( ImageDataBlock[ i ][ j + 0 ], ImageDataBlock[ i ][ j + 1 ], ImageDataBlock[ i ][ j + 2 ], &Lab_buf[ i ][ j + 0 ], &Lab_buf[ i ][ j + 1 ], &Lab_buf[ i ][ j + 2 ] ); aSum += Lab_buf[ i ][ j + 1 ]; bSum += Lab_buf[ i ][ j + 2 ]; a_index = ( int )( Lab_buf[ i ][ j + 1 ] + 0.5 ) + 86; b_index = ( int )( Lab_buf[ i ][ j + 2 ] + 0.5 ) + 108; abDomain[ a_index ][ b_index ]++; } fp_domain_data = fopen( "histogram.dat", "w" ); // write ab domain value in data file for( int i = 0; i <= 184; i ++ ) for( int j = 0; j <= 202; j ++ ) if( abDomain[ i ][ j ] != 0 ) fprintf( fp_domain_data, "%d %d %d\n", i - 86, j - 108, abDomain[ i ][ j ] ); fclose( fp_domain_data ); fp_domain_script = fopen( "histogram.dem", "w" ); fprintf( fp_domain_script, "cd '%s'\n", PresentWorkingDirectory ); fprintf( fp_domain_script, "set terminal emf color\n" ); fprintf( fp_domain_script, "set xrange [ -86 : 98 ]\n" ); fprintf( fp_domain_script, "set yrange [ -108 : 94 ]\n" ); fprintf( fp_domain_script, "set xlabel 'a'\n" ); fprintf( fp_domain_script, "set ylabel 'b'\n" ); fprintf( fp_domain_script, "set grid\n" ); if( TabControl1 -> TabIndex == 1 ) { fprintf( fp_domain_script, "set zlabel 'intensity'\n\n" ); fprintf( fp_domain_script, "set title '2D histogram in the ab plane'\n" ); fprintf( fp_domain_script, "set ticslevel 0\n" ); fprintf( fp_domain_script, "set output '%s'\n", histogram_file ); fprintf( fp_domain_script, "splot 'histogram.dat' title '%s' with lines\n\n", histogram_file ); } else // TabControl1 -> TabIndex == 2 { aMean = aSum / ( imageHeight * imageWidth ); bMean = bSum / ( imageHeight * imageWidth ); offset = pow( aMean * aMean + bMean * bMean, 0.5 ); aSum = 0; bSum = 0; for( int i = 0; i <= 184; i ++ ) for( int j = 0; j <= 202; j ++ ) if( abDomain[ i ][ j ] != 0 ) { aSum += pow( aMean - ( i - 86 ), 2 ) * abDomain[ i ][ j ]; bSum += pow( bMean - ( j - 108 ), 2 ) * abDomain[ i ][ j ]; } aVariance = aSum / ( imageHeight * imageWidth ); bVariance = bSum / ( imageHeight * imageWidth ); radius = pow( aVariance + bVariance, 0.5 ); intensity = ( offset - radius ) / radius; fprintf( fp_domain_script, "set parametric\n" ); fprintf( fp_domain_script, "set output '%s'\n", ec_file ); fprintf( fp_domain_script, "set arrow to %f, %f\n", aMean, bMean ); fprintf( fp_domain_script, "set title 'Equivalent circle'\n" ); if( aMean >= 0 && bMean >= 0 ) // first quadrant { fprintf( fp_domain_script, "set label 'offset = %f' at -10, -10\n", offset ); fprintf( fp_domain_script, "set label 'radius = %f' at -10, -20\n", radius ); fprintf( fp_domain_script, "set label 'intensity = %f' at -10, -30\n", intensity ); } else if( aMean <= 0 && bMean >= 0 ) // second quadrant { fprintf( fp_domain_script, "set label 'offset = %f' at 10, -10\n", offset ); fprintf( fp_domain_script, "set label 'radius = %f' at 10, -20\n", radius ); fprintf( fp_domain_script, "set label 'intensity = %f' at 10, -30\n", intensity ); } else if( aMean <= 0 && bMean <= 0 ) // third quadrant { fprintf( fp_domain_script, "set label 'offset = %f' at 10, 30\n", offset ); fprintf( fp_domain_script, "set label 'radius = %f' at 10, 20\n", radius ); fprintf( fp_domain_script, "set label 'intensity = %f' at 10, 10\n", intensity ); } else // fourth quadrant { fprintf( fp_domain_script, "set label 'offset = %f' at -10, 30\n", offset ); fprintf( fp_domain_script, "set label 'radius = %f' at -10, 20\n", radius ); fprintf( fp_domain_script, "set label 'intensity = %f' at -10, 10\n", intensity ); } fprintf( fp_domain_script, "plot [ 0 : 2 * pi ] %f * sin( t ) + %f, %f * cos( t ) + %f title '%s'\n", radius, aMean, radius, bMean, ec_file ); } fclose( fp_domain_data ); char command[ 200 ]; sprintf( command, "%s\\gnuplot\\bin\\wgnuplot.exe %s\\histogram.dem", ExtractFileDrive( FileListBox1 -> FileName ), PresentWorkingDirectory ); system( command ); if( TabControl1 -> TabIndex == 1 ) Image4 -> Picture -> LoadFromFile( histogram_file ); else // TabControl1 -> TabIndex == 2 Image4 -> Picture -> LoadFromFile( ec_file ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; remove( "histogram.dat" ); remove( "histogram.dem" ); break; } } }
// ------------------------------------------------------------------------ double LABHistogram2D::GetValue(CvScalar bgr) { double lab[3]; RGB2Lab(bgr.val[2], bgr.val[1], bgr.val[0], lab); return GetValue(lab[1], lab[2]); }
void __fastcall TForm1::TabControl1Change(TObject *Sender) { switch( TabControl1 -> TabIndex ) { case 0: case 1: case 2: case 3: case 4: case 5: { char CIELabChartFileName[ 150 ]; int LValue; switch( TabControl1 -> TabIndex ) { case 0: strcpy( CIELabChartFileName, "CIELabChartL0.BMP" ); LValue = 0; break; case 1: strcpy( CIELabChartFileName, "CIELabChartL25.BMP" ); LValue = 25; break; case 2: strcpy( CIELabChartFileName, "CIELabChartL50.BMP" ); LValue = 50; break; case 3: strcpy( CIELabChartFileName, "CIELabChartL75.BMP" ); LValue = 75; break; case 4: strcpy( CIELabChartFileName, "CIELabChartL90.BMP" ); LValue = 90; break; case 5: strcpy( CIELabChartFileName, "CIELabChartL100.BMP" ); LValue = 100; break; } if( !FileExists( CIELabChartFileName ) ) { for( int i = 0; i < imageHeight; i ++ ) for( int j = 0; j < imageWidth * 3; j += 3 ) { ImageDataBlock[ i ][ j + 0 ] = 255; ImageDataBlock[ i ][ j + 1 ] = 255; ImageDataBlock[ i ][ j + 2 ] = 255; } double L; double a; double b; //FILE *test = fopen( "test.dat", "w" ); for( int R = 0; R <= 255; R ++ ) for( int G = 0; G <= 255; G ++ ) for( int B = 0; B <= 255; B ++ ) { RGB2Lab( ( unsigned char )B, ( unsigned char )G, ( unsigned char )R, &L, &a, &b ); if( L >= LValue - 1 && L <= LValue + 1 ) { //fprintf( test, "R = %d, G = %d, B = %d, L = %f, a = %f, b = %f\n", R, G, B, L, a, b ); ImageDataBlock[ ( int )( b + 107 + 0.5 ) ][ ( int )( a + 86 + 0.5 ) * 3 + 0 ] = ( unsigned char )B; ImageDataBlock[ ( int )( b + 107 + 0.5 ) ][ ( int )( a + 86 + 0.5 ) * 3 + 1 ] = ( unsigned char )G; ImageDataBlock[ ( int )( b + 107 + 0.5 ) ][ ( int )( a + 86 + 0.5 ) * 3 + 2 ] = ( unsigned char )R; } } // fclose( test ); // plot a axis for( int j = 0; j < imageWidth * 3; j += 3 ) { ImageDataBlock[ 107 ][ j + 0 ] = 0; // B element ImageDataBlock[ 107 ][ j + 1 ] = 0; // G element ImageDataBlock[ 107 ][ j + 2 ] = 0; // R element } // plot b axis for( int i = 0; i < imageHeight; i ++ ) { ImageDataBlock[ i ][ 86 * 3 + 0 ] = 0; // B element ImageDataBlock[ i ][ 86 * 3 + 1 ] = 0; // G element ImageDataBlock[ i ][ 86 * 3 + 2 ] = 0; // R element } FILE *fp = fopen( CIELabChartFileName, "wb" ); fwrite( &header1.bfType, 2, 1, fp ); fwrite( &header1.bfSize, 4, 1, fp ); fwrite( &header1.bfReserved1, 2, 1, fp ); fwrite( &header1.bfReserved2, 2, 1, fp ); fwrite( &header1.bfOffBits, 4, 1, fp ); fwrite( &header2, sizeof( BitMapInfoHeader ), 1, fp ); for( int i = 0; i < imageHeight; i ++ ) fwrite( ImageDataBlock[ i ], 3 * imageWidth, 1, fp ); fclose( fp ); } TabControl1 -> Tabs -> Strings[ TabControl1 -> TabIndex ] = ExtractFileName( CIELabChartFileName ); Image4 -> Picture -> LoadFromFile( CIELabChartFileName ); TabControl1->Width=Image4->Picture->Width; TabControl1->Height=Image4->Picture->Height; break; } } }