inunu 該用戶已被刪除 | 如果瀏覽伊莉時速度太慢或無法連接,可以使用其他分流瀏覽伊莉,www01.eyny.com(02,03)。 一般的影像處理會先定義一個資料結構來描述 pixel
其次, 沒有必要輸入輸出各跑自己的雙層夾心迴圈
摻在一起做成撒尿牛丸就行了
因此兩個 2D array 也沒有存在必要
我比較偏向這樣的精簡寫法
通常是要進行縮放, blur 或其它有資料相依性的處理才會讀全圖
- typedef struct
- {
- unsigned char gray;
- } PIXEL;
- int main(int argc, char *argv[])
- {
- fstream input;
- fstream output;
- int x = 0;
- int y = 0;
- input.open("LENA1.raw", ios::in | ios::binary);
- output.open("LENA2.txt", ios::out);
- while(!input.eof())
- {
- PIXEL pixel;
- input.read((char *)&pixel, sizeof(PIXEL));
- output << (int)pixel.gray << ' ';
- x++;
- if (x >= W)
- {
- output << endl;
- x = 0;
- y++;
- if (y >= H)
- {
- break;
- }
- }
- }
- input.close();
- output.close();
- return 0;
- }
複製代碼
...
|
|