Custom Script Tutorial

Create Beautiful Satellite Images with EO Browser

Home > Explore > Education > Custom Scripts Tutorial

Would you like to create beautiful and informative satellite images? This short guide will show you how.

This is a tutorial for those interested in creating custom scripts, who are not familiar with programming. Custom scripts are javascript code, used to control the visualization and processing of satellite images with Sentinel Hub. They allow the user to quickly calculate different band combinations and visualize them, without previously downloading data.

Search for data first

We are going to be using the EO Browser application, that allows easy access to free satellite data. We will be using the Sentinel-2 satellite.

First, we will choose the data for the visualization. Follow the short steps below.

  • First, open the EO Browser.
  • Next you can pan the window to your area of interest, but we recommend you choose vegetated areas, since we will be working with vegetation. You can also simply stay in Italy, as is default.
  • In the search tab, choose the data by selecting the Sentinel-2 satellite (leave the L1C option on), low cloud coverage (2-5 %) and a time range (we recommend you change the first date to a specific day in 2015), like on the image below (left).
  • Scroll down and confirm by clicking search.
  • Choose one of the results, that covers your area well and has low cloud coverage by selecting visualize, like on the image below (right).
  • For more information on how to use the EO Browser, consult the Sentinel Hub user guide.

 

That’s it! Now we can start having fun!

Create a composite in EO Browser

Open tabs below to learn how to create your first color composite.

 

The EO Browser already offers some visualization options, but since we want to create one ourselves, we will click on the  Custom option on top. The drag and drop panel opens, where we can create custom images very quickly. Hover the mouse over the circles to discover which bands they display.

EO Browser 
 

If we want to create a colorful image, we need to input  bands (the 13 circles in the upper area) into the bottom 3 circles with the R (red), G (green) and B (blue) letters, also called color channels. To create a color image, we need to input different bands into them, which combines the 3 colors and creates a color composite, such as on the diagram below.

EO Browser

If we input bands B04 (red light), B03 (green) and B02 (blue) into the R, G, and B circles, respectively, we will get a true color image. Any other combination will produce a false color composite. The example below (right) uses band 8, which displays vegetation, band 4, which highlights bare ground areas and band 2 to produce the image, that shows vegetation depth. If you would like to understand more about bands and which features they display, take a look at our beginner tutorial at the bottom of this page.

EO Browser EO Browser

Start scripting!

To get more control over how we display our bands, we can multiply them to make them brighter. This is where we use custom scripts. Custom scripts are javascript code used to control the visualization and processing of satellite images. Don’t worry, it is very easy.

To access custom scripts, click on the green hand symbol under custom, to toggle between draggable bands and custom scripts (</>).

 

As the white javascript window opens, you can start changing the code. When you’re done, scroll down and click refresh, since the image won’t update automatically.

To create the same composites as above in the scripting window, we would simply write the bands by hand after the function return, wrap them inside the square brackets and separate them with commas. In our case, the first number corresponds to the red channel, the second to green and the third to blue. Additionally, we multiply the bands by 2.5 to increase the brightness.

return [ B04 * 2.5, B03 * 2.5, B02 * 2.5 ]; // examine in EO Browser.
return [ B08 * 2.5, B04 * 2.5, B03 * 2.5 ]; // examine in EO Browser.

Visualise the Betsiboka river delta in Madagascar

Let’s try out a fun challenge. We will visualize the Madagascar Betsiboka river delta, in an informative and appealing way. Open the tabs below to follow the steps. 

Below is the true color composite, we will try to enhance. Click on the image below to open it in the EO Browser.

Let’s suppose we want to separate vegetation from non-vegetation and highlight river sedimentation. To achieve that, we can input band 8 (vegetation) into the green channel, band 4 (bare ground) into the red channel and band 2 (which is used for deep water analysis) into the blue channel. We also multiply them by 2.5.

return [ B04 * 2.5, B08 * 2.5, B02 * 2.5 ]; // examine in EO Browser.

We can see, that band 8 is very strong and we can't see sedimentation or non-vegetated areas well.

Let’s try to increase the brightness of red and blue channels, by multiplying them by 3.5.

return [ B04 * 3.5, B08 * 2.5, B02 * 3.5 ]; // examine in EO Browser.

Although the result we got is informative enaugh, the image would be more expressive, if we increased the red values further. This is now only a matter of aesthetics and experimentation. Let’s increase the value of band 4 to 5.5.

return [ B04 * 5.5, B08 * 2.5, B02 * 3.5 ]; // examine in EO Browser.

Now we have created a composite, that displays deeper water in dark purple, sedimentation and shallow waters in red, bare ground in orange and pink and vegetation in green.


You should take some time to practice and experiment. Try out different values and bands. Note that custom scripts can be used for scientific, as well as aesthetic purposes. Think about whether your script is useful to you.

There is a lot more to learn. If you would like to:

  • understand why certain bands highlight certain types of objects,
  • how color works,
  • create useful maps by implementing indices,
  • create your own custom color classes or
  • create continuous color scales,

we prepared an extended, but still short and friendly, guide in the pdf below. If you continue reading, you will understand everything we did above in depth and be able to create useful satellite visualizations.

It’s time to create your own color composite!