// BackGround.cpp: implementation of the CBackGround class. // ////////////////////////////////////////////////////////////////////// #include "BackGround.h" #include "PMImage.h" #include #include #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CBackGround::CBackGround() { } CBackGround::~CBackGround() { } CBackGround::CBackGround(int First, int Last) { char Filename[100]; char tmp[100]; int i, j, index; itoa(First, tmp, 10); if (First<10){ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); } else if (First< 100){ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); }else if (First<1000){ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); }else{ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); } CPMImage *Tempimg; Tempimg = new CPMImage(Filename); int ** BGSum; //new integer array BGSum = new int *[Tempimg->GetSizeX()]; for (i = 0; i < Tempimg->GetSizeX(); i ++) BGSum[i] = new int [Tempimg->GetSizeY()]; for ( i = 0; i GetSizeX(); i++ ){ for ( j = 0; j GetSizeY(); j++ ){ BGSum[i][j] = (int) ((double)Tempimg->r->GetXY(i,j) * 0.299+(double)Tempimg->g->GetXY(i,j) * 0.587+(double)Tempimg->b->GetXY(i,j) * 0.114); } } if (Last-First >= 1){ // for (index = First+1; index<=Last; index++){ itoa(index, tmp, 10); if (First<10){ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); } else if (First< 100){ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); }else if (First<1000){ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); }else{ strcpy(Filename, "ssip-"); strcat(Filename, tmp); strcat(Filename, ".pgm"); } Tempimg = new CPMImage(Filename); printf("%shphph\n", Filename); for ( i = 0; i GetSizeX(); i++ ){ for ( j = 0; j GetSizeY(); j++ ){ BGSum[i][j] += (int) ((double)Tempimg->r->GetXY(i,j) * 0.299+(double)Tempimg->g->GetXY(i,j) * 0.587+(double)Tempimg->b->GetXY(i,j) * 0.114); } } } } for ( i = 0; i GetSizeX(); i++ ){ for ( j = 0; j GetSizeY(); j++ ){ BGSum[i][j] = (int)(((double)BGSum[i][j]) / ((double)Last - First+1)); } } bg = new CPMImage(Tempimg->GetSizeX(), Tempimg->GetSizeY()); for ( i = 0; i GetSizeX(); i++ ){ for ( j = 0; j GetSizeY(); j++ ){ bg->r->SetXY(i,j, BGSum[i][j]); bg->g->SetXY(i,j, BGSum[i][j]); bg->b->SetXY(i,j, BGSum[i][j]); } } bg->Smooth(0); bg->SaveToPGMFile("bg.pgm"); }