GLvoid CreateImage (GLint ImageId) { GLint width, height; switch (ImageId) { case 1: width = 128; height = 128; ImageData1 = (GLint*) malloc (width * height * (sizeof (GLint))); ReadBmp ("kat_128_128.bmp",(unsigned char*) ImageData1, &TexWidth, &TexHeight); break; case 2: width = 74; height = 94; SubImageData1 = (GLint*) malloc (width * height * (sizeof (GLint))); ReadBmp ("Amoeba_74_94.bmp",(unsigned char*) SubImageData1, &TexWidth, &TexHeight); } }
int ocrProcessFile(char* fileName) { int i, h, w; uint32 **pix; createNetworkFromFile(); pix = ReadBmp(fileName, &h, &w); Image inputImg = getGrayLevel(pix, h, w); for(i = 0; i < h; i++) { free(pix[i]); } free(pix); ocrProcess(inputImg); return 0; }
void main() { int fmode=0; int i,j; int red[256]; int green[256]; int blue[256]; FILE *f; char *filename="text_gray.bmp"; ReadBmp(filename,&tmp1); printf("%d %d\n",tmp1.height,tmp1.width); while(1){ printf(" 0:モード法\n 1:判別分析法\n 2:移動平均法\n 3:終了\n"); scanf("%d",&fmode); if(fmode > 2) break; tmp2=tmp1; /* 元の画像ファイルのすべての画像データをコピーする */ reset( red, green, blue ); Gray( &tmp2 , &tmp1 ); set( red , green , blue ); switch(fmode){ case 0 : mode(red); //モード法 break; case 1 : sweep(red); //判別分析法 break; case 2 : mov_ave(red); //移動平均法 break; } WriteBmp("border.bmp",&tmp2); PrintBmpInfo("border.bmp"); } }
int main() { unsigned int iter; int dctin[64]; int dctout[64]; int quantizeout[64]; int zigzagout[64]; // preallocate memory for global variable unsigned char ScanBuffer[IMG_HEIGHT_MDU*8][IMG_WIDTH_MDU*8]; ReadBmp(ScanBuffer); for (iter = 0; iter < IMG_BLOCKS; iter++) { readblock(ScanBuffer, dctin); dct(dctin, dctout); quantize(dctout,quantizeout); zigzag(quantizeout, zigzagout); huffencode(zigzagout); } return 0; }
int autoTrainProcess(int nTrainImg, int nTestImg, double *mse) { int i, j, h, w, cnt = 0; //int nTrainChar[nTrainImg]; //int nTestChar[nTestImg]; int *nTrainChar = (int*)calloc(nTrainImg, sizeof(int)); int *nTestChar = (int*)calloc(nTestImg, sizeof(int)); //double ** trainFeature[nTrainImg]; double ***trainFeature = (double***)calloc(nTrainImg, sizeof(double**)); //double ** testFeature[nTestImg]; double ***testFeature = (double***)calloc(nTestImg, sizeof(double**)); uint32 **pix; FILE *f; //char *str_train[nTrainImg]; char **str_train = (char**)calloc(nTrainImg, sizeof(char*)); //char *str_test[nTestImg]; char **str_test = (char**)calloc(nTestImg, sizeof(char*)); char trainImgName[100]; char trainTxtName[100]; char testImgName[100]; char testTxtName[100]; /// read train image + text for(i = 0; i < nTrainImg; i++) { sprintf(trainTxtName, "train/%d.txt", i+1); f = fopen(trainTxtName, "r"); fscanf(f, "%d\n", &(nTrainChar[i])); str_train[i] = (char *) malloc(nTrainChar[i] *sizeof(char)); for(j = 0; j < nTrainChar[i]; j++) { fscanf(f, "%c", &(str_train[i][j])); } fclose(f); sprintf(trainImgName, "train/%d.bmp", i+1); pix = ReadBmp(trainImgName, &h, &w); if (pix == NULL) return -1; Image trainImg = getGrayLevel(pix, h, w); for(j = 0; j < h; j++) { free(pix[j]); } free(pix); trainImg = binarizeGrayImageKmeans(trainImg); trainFeature[i] = getFeatureFromImage(trainImg, nTrainChar[i]); } printf("start read test img\n"); /// read test img + text for(i = 0; i < nTestImg; i++) { sprintf(testTxtName, "test/%d.txt", i+1); f = fopen(testTxtName, "r"); fscanf(f, "%d\n", &(nTestChar[i])); str_test[i] = (char *) malloc(nTestChar[i] *sizeof(char)); for(j = 0; j < nTestChar[i]; j++) { fscanf(f, "%c", &(str_test[i][j])); printf("%c", str_test[i][j]); } fclose(f); sprintf(testImgName, "test/%d.bmp", i+1); pix = ReadBmp(testImgName, &h, &w); if (pix == NULL) return -1; Image testImg = getGrayLevel(pix, h, w); for(j = 0; j < h; j++) { free(pix[j]); } free(pix); testImg = binarizeGrayImageKmeans(testImg); testFeature[i] = getFeatureFromImage(testImg, nTestChar[i]); } /// init network randomly initNetwork(); double *outValue; double charMse, minCharMse = 10000; int trainComplete = 0; /// training process int nOver = 0; int saved = 0; char savedFileName[100]; printf("start training\n"); while (cnt < NUM_LOOP) { cnt++; /** processing feature data */ /// training network for (i = 0; i < nTrainImg; i++) { for(j = 0; j < nTrainChar[i]; j++) { outValue = getOutFromChar(str_train[i][j]); trainNetwork(trainFeature[i][j], outValue, 0.1); free(outValue); } } /// testing network charMse = 0; for (i = 0; i < nTestImg; i ++) { for (j = 0; j < nTestChar[i]; j++) { outValue = getOutFromChar(str_test[i][j]); charMse += testError(testFeature[i][j], outValue); free(outValue); } } /// check if train complete if (charMse < minCharMse) { nOver = 0; minCharMse = charMse; } else { if(nOver == 0) { ///save network to file saved = 1; sprintf(savedFileName, "%d_%.4lf.wdb", NUM_HID_CHAR, minCharMse); saveNetworkToFile(savedFileName); } printf("over\n"); nOver ++; if(nOver > 100) trainComplete = 1; } printf("%.2lf %d\n", charMse, cnt); if (trainComplete) break; } if(!saved) { sprintf(savedFileName, "%d_%.4lf.wdb", NUM_HID_CHAR, minCharMse); saveNetworkToFile(savedFileName); } if (mse != NULL) { *mse = minCharMse; } for (i = 0; i < nTrainImg; i++) { for (j = 0; j < nTrainChar[i]; j++) { free(trainFeature[i][j]); } } for (i = 0; i < nTestImg; i++) { for (j = 0; j < nTestChar[i]; j++) { free(testFeature[i][j]); } } return 0; }
bool Encryption(char *file_in_name){ //初期化 char *file_out_name;//画像の出力・入力ファイル名 char *key_out_file;//鍵ファイル char *buf; img *imagein, *imageout; int h, w; int i = 0; int registered_num = 0;//色の登録数 angou *code;//色を変換するテーブル FILE* fp; srand((unsigned)time(NULL)); file_out_name = (char *)malloc(sizeof(char)*(strlen(file_in_name) + 10)); strcpy(file_out_name, file_in_name); strcat(file_out_name, "_conv.bmp"); key_out_file = (char *)malloc(sizeof(char)*(strlen(file_in_name) + 8)); buf = (char *)malloc(sizeof(char)*(strlen(file_in_name) + 1)); strcpy(buf, file_in_name); strcpy(key_out_file, buf); strcat(key_out_file, "_key.kp"); imagein = (img *)malloc(sizeof(img)); imageout = (img *)malloc(sizeof(img)); ReadBmp(file_in_name, imagein); code = (angou *)malloc(sizeof(angou)*imagein->height*imagein->width); imageout = imagein; if ((fp = fopen(key_out_file, "w")) == NULL){ MessageBox(NULL, TEXT("key file output error."), NULL, MB_OK); return false; } //画像処理 for (h = 0; h < imagein->height; h++){ for (w = 0; w < imagein->width; w++){ for (i = 0; i <= registered_num; i++){ if (memcmp(&code[i].original_color, &imagein->data[h][w], sizeof(code[i].original_color)) == 0){ //登録してある色が見つかったら代入 imageout->data[h][w] = code[i].converted_color; goto searched_out; } } //変換する色の登録 //変換前の色を登録 code[registered_num].original_color = imagein->data[h][w]; try_again: //変換後の色を登録 code[registered_num].converted_color.r = rand() % 256; code[registered_num].converted_color.g = rand() % 256; code[registered_num].converted_color.b = rand() % 256; ///*変換後の色が既に登録してある色だったら // 変換後の色の登録をやり直す*/ for (i = 0; i < registered_num; i++){ if (memcmp(&code[registered_num].converted_color, &code[i].converted_color, sizeof(code[registered_num].converted_color)) == 0){ goto try_again; } } //出力画像に変換後の色を代入 imageout->data[h][w] = code[registered_num].converted_color; registered_num++; searched_out: ; } } fwrite(code, sizeof(angou), registered_num, fp);//鍵ファイルに変換情報を記録 WriteBmp(file_out_name, imageout); //後処理 fclose(fp); //free(file_out_name); /*free(key_out_file);*/ free(buf); free(code); return true; }