顯示廣告
隱藏 ✕
看板 Knuckles
作者 Knuckles(阿德)
標題 Re: DIP的作業1
時間 2007年10月17日 Wed. PM 09:53:40


怕大家還是不會用那個CImage來讀寫圖片
來示範一下使用Nearest-neighbor interpolation做影像縮放的程式碼
#include <iostream>
#include "CImage.h"

void main()
{
    int x1,y1,x2,y2;
    CImage img1; //產生一個CImage物件
    img1.LoadBmpFile("lena.bmp"); // 載入圖片
    int height1 = img1.GetHeight(); // 取得圖檔的高
    int width1  = img1.GetWidth();  // 取得圖檔的寬

    double scale_h=0, scale_w=0;
    printf("請輸入高與寬的縮放比例:");
    scanf("%lf %lf", &scale_h, &scale_w); 
    int height2 = (int)(height1*scale_h + 0.5);
    int width2  = (int)(width1*scale_w + 0.5);
    CImage img2; //產生第二個CImage物件
    img2.Create(width2,height2,24); //建立一張24 bits per pixel的圖片

    printf("將圖形依高與寬的比例做縮放...\n");
    DWORD color; 
    for(y2=0; y2<height2; y2++){
        for(x2=0; x2<width2; x2++){
            x1 = (int)(x2/scale_w);
            y1 = (int)(y2/scale_h);
            color = img1.GetPixel(x1,y1);
            img2.SetPixel(x2,y2,color);
        }
    }
     
    img2.SaveBmpFile("lena2.bmp");
    printf("已儲存新的圖形,檔名為lena2.bmp\n");

    system("pause");
}

※ 引述《Knuckles》之銘言:
> 我有本C語言影像處理的書裡面有相關的內容
> 掃起來給大家參考一下
> C語言影像處理ch10
> ※ 引述《Knuckles》之銘言:
> > 洪一平的數位影像處理出作業囉
> > 課程網頁
> > Homework Assignment #1
> > Write a program for
> > • Digitally zoom-in an image using Nearest-neighbor interpolation
> >    Bilinear interpolation
> > • Rotating an image using Nearest-neighbor interpolation
> >    Bilinear interpolation
> > You will have to hand in the source code and a written
> > report (try different images, different parameters, and
> > discuss what you learn).
> > 有想要學用C++來寫的人
> > 先把VS2005裝一裝,然後把這個看一看吧
> > 用VS2005讀寫BMP圖檔教學
> > 以後有問題可以在這邊討論

--
※ 來源: 台大電信 DISP 實驗室 (http://disp.twbbs.org)
※ 作者: Knuckles  來自: 140.112.175.130  時間: 2007-10-17 21:53:40
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-17 21:54:02
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-17 21:54:58
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-17 22:12:42
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-20 23:53:45
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2007-10-21 18:48:09
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-05-31 15:07:01
※ 編輯: Knuckles  時間: 2010-10-23 04:39:07  來自: 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 累積人氣: 2939 
※ 文章分類: 程式設計 C/C++
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇