顯示廣告
隱藏 ✕
看板 Knuckles
作者 Knuckles(阿德)
標題 Re: DIP的作業1
時間 2007年10月21日 Sun. PM 04:03:50


灰階圖使用Nearest-neighbor interpolation旋轉的方法
不會寫的話可以參考一下:
#include <math.h> //多加這個為了使用sin()、cos()、sqrt()

/* 讀取img1的過程省略 */

double pi = 3.1415926;
double angle = 0;
printf("請輸入順時針旋轉的角度:");
scanf("%lf", &angle); 
angle*=(pi/180); //角度換為徑度
int height3 = (int)(height1*sqrt(2.0));
int width3  = (int)(width1*sqrt(2.0));
int cy1 = height1/2, cx1 = width1/2;
int cy3 = height3/2, cx3 = width3/2;
CImage img3; //產生一個CImage物件
img3.Create(width3,height3,8); //建立一張8 bits per pixel的圖片

printf("Rotation using nearest-neighbor interpolation\n");
int x3,y3;
BYTE value;
for(y3=0; y3<height3; y3++){
    for(x3=0; x3<width3; x3++){
        x1 = (int)( (x3-cx3)*cos(angle)+(y3-cy3)*sin(angle))+cx1;
        y1 = (int)(-(x3-cx3)*sin(angle)+(y3-cy3)*cos(angle))+cy1;
        if(y1>=0 && y1<height1 && x1>=0 && x1<width1){
            value = img1.GetGrayPixel(x1,y1);
            img3.SetGrayPixel(x3,y3,value);
        }
    }
}
img3.SaveBmpFile("Rotate.bmp");
printf("已儲存為圖檔,檔名為Rotate.bmp\n");
--
※ 來源: 台大電信 DISP 實驗室 (http://disp.twbbs.org)
※ 作者: Knuckles  來自: 140.112.175.130  時間: 2007-10-21 16:03:50
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-21 16:04:17
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-21 16:04:37
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-21 16:08:20
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-21 16:08:34
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-05-31 15:14:17
※ 編輯: Knuckles  時間: 2010-10-23 04:39:55  來自: 111-248-0-184.dynamic.hinet.net
※ 同主題文章:
  10-10 16:32 Knuckles □ DIP的作業1
  10-17 02:39 Knuckles Re DIP的作業1
  10-17 21:53 Knuckles Re DIP的作業1
  10-21 14:40 Knuckles Re DIP的作業1
● 10-21 16:03 Knuckles Re DIP的作業1
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 673 
※ 文章分類: 程式設計 C/C++
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇