[問題] 讀取大量txt檔會停止運作
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev c++ (很多版本)、Ubuntu g++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
1.在windows 下的dev C++ 完會出現sinogram.exe停止運作的視窗
2.在Ubuntu下 compile 產生執行檔 執行執行檔(指令我忘記了)後terminal沒反應
(要按ctrl+c)
3.由於不會動態記憶體跟pointer所以沒用到那些(禮拜一meeting要結果之後會在學
pointer 跟 dynamic memory allocation),跟人討論的結果是說有陣列的值沒有分配
到,但我在想會不會是因為計算量太大所以無法編譯?
大家可以先看我補充說明那邊我的code在幹嘛
-----------------------------------以下夾帶其他問題-------------------------
1.有沒有人能簡略說一下pointer跟dynamic memory allocation的功能是什麼,是要壓縮
記憶體使計算量不會那麼大嗎?
2.本魯蛇現在是碩一生,大學非電資相關科系,只有學過大一的c++(大概學了基本、迴圈
、副程式、陣列,而且只用過devc++ 跟codeblock)我知道我不會的東西還有物件
(class、struct),還有pointer相關,我們實驗室是做影像處理,不知道這兩個東西會
不會用到,或是還有其他我不知道的東西是必學的
3.我用ubuntu系統把課本上的code完完整整打上去(以前是用devc++、 code block)
compile不會過,有人知道為什麼嗎??
餵入的資料(Input):
201*201的txt陣列 phantom
以下是txt檔跟phontom的圖形
txt檔:https://mega.nz/#!F0Nk1a4J!jqeHi4n5-55Niap82BxAOxb5kHQZU-Gteh_-ycsbkHQ
phanotm:https://mega.nz/#!NtswQQZD!u3745ND4E7xE16eX-hlKyCW4uoZi8k8pdSqOhFXT7aA
預期的正確結果(Expected Output):
輸出一個 201*180的陣列在txt檔案中,再用matlab 畫圖。
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<fstream>
#include<math.h>
const double pi=3.14159265359;
//double interp2(double x_axis[][] , double y_axis[][], double phantom[][]
,double t_axis[][] ,bouble s_axis[][]);
int main()
{
using namespace std;
double x_axis[201][201],y_axis[201][201],phantom[201][201],sinogram[201][180];
ifstream ifile;
ofstream ofile;
ifile.open("phantomfinal.txt");
ofile.open("sinogram.txt");
for (int i=0; i<201 ; i++)
for (int j=0; j<201; j++)
ifile>>phantom[i][j];
for (int n=0 ; n<201 ; n++)
for (int k=0 ; k<180 ; k++)
sinogram[n][k]=0;
for(int j=0 ; j<201 ; j++)
{x_axis[0][j]=-1.0; y_axis[j][0]=1.0;}
for (int i=1;i<201 ;i++)
for (int j=1 ; j<201 ;j++)
{
x_axis[i][j]=x_axis[i-1][j]+0.01;
y_axis[i][j]= y_axis[i][j-1]-0.01;
}
for (int k=1 ; k<=180 ; k++)
{
//int k=1;
double project[201][201],t_axis[201][201],s_axis[201][201];
for (int m=0 ; m<201 ; m++)
for (int n=0 ; n<201 ; n++)
{
project[m][n]=0;
t_axis[m][n]=x_axis[m][n]*cos(pi/180*k)+y_axis[m][n]*sin(pi/180*k);
s_axis[m][n]=-x_axis[m][n]*sin(pi/180*k)+y_axis[m][n]*cos(pi/180*k);
}
for (int i=0 ; i<200 ; i++)
for (int j=0 ; j<200 ; j++)
for (int m=0 ; m<201 ; m++)
for (int n=0 ; n<201 ; n++)
{
if ( t_axis[m][n]>=x_axis[i][j] && t_axis[m][n]<=x_axis[i+1][j] &&
s_axis[m][n]<=y_axis[i][j] && s_axis[m][n]>=y_axis[i][j+1] )
{
double alpha , beta ,high_y ,low_y ;
alpha=t_axis[m][n]-x_axis[i][j];
beta =s_axis[m][n]-y_axis[i][j+1];
high_y=(1-alpha)*phantom[i+1][j]+alpha*phantom[i][j];
low_y =(1-alpha)*phantom[i+1][j+1]+alpha*phantom[i][j+1];
project[m][n]=(1-beta)*high_y+beta*low_y;
}
else
project[m][n]=0;
}
for ( int m=0 ; m<201 ; m++)
for ( int n=0 ; n<201 ; n++)
sinogram[m][k-1]=sinogram[m][k-1]+project[m][n];
}
for (int i=0 ; i<201 ; i++)
{
for (int j=0 ; j< 180; j++)
ofile<<sinogram[i][j]<<"\t";
ofile<<endl;
}
return 0;
}
/*
double interp2(double x_axis[][] , double y_axis[][], double phantom[][]
,double t_axis[][] ,bouble s_axis[][])
{
double project[201][201];
for (int i=0 ; i<201 ; i++)
for (int j=0 ; j<201 ; j++)
for (int m=0 ; m<201 ; m++)
for (int n=0 ; n<201 ; n++)
{
if ( t_axis[m][n]>=x_axis[i][j] && t_axis[m][n]<=x_axis[i+1][j] &&
s_axis[m][n]<=y_axis[i][j] && s_axis[m][n]>=y_axis[i][j+1] )
{
double alpha , beta ,high_y ,low_y ;
alpha=t_axis[m][n]-x_axis[i][j];
beta =s_axis[m][n]-y_axis[i][j+1];
high_y=(1-alpha)*phantom[i+1][j]+alpha*phantom[i][j];
low_y =(1-alpha)*phantom[i+1][j+1]+alpha*phantom[i][j+1];
project[m][n]=(1-beta)*high_y+beta*low_y;
}
else
project[m][n]=0;
}
return(project);
}
*/
(/部分是我本來要用副程式的寫法,但不會回傳就直接寫在main function)
(interp2也有上網找過code,但由於基礎不好看不懂就沒用了,想說自己用笨方法寫)
補充說明(Supplement):
1.這是一個FBP影像重建的FORWARD PROJECTION步驟,主要是先讀我做的一個201*201影像
(xy軸),然後從1到180度做投影(所謂的投影就是1~180度都打一到光,光的另一側有
dector接收每一個column相加的結果,所以每個dector都是一個201*1的陣列,然後會
有180個201*1的陣列,再將這些陣列疊成一個201*180的output),因為在數位的世界是
離散的,所以在座標旋轉後(ts軸)需要做bilinear interpolation至原來的201*201陣
列,而經旋轉沒有在201*201陣列中的點(ts軸)則assign為0
2.因為我自己檢察了很多次,不知道我code哪裡有問題(可能 interpolation2 的問題
或是把每個201*1的矩陣疊成201*180得矩陣,當然也有可能是別的問題),麻煩請高
手指點一下。
3.bilinearly interpolation 的部份我本來是想寫在副程式中再回傳回來,但那好像
要用到pointer的部分,還是有能人能提出什麼可以回傳一個2維陣列副程式的方法。
p.s.
第一次發文如果有什麼要改的請見量,由於禮拜一要meeting希望能趕出結果,能幫
我解決問題的人我可以送p幣!!然後如果發這文哪裡有問題的也請鞭小力點,小弟會改
進的><
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.71.242.242
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1442674206.A.5E5.html
→
09/19 23:08, , 1F
09/19 23:08, 1F
→
09/19 23:11, , 2F
09/19 23:11, 2F
→
09/19 23:12, , 3F
09/19 23:12, 3F
推
09/20 00:07, , 4F
09/20 00:07, 4F
推
09/20 00:11, , 5F
09/20 00:11, 5F
→
09/20 00:14, , 6F
09/20 00:14, 6F
→
09/20 00:15, , 7F
09/20 00:15, 7F
推
09/20 03:32, , 8F
09/20 03:32, 8F
推
09/20 11:12, , 9F
09/20 11:12, 9F
→
09/20 20:53, , 10F
09/20 20:53, 10F
→
09/20 20:56, , 11F
09/20 20:56, 11F
推
09/20 22:22, , 12F
09/20 22:22, 12F
推
09/20 22:27, , 13F
09/20 22:27, 13F
→
09/20 22:29, , 14F
09/20 22:29, 14F
→
09/21 00:12, , 15F
09/21 00:12, 15F
→
09/21 00:13, , 16F
09/21 00:13, 16F
→
09/21 01:14, , 17F
09/21 01:14, 17F
→
09/21 01:15, , 18F
09/21 01:15, 18F
→
09/21 17:29, , 19F
09/21 17:29, 19F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-3
16