[vtkusers] vtkImageData to 3D CArray
Jothy
jothybasu at gmail.com
Tue Aug 23 12:30:04 EDT 2011
Hi David,
Now I realized the problem/limitation of multi-dimensional C array!
Since I could not find out any example in Google on how to create C arrays
with strides, I ended up in using boost multi_array.
It's quite good, but the problem is when the array dimensions increase to
about 500x500x500, I get a strange run time error. I googled about this and
found that the errors occurs when the system can't allocate CONTIGUOUS
MEMORY.
Now I realize the reason behind your suggestion to use arrays with strides.
I am resampling the vtkImageData to 1mm spacing from 2.5mm in all 3
dimensions. So there could be a factor of 8 increase in memory requirement.
I tried to set the scalar data type to float even.
I desperately need to use 1mm dimensions for my research.
I have only 2GB RAM on win XP. I will try on the other computer with higher
RAM.
Do you have any example or references for creating arrays with strides.
You were correct,C array are useless for image processing!
Thank you
Jothy
On Fri, Aug 19, 2011 at 5:29 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi Jothy,
>
> I'm not telling you to not use a C array. What I'm telling you is
> that you should use a 1D C array with strides for each dimension.
> Do not use a 3D C array. Read up on strides and learn how to use
> them. You'll thank me later.
>
> - David
>
>
> On Fri, Aug 19, 2011 at 10:23 AM, Jothy <jothybasu at gmail.com> wrote:
> > Thanks for your reply.
> >
> > I don't need to do any image processing with that C array. I need to get
> the
> > scalar values at [x,y,z] for a huge list of points from the vtkImageData
> > (they are randomly located). First I tried with
> > GetScalarComponentAsDouble(x,y,z,0).
> >
> > But it's too slow (for my purpose, 20-30 secs). After some Google search,
> I
> > came to know that acessing array with [] will be much faster that
> > GetscalarComponent.
> >
> > I even looked at vtkImageIterator, it only has methods span, begin,end.
> Most
> > importantly I need to copy those scalar values for later uses, so mere
> > scalar pointers won't help. That's why I am trying to do it with a c
> array.
> >
> > Jothy
> >
> > On Fri, Aug 19, 2011 at 5:15 PM, David Gobbi <david.gobbi at gmail.com>
> wrote:
> >>
> >> Hi Jothy,
> >>
> >> You probably don't want to create a 3D C array. In C, all dimensions
> >> of a C array except for the first dimension must be constant. So if
> >> you have variables N and M and you try doing this:
> >>
> >> short myarray[N][M];
> >>
> >> then you will get a compile error. Multidimensional C arrays are
> >> pretty much useless for image processing, people generally use a
> >> 1D array and strides/increments. Do a search for "array strides" on
> >> google.
> >>
> >> - David
> >>
> >> On Fri, Aug 19, 2011 at 9:54 AM, Jothy <jothybasu at gmail.com> wrote:
> >> > Hi all,
> >> >
> >> > I am trying to create a 3D C array form vtkImageData. I tried
> >> > vtkImageExport, but I seems like only exporting it as a 1D array. Is
> >> > there
> >> > any other filter or how to convert it to a 3D array? I am new to c++
> and
> >> > I
> >> > don't find any matrix manipulation function as in MATLAb or Python in
> c
> >> > std
> >> > lib.
> >> >
> >> > Thank you
> >> >
> >> > Jothy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110823/13dbc9e6/attachment.htm>
More information about the vtkusers
mailing list