Sentinel 2 images often contain some clouds, with mathematical processing it is possible to correct cirrus effect, but it is impossible to see through thick clouds.

The objective is to detect them to avoid inaccurate results. Logically one should be able to detect the clouds and also calculate its shadow position because it perturbs the reflectance as much as the cloud himself.

Nevertheless, when a cloud is detected, its shadow is not far away, enlarging the cloud detection area may be enough to avoid cloud effects.

I have tested several algorithms available through java scripts usable on Sentinel hub  on the example image below.

 

The first script written in javascript use the Braaten-Cohen and Yang method  (Braaten J, Cohen WB, Yang Z. 2015. Automated cloud and cloud shadow identification in Landsat MSS imagery for temperate ecosystems. Remote Sensing of Environment. 169:128-138.)

One can observe the detection is not perfect, I did not test the algorithm using R, this algorithm is based on NDGR reflectance indicator, may the coefficients should be optimized.Detected clouds are plotted in red color.

A second method was tested using tree classification from Holstein( A. Hollstein et al., Ready-to-Use Methods for the Detection of Clouds, Cirrus, Snow, Shadow, Water and Clear Sky Pixels in Sentinel-2 MSI Images. Remote Sensing (2016). 10.3390/rs8080666)

Clouds are considered as blue pixels on the above image. The results do not show improvement compared to the first method.

Test of a third method:

This algorithm is inspired from Sen2cor and Fmask algorithms and simplified, which yield quite efficient results, when processing a field, the cloud mask is generated on a larger area and if some cloud pixels are detected in the field, of course, the image is discarded from the process, else, cloudy pixels on the larger area are summed and a cloud rate is determined, if above a threshold the image is discarded.

This method is very simple to process and fast enough even using R and quite efficient.