Social Icons

twitterfacebookgoogle plusrss feedemail

4/14/2013

影像處理 -圖片濾光


影像主要由RGB所構成,如果要將一張彩色圖片過濾成只有單一顏色,只要將其它兩者設成0即可!



程式碼:

#include <iostream>
#include <cstdlib>

#include "bmp.h"

using namespace std;

int R[MaxBMPSizeX][MaxBMPSizeY];
int G[MaxBMPSizeX][MaxBMPSizeY];
int B[MaxBMPSizeX][MaxBMPSizeY];
int width, height;

int main(int argc, char* argv[])
{
    int x, y;
    // 加強值 
    int value;
    
    char* file_name;
    // 圖檔名稱 
    file_name = "Butterfly.bmp";
    
    // 開啟並讀取全彩(24bits)bmp 影像圖檔,如果是灰階影像只要存取RGB其中一項即可!
    // RGB 三個 channel 的值存入 R, G, B 三個自訂的陣列中
    // 陣列大小規定是 MaxBMPSizeX * MaxBMPSizeY
    // 同時取得該影像圖檔的高度和寬度
    open_bmp( file_name, R, G, B, width, height);

    // 影像處理(綠色濾光)
    for (x = 1 ; x < width-1 ; x++) {
        for (y = 1; y < height-1 ; y++) {

            // 去除R,B值, 保留G值 
            R[x][y] = 0;
            B[x][y] = 0;
        }
    }
    // 儲存處理結果至新的圖檔中
    save_bmp("new_filter.bmp", R, G, B);
    // 關閉 bmp 影像圖檔
    close_bmp();
    


    system("PAUSE");
    return 0;

}


下載點
載點1 載點2

(執行環境Visual C 2012 不能執行請重新編譯)

沒有留言:

張貼留言

俗話說
凡走過必留下痕跡,凡住過必留下鄰居
凡爬過必留下樓梯,凡來過必留下IP
看過文章之後歡迎留下您寶貴的意見喔!

 
 
无觅相关文章插件,迅速提升网站流量