[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dereferencing a Pointer Array
Art Burden wrote:
> I have a structure that contains a pointer array that points to twelve
> 512-by-512 images. I would like to find the mean image from the twelve
> images in a simple and fast way. I understand that I can dereference
> the pointer to an image or an individual element in an image by using,
> for example
>
> img = (*info.images[0])
> and
> img_element = (*info.images[0])[240,240]
>
> but I can't figure out a way to dereference the pointers to all 12 pixel
> values from a given coordinate in one step. At this stage, I pass the
> structure into my averaging subroutine and I create a new array to
> store the 12 images. I then fill the array by dereferencing the pointer
> to each image in a loop. Finally, I loop through the rows and columns
> to get each mean pixel value, as shown below. Can anyone think of a
> better (mainly faster) way to do this?
>
> ;retrieve array of images
> ffim = lonarr(12,512,512)
> for num=0,11 do ffim[num,*,*] = *info.images[num]
>
> ;calculate mean of images
> mean_ff = fltarr(512,512)
> for ir = 0,511 do for ic = 0,511 do mean_im[ic,ir] = mean(ffim[*,ic,ir])
Perhaps something like this (untested):
sum = fltarr(512, 512)
n = 12
for i = 0L, n - 1L do sum = sum + *info.images[i]
avg = sum / float(n)
Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley/