#include #include #include #include "vision.h" #define WIDTH 320 #define HEIGHT 200 main(int argc, char *argv[]) { double input[WIDTH][HEIGHT]; double output[WIDTH][HEIGHT]; char filein[] = "object.pgm"; char fileout[] = "imagemove-t.pgm"; FILE *fpin, *fpout; int width, height; double angle, cosa, sina, distx, disty, expand; int oi, oj; /* ファイル filein を開く */ if ((fpin = fopen(filein,"r")) == NULL) { fprintf(stderr, "%s: cannot open %s\n", argv[0], filein); exit(1); } /* 画像 input をファイルポインタ fpin から読み込む */ imageRead(fpin, &width, &height, 0, 0, 1, 1, WIDTH, HEIGHT, &input[0][0]); /* ファイルを閉じる */ fclose(fpin); oi = width/2, oj = height/2; /* 座標中心(格子点) */ #if 1 distx = 100.00; disty = -50,00; /* 並進移動量 */ printf("[oi,oj] = [%d %d] [distx disty] = [ %lf %lf ]\n", oi, oj, distx, disty); imageTranslation(width, height, WIDTH, HEIGHT, oi, oj, 1.00, 1.00, &input[0][0], distx, disty, &output[0][0]); #endif #if 0 angle = M_PI/2; /* 回転角度 */ printf("[oi,oj] = [%d %d] angle = %lf\n", oi, oj, angle); cosa = cos(angle), sina = sin(angle); imageRotation(width, height, WIDTH, HEIGHT, oi, oj, 1.00, 1.00, &input[0][0], cosa, sina, &output[0][0]); #endif #if 0 expand = 0.50; /* 拡大率 */ printf("[oi,oj] = [%d %d] expand = %lf\n", oi, oj, expand); imageExpansion(width, height, WIDTH, HEIGHT, oi, oj, 1.00, 1.00, &input[0][0], expand, &output[0][0]); #endif /* ファイル fileout を開く */ if ((fpout = fopen(fileout,"w")) == NULL) { fprintf(stderr, "%s: cannot open %s\n", argv[0], fileout); exit(1); } /* 画像 output をファイルポインタ fpout に書き込む */ imageWrite(fpout, width, height, 0, 0, 1, 1, WIDTH, HEIGHT, &output[0][0]); /* ファイルを閉じる */ fclose(fpout); }