# Create loop that create new imagecollection based on calculation of previous imagecollection

I have imagecollection from sentinel which I would like to run few processes on it by using loop. I know what are the steps of the loop that I want and I have written draft that ia full of errores and I would like to get help in writing it correct.

The needd steps are:

1. apply the next function on each image:
``````//Apply Frost filter for speckle correction
function Frost(image, frostDamp, ksize)
// Frost is really a simplified version of GammaMap
// Make sure to pass the frost damp factor (frostDamp) as a NEGATIVE number
{
// ~~(ksize/2) does integer division in JavaScript
var distance_kernel = ee.Kernel.euclidean(~~(ksize/2));

// Square kernel, ksize should be odd (typically 3, 5 or 7)
var weights = ee.List.repeat(ee.List.repeat(1,ksize),ksize);

var kernel = ee.Kernel.fixed(ksize, ksize, weights, ~~(ksize/2), ~~(ksize/2), false);

// Get mean and variance
var mean = image.reduceNeighborhood(ee.Reducer.mean(), kernel);
var variance = image.reduceNeighborhood(ee.Reducer.variance(), kernel);

var B = variance.multiply(frostDamp).divide(mean.multiply(mean));

var W = B.exp().reduceNeighborhood(ee.Reducer.mean(), distance_kernel);

return image.multiply(W).reduceNeighborhood(ee.Reducer.sum(), kernel).divide(W.reduceNeighborhood(ee.Reducer.sum(), kernel));
}
``````
1. calculate new imagecollection , for each image ,each pixel will be calculted as folloing:
``````//here I would like to run calculation for each image in my imagecollection:
var calc=i.expression(
'3.75-(-0.521*VH)+(0.34*VV)+(3.12*NRPB)', {
'VH': i.select('VH_sum'),
'VV': i.select('VV_sum'),
});
``````

all of it will create new imagecollection.

I have tried to apply the first function using this:

``````var FrostDB=clippedSAR.map(function(im){
return im.Frost(geometry);
});
``````

but got this error:

im.Frost is not a function

My end goal is to create one loop that can run all the mentioned processes on an imagecollection, and also to get deeper understanding of loops in GEE

• It seems like there are multiple questions here. Two answers provide a solution to the error you received. Please apply the solutions and ask an additional question regarding anything further - thanks! Mar 2, 2020 at 17:15

The error results because you are calling the `Frost` function on an `ee.Image` as if it were an Earth Engine method of the `ee.Image` object. However, `Frost` is a client-side function, so it can only be applied with the format as Sean describes (`Frost(ee.Image)`) or as a function to be mapped over an `ee.ImageCollection` like shown below. The later implementation requires that the function have only a single parameter - an `ee.Image`. Other client variables that you wish to include as parameters of the function must instead be defined as global variables to be accessed from within the function.

Pseudo script:

``````// Define global scope variables that will be accessible to Frost function.
var frostDamp = <some number>;
var ksize = <some number>;

// Define Frost filter for speckle correction.
function Frost(image) {
<logic>;
}

// Apply the Frost function to image collection.
var frostFilterCol = myImgCol.map(Frost);
``````

For further reference:

I haven't been able to try it, as I don't have access to your different variables, but changing the applying of your function as follows should work.

``````var FrostDB=clippedSAR.map(function(im){
im = Frost(ee.Image(im));
return im;
});
``````