[MINC-users] Reading time-width data with minc2 API

EJ Nikelski nikelski at bic.mni.mcgill.ca
Mon Aug 10 13:27:42 EDT 2009


Hi Claude (and List),

   Thanks for the suggestion. I did as you suggested and commented out
the malloc in libsrc2/dimension.c and rebuilt using minc-2.0.18.  No
success, however, after tossing in liberal printf's I found that it's
going here ...

  if (dimension->widths == NULL) {
    for (i=start_position; i <= diff; i++) {
      widths[j] = dimension->width;
      j++;
    }
  }

In other words, it's returning zeros because the dimension->widths
pointer is null.  So either the pointer is not being initialized, or
"miget_dimension_widths" does not do what I expect it to do --- which
in this case is return the 34 time-width values from the volume.  The
API does not seem to suggest any other obvious routines, although, all
we really need is to be able to read the values from the "time-width"
variable. I feel like I'm missing something really obvious.

Suggestions?

-Jim



On Fri, Aug 7, 2009 at 7:45 PM, Claude LEPAGE<claude at bic.mni.mcgill.ca> wrote:
> Hi Jim,
>
> ok, this one looks like a bug to me.
>
> See libsrc2/dimension.c:
>
> miget_dimension_widths(midimhandle_t dimension,
>                       mivoxel_order_t voxel_order,
>                       unsigned long array_length,
>                       unsigned long start_position,
>                       double widths[])
> {
>
>  /* Allocate space for the widths array
>   */
>  widths = (double *) malloc(diff*sizeof(double));
>
>    for (i=start_position; i <= diff; i++) {
>      widths[j] = dimension->width;
>      j++;
>    }
>
> Well, the memory has been allocated from outside, so this malloc
> simply redefines widths to be some new location in memory. It ends
> up that your array is not updated.
>
> As a quick fix, try to comment out the above malloc line in your
> minc2 library, then rebuild minc2 and relink your application.
>
> If widths is to be allocated from within this function (bad idea),
> then you need to pass a double * widths[] and assign it as
> *widths = (double*)malloc(...);
>
> Let me know if this works so that I can commit the change in cvs.
>
> By the way *** IMPORTANT ***, since you are using 4-D volumes, please
> update to minc-2.0.18 which fixes internal compression for 4-D volumes.
> For some images (fMRI, DTI), this is the difference between 90 minutes
> vs 15 seconds to read a volume.
>
> bye
>
> Claude
>
>
>
>
>> Hi List (yet again),
>>
>>    I have a 4-d volume (time, zspace, yspace, xspace) and I need to
>> read the time-related information, specifically the offset and width
>> info.  Looking at the volume itself, I can see 34 values each for the
>> "time" and "time-width" variables.
>>
>> "miget_dimension_offsets" (minc2 API) had no trouble pulling in the 34
>> "time" values, however, I'm stumped on how to read in the 34
>> "time-width" values.  I tried "miget_dimension_widths" and got zeros.
>> Am I using the correct API call?  Here's what I'm doing ...
>>
>> -----------------------------------------------------------
>> midimhandle_t         *dimensions;
>> double                        time_widths[34];
>>
>> result = miget_dimension_widths(dimensions[0], MI_ORDER_FILE, 34, 0,
>> time_widths);
>> if ( result == MI_ERROR ) { error("Error returned from
>> miget_dimension_widths.\n"); }
>> -----------------------------------------------------------
>>
>>    Forgive the hard-coding of 34 ... I'm testing.  My immediately
>> preceding call to "miget_dimension_offsets" (also using dimensions[0])
>> worked just fine.  Any idea what's going on here?
>>
>> Thanks,
>>
>> -Jim
>>
>> --
>> =================================
>> Jim Nikelski, Ph.D.
>> Postdoctoral Research Fellow
>> Bloomfield Centre for Research in Aging
>> Lady Davis Institute for Medical Research
>> Sir Mortimer B. Davis - Jewish General Hospital
>> McGill University
>> _______________________________________________
>> MINC-users at bic.mni.mcgill.ca
>> http://www2.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>>
> _______________________________________________
> MINC-users at bic.mni.mcgill.ca
> http://www2.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>



-- 
=================================
Jim Nikelski, Ph.D.
Postdoctoral Research Fellow
Bloomfield Centre for Research in Aging
Lady Davis Institute for Medical Research
Sir Mortimer B. Davis - Jewish General Hospital
McGill University



More information about the MINC-users mailing list