Hyperspectral Band Smoothing
QUESTION: We are trying to do a moving average on our dataset. The dataset comes from a hyperspectral sensor and has 296 samples, 2000 lines and 492 bands (i.e, image = Fltarr(296, 2000, 492). We need to go through each pixel and do a moving average on the spectral bands. So in the end we will have a dataset with the same dimensions as the original but with smooth spectra. And because of the moving average kernel size, we will have some empty bands at the beginning and at the end.
Here is the code we are using now, and it takes about three hours to run. Is there a way to speed this up in IDL?
Step = FIX(Kernel / 2) FOR samples = 0 , 295 DO BEGIN FOR lines = 0, 1999 DO BEGIN FOR bands = Step, 491 - Step DO BEGIN ARR_TEMP = MEAN(IMAGE[samples, lines,bands-Step:bands+step]) IMAGE[samples, lines, bands] = ARR_TEMP IMAGE[samples, lines, 0:step-1] = 0 IMAGE[samples, lines, bands-(Step):bands-1] = 0 ENDFOR ENDFOR ENDFOR
ANSWER: If we could do it with one line of code, and in a couple of seconds, would that help?
JD Smith suggests this:
image = Smooth(Temporary(image), [1,1,width])
where width is the size of the window you want to use for your moving average. In your case, something like (492 - (2*step) + 1).
Since this array address something like 1.2GB of memory space, it is possible you may want to do this operation in “chunks.” That is to say, use a small loop and do, say, 50 bands at a time.
Copyright © 2007 David W. Fanning
Last Updated 1 January 2007