- 最後登錄
- 2023-3-18
- 在線時間
- 0 小時
- 註冊時間
- 2012-5-6
- 閱讀權限
- 20
- 精華
- 0
- UID
- 11305296
- 帖子
- 237
- 積分
- 198 點
- 潛水值
- 26390 米
| 若有安裝色情守門員,可用無界、自由門等軟件瀏覽伊莉。或使用以下網址瀏覽伊莉: http://www.eyny.com:81/index.php 本帖最後由 sank910021 於 2016-2-21 10:56 PM 編輯
現在在做大學的專題,有牽涉到影像處理的部分,我是第一次用c++寫影像處理,所以有一些問題想請教!
程式:
- #include <iostream>
- #include <fstream>
- #define H 512
- #define W 512
- using namespace std;
- int main(){
- fstream input,output;
- unsigned int* Image = new unsigned int[H*W];
- unsigned char* ch = new unsigned char[H*W];
- input.open("LENA.RAW",ios::in | ios::binary);
- if(!input)
- cout << "Load failed!" << endl;
- else{
- input.read((char*)ch,H*W*sizeof(char));
- for(long int h=0;h<H*sizeof(char);h++)
- for(long int w=0;w<W*sizeof(char);w++)
- Image[h*W+w]=int(ch[h*W+w]);
- input.close();
- output.open("LENA2.txt",ios::out | ios::binary);
- for(long int h=0;h<H*sizeof(char);h++){
- for(long int w=0;w<W*sizeof(char);w++){
- output << Image[h*W+w] << " ";
- if(w == W-1)
- output << endl;
- }
- }
- output.close();
- }
- return 0;
- }
複製代碼 上面主要是將灰階的.raw檔案(LENA.RAW)的數值存入整數陣列中,範圍以灰階圖片來說應該是0~255,輸出後到.txt也都沒超出範圍
我想問的是在 "Image[h*W+w]=int(ch[h*W+w]);" 這行中,為何ch不必經過ASCII轉換呢?
另外如果有哪邊可以改進的部分也請各位大大指正出來,謝謝!
... |
|