// affine.cpp : コンソール アプリケーションのエントリ ポイントを定義します。 // #include #include "pgmlib.h" #include #define PI 3.141592 void affine_size(int n, int n2); void affine_rot(int n, int n2); void affine_shift(int n, int n2); int main() { char file[256] = ""; load_image(0, file); affine_shift(0, 1); //affine_size(0,1); //affine_rot(0,1); save_image(1, file); return 0; } void affine_shift(int n, int n2) { int shift_x, shift_y; int size_x, size_y; int out_pos_x, out_pos_y; printf("x方向の移動量を入力してください.\n"); scanf("%d", &shift_x); printf("y方向の移動量を入力してください.\n"); scanf("%d", &shift_y); size_x = (int)(width[n]); size_y = (int)(height[n]); width[n2] = size_x; height[n2] = size_y; printf("出力画像サイズ:%d, %d\n", size_x, size_y); for (int j = 0; j < size_y; j++) { for (int i = 0; i < size_x; i++) { out_pos_y = j - shift_y; out_pos_x = i - shift_x; if (out_pos_x >= 0 && out_pos_x < width[n] && out_pos_y >= 0 && out_pos_y < height[n]) { image[n2][i][j] = image[n][out_pos_x][out_pos_y]; } } } printf("移動しました"); } void affine_size(int n, int n2) { double ratio_x, ratio_y; int size_x, size_y; double pos_x, pos_y; int out_pos_x, out_pos_y; printf("x方向の拡大/縮小率を入力してください.\n"); scanf("%lf", &ratio_x); printf("y方向の拡大/縮小率を入力してください.\n"); scanf("%lf", &ratio_y); size_x = (int)(ratio_x * (double)width[n] + 0.5); size_y = (int)(ratio_y * (double)height[n] + 0.5); width[n2] = size_x; height[n2] = size_y; printf("出力画像サイズ:%d, %d\n", size_x, size_y); for (int j = 0; j < size_y; j++) { for (int i = 0; i < size_x; i++) { pos_y = (double)j / ratio_y; pos_x = (double)i / ratio_x; out_pos_y = (int)(pos_y + 0.5); out_pos_x = (int)(pos_x + 0.5); if (out_pos_x >= 0 && out_pos_x < width[n] && out_pos_y >= 0 && out_pos_y < height[n]) { image[n2][i][j] = image[n][out_pos_x][out_pos_y]; } } } printf("サイズを変更しました.\n"); } void affine_rot(int n, int n2) { double ratio_x, ratio_y; int size_x, size_y; double deg; double pos_x, pos_y; int out_pos_x, out_pos_y; printf("回転角度を入力してください.\n"); scanf("%lf", °); size_x = (int)(width[n]); size_y = (int)(height[n]); width[n2] = size_x; height[n2] = size_y; printf("出力画像サイズ:%d, %d\n", size_x, size_y); for (int j = 0; j < size_y; j++) { for (int i = 0; i < size_x; i++) { pos_x = (double)(i * cos(deg * PI / 180.0)) + (double)(j * sin(deg * PI / 180.0)); pos_y = -(double)(i * sin(deg * PI / 180.0)) + (double)(j * cos(deg * PI / 180.0)); out_pos_y = (int)(pos_y + 0.5); out_pos_x = (int)(pos_x + 0.5); if (out_pos_x >= 0 && out_pos_x < width[n] && out_pos_y >= 0 && out_pos_y < height[n]) { image[n2][i][j] = image[n][out_pos_x][out_pos_y]; } } } printf("回転しました"); }