Avoiding For Loops [message #45080] |
Mon, 01 August 2005 12:15 |
sudipta
Messages: 1 Registered: August 2005
|
Junior Member |
|
|
Hello Everybody,
My IDL problem is simple but is very crucial. I have a small program
that calculates the RMSE difference between each pixel spectral
signature for a landsat scene and corresponding spectral signatures
from a Look up Table database that cam e from experiments. In order to
do the RMSE calculations I am having to run three for loops as the
variable that has all the database spectral signatures is a 4
dimensional variable where the last dimension has the 6 simulated
values for the 6 bands of landsat. So the portion for RMSE calculation
in my program looks like the following:
for i = 0,9 do begin ;number of AI
for j = 0, 14013 do begin ;number of spectral combinations
for k = 0, 9 do begin ;number of fractions
tdata = reform(data(i,j,k,*),numbands,1)
rms(i,j,k) = total((tdata - lfdata)^2)
end
end
end
where 'data' is the 4 dimensional variable containing all possible
database signature combinations, lfdata has the landsat reflectance
from each pixel. I have a landsat 6 band file in BIP format so I do a
'While ~eof(file)' loop and read in each 6 band spectral profile for
each pixel and compute its RMS with all posisble database spectral
combinations with the aim being to choose the databse signature that
has the closest match.
But the first three dimensins of the database are respectively 10,14014
and 10 so giving a total of 1410400 combinations for each pixel. This
is slowing things down terribly. So i was wondering if there was a way
to avoid the for loops and do the RMS computation in one single step?
Please let me know as any feedback from you will be welcome.
Thanks
Sudipta
|
|
|