Hi Guys, I am having some problems implementing some things in C++. I currently have a text file which has the information for a picture within it... Here is some sample code to give you an idea:
1 2 3 4
|
0.0000000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000
0.0000000e+000 1.0000000e+000 1.0000000e+000 0.0000000e+000
1.0000000e+000 1.0000000e+000 1.0000000e+000 1.0000000e+000
1.0000000e+000 0.0000000e+000 0.0000000e+000 1.0000000e+000
|
Basically I have managed to read this into my C++ (console) program like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
double* readTxt(char *fileName, int sizeW, int sizeH)
{
double* data = new double[sizeW*sizeH];
int i=0;
ifstream mytxtfile (fileName);
if (mytxtfile.is_open())
{
while ( mytxtfile.good())
{
if (i>sizeW*sizeH-1) break;
mytxtfile >> *(data+i);
cout << *(data+i) << ' ';
i++;
}
mytxtfile.close();
}
else cout << "Unable to open file";
cout << i;
return data;
}
|
This leaves me with a double called 'data'. My Problem/Question is how do I get this into a matrix.
Say for example I am given a binary image 512x512, my goal is to read this in via a .txt file, put it in a 1 dimensional matrix representing the image, and then be able to split it into smaller 32x32 squares for analysis.
I have tried to make my problem as clear as possible. A simple Matrix class solution would suffice just to show me how to put it into a Matrix. From the research I have done I found the following code for making a new Matrix starting with 1000, I am just struggling to apply it to my problem:
1 2 3 4 5 6 7 8 9 10
|
Matrix::Matrix(int M, int N){
data = new double[M*N];
for (int i=0; i<M; i++){
for (int j=0; j<N; j++){
data[i*N+j] = (double) 1000 + i*N + j;
cout<<data[i*N+j]<<"\t";
}
cout<<"\n";
}
}
|
Thanks in advance for any help, I hope this isn't too advanced for the beginners section.