Calculate the nearest distance between each pixel inside my region of interest to the closest streamline (a FeatureCollection) in Google Earth Engine

I need to find the nearest distance between every pixel in my area of interest to the streamline closest to it. I'm using the following dataset for the streamlines `ee.FeatureCollection("WWF/HydroSHEDS/v1/FreeFlowingRivers")`.

Initially, I thought `image.cumulativeCost()` would do the trick, but it seems like increasing the `maxDistance` only increases the buffer around the streamlines. The resulting value of cumulative_cost is 0 when the area is within the 1km buffer of the streamlines, and 'masked' otherwise.

What are the values of the 'masked' pixels? Is it even feasible to achieve what I need using `image.cumulativeCost()`?

``````var streams = ee.FeatureCollection("WWF/HydroSHEDS/v1/FreeFlowingRivers");
var roi = ee.Geometry.Polygon(
[[[31.79857587268242, 40.34237834590226],
[31.79857587268242, 39.1087726665225],
[35.77013348986992, 39.1087726665225],
[35.77013348986992, 40.34237834590226]]], null, false);

//polylines representing river networks
var filteredstreams = streams.filterBounds(roi);

var streamImg = filteredstreams
.reduceToImage({
properties: ['LENGTH_KM'],    //picked a random property here just to convert the FeatureCollection
reducer: ee.Reducer.first()   //into an image
});

//create a source image where the geometry is 1, everything else is 0
var streamsources = ee.Image().toByte().paint(roi, 1);
var emptysource = ee.Image().toByte().paint(roi, 0);

//define distance
var maximumdist = 1000; //1km

//cost image
var thedist = emptysource.cumulativeCost({
source: streamsources ,
maxDistance: maximumdist,
});
print(thedist);
You can compute the distance using `fastDistanceTransform()`. See also here:
``````// calculate the distance from the strem (in pixels)