Hi all,
Actually, I have read a data file of an image from its sub header stored the data in a buffer.*imdata is a pointer to the buffer for data. The data size is 100x100x81 and no. of bytes per pixel is 4 bytes and the format type is float. Now I have to read all the rowa and columns of 40th row in 3rd dimension. My problem is how to access it through this pointer imdata. Thanks in advance.
imsize_x=100;
imsize_y=100;
imsize_z=81;
nobytesperpixel=4;
I want to get all the elements 100x100 of z=40.
11 2425
I am a little confused by your question.
Is it that you have the value z=40 and you want to access another set of data that relates to this value?
Hi willakawill,
Sorry if I anot clear.I am just giving you an example of what I meant.
For eg: a[3][3][2]
a[ ][ ][1]={2,3,4; 1,2,3;4,5,6};
a[ ][ ][2]={1,1,1;2,2,2;3,3,3};
Now I would like to access all the rows and columns of a[ ][ ][2];
Here I have pointer to this buffer of data as I have mentioned before *imdata.So now I want to access these elemnts for eg: a[ ][ ] [40] using imdata.
Using two for loops, iterate through the first two dimensions of the matrix, using the indexes and 40 when reading data. Something like this: -
FOR (Index i, from 0 to X) {
-
FOR (Index j, from 0 to Y) {
-
READ imdata[i][j][40];
-
// DO STUFF...
-
}
-
}
where X and Y are the dimensions.
Hi,
I have declared the pointer as float *imgdata;
I just tried to check to display one value.
But when I say just cout<<imgdata[1][1][1] or cout<<*imgdata[1][1][1] it says
error C2109: subscript requires array or pointer type.
In case if I say imgdata[1000] it displays some value.
Could you please help me how I need to declare this pointer ?Am I doing something wrong?
Thank you very much for all your help.
you could define imgadata so
create the storage etc, then access the elements
I think (and pointers confuse me, especially when substituted with arrays) that if you want to have three indexes you need to warn the compiler that this is what you can do.....
That is, you can declare:
float [][][] imgdata; OR
float ***imgdata
BUT when you declare float *imgdata, the compiler doesn't understand why you add three indexes ("imgdata[1][1][1]")
Hi all,
Thank you all for the replies and your help.
Declaring the pointer can solve but actually my read function takes a pointer to single array like read(const *imgdata, imgsize).It says it cannot convert from float* to float***.I am thinking the read function takes the parameter as a pointer to 1D array and I cannot change this function as it is written by someone.
I have created the memory as
imgdata=new float[imgsize]; ///Thinking something wrong here
where imgsize is calculated as multiplication of all the dimensions = 1000(if data is 10x10x10).
Do you think the way I created memory is wrong?But I am thinking still my read function still cannot convert.
Could you give me any suggestions or any other options???Thanks in advance.
If you have to use a read function written by someone else, but you have to read/process the data as a 3D array, then I'd say you have a problem O.O
Not sure how to tackle this one...
I think declaring as float[1000], means that the data is considered as 1000 floats....
while using float[10][10][10] would still give 1000 floats, it is actually 10 arrays of 10 arrays of 10 floats (which I think is what you want)......
you could create your own way to access the data within your array of 1000 floats, but I'm not sure this is a particularly good idea, as it complicates the code (which introduces scope for extra errors).
Deman,
Thank you for all the options you have suggested.Actually I am trying to access it as single array.Thanks once again.
I think then you could cretae your own accessor methods to give the appearance of a 3d array
eg:
you have X elements in single array, and want to treat the array as a 3d array where a, b, c are the lengths of respective arrays (and therefore abc = X) then:
You need to be consistent with which value you use where, but basically any item in the array (can be accessed for some values i,j,k (all less than their a,b,c counterparts respecively) then the value in the array could be calculated as i*(b*c) + j*c + k (You can use other combinations to form this sum, but you need to be careful that the value you compare with a (ie i<=a) isn't multioplied by a.
This probably sounds confusing, but if we substitute 10 in for a,b,c so that X is 1000, then for i, j, k you would store at 100i + 10j + k, which is unique for any i, j, k less than a==b==c==10.,....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: SUPER_SOCKO |
last post by:
Suppose I have a matrix M x N dimension.
Normally, to print all of the elements in the matrix. I write the
following codes:
Suppose M = 5, N = 4:
for(int j=0; j<5; ++j) {
for(int k=0; k<4;...
|
by: Chris Styles |
last post by:
Dear All,
I've been using some code to verify form data quite happily, but i've
recently changed the way my form is structured, and I can't get it to work
now.
Originally :
The form is...
|
by: Thes |
last post by:
Hi all,
I have a 2d float array to which I have declared a pointer thus:
float Matrix = {/* snipped initialisation */ };
float (*StoredMatrix);
So as to create a copy in a program...
|
by: Jason Bell |
last post by:
Every example of properties I've seen have used simple types such as
integers and strings.
Here's the scenario I'm trying to work out (3D graphics programming):
I have a class called...
|
by: djhulme |
last post by:
Hi,
I'm using GCC. Please could you tell me, what is the maximum number of
array elements that I can create in C, i.e.
char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ;
I've...
|
by: deLenn |
last post by:
Hi,
Does scipy have an equivalent to Matlab's 'find' function, to list the
indices of all nonzero elements in a sparse matrix?
Cheers.
|
by: Michael Goerz |
last post by:
Hi,
What is the error in the code below? The output is:
DEBUG: matrix.b is 2.000000
DEBUG: matrix->b is 0.000000
In other words, the struct is empty after it is passed to the
solve_tridiag...
|
by: 8rea |
last post by:
Hello,
I have got a matrix and I want to get his elements so I can work with them in an unsigned int or in a similar way.
I have proved to get them with the method Element but it returns an...
|
by: Nezhate |
last post by:
Hi all,
Is there any way to print a matrix's elements using a simple printf ?
what I want as result is for example:
if mat ={0,1,2,3}
result must be: "0123".
I tried this code:
...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |