Supervised and unsupervised classification, Sentinel 2

Hello everyone,

I’m a student of geodesy and geomatics and I’m supposed to do thesis on classification (supervised and unsupervised) of area near Novi Sad, Serbia. Since I’m new to s2tbx I’m having some problems. I already tried to do the unsupervised classification but the process didn’t finish even though it worked all night. I already tried to find some tutorials and user-guides that could help me, but I didn’t find anything usefull. So I was wondering if there is anyone who could help me in any way possible? I could use some instructions like where to start, etc.
Name of the product: S2A_OPER_PRD_MSIL1C_PDMC_20160815T080201_R036_V20150725T094006_20150725T094003
SNAP version: 4.0
OS: Windows 10, 64-bit
I don’t have much experience with softwares like s2tbx, since only software I worked with is ERDAS.

Anyway, that’s all guys.

Thanks in advance.


if the unsupervised classification took too long you can

  1. subset your image and test it (a whole S2 scene could take really long for a cluster or EM analysis)
  2. reduce the number of clusters
  3. Choose another classifier (EM and K-means take different time)

For a supervised classification you have to define geometries including your training areas.

Make one per class you want to detect.

They are stored in the vector Data folder (don’t mind about pins and gcps)

You can then select a supervised classifier, but make sure you know a litte about how they and corresponding parameters work. KNN is quite simple and you can’t do much wrong with it. Your trained classes should appear in the dialogue:


Thank you very much. You were very helpful. I followed your instructions and I did everything right.


I tried all the steps, but the classified map is blank. May you tell me where I missed out

hard to guess. What data are you using? Which steps did you perform?

Sometimes it’s required to save the product with the digitized geometries first so they really apply in the classification module.

You have to save the product with digitized geometries and then do the classification. I did the same mistake.

How do you save the product with “digitized geometries”? I am getting the same issue - after supervised classification using vector polygons, I get a blank classification map.


actually under File > save product.

What supervised method did you chose? Which parameters?
You could also send a screenshot of the classification module you are using.

Thanks for the response. I saved the subsetted product (under FIle->save product) and then re-opened it in snap but I still get the same issue. I’m using the Maximum Likelihood Classifier (however I get the same issue with the KNN Classifier).

Here are my settings for supervised classification (I just used the default settings):

Here is the output:

hmm, 1 second is not much.
Does the raster have values? You can select the pixel information tab and move your mouse over it.

Yep. The raster has values. The example I’ve shown is on quite a small subset of the data. I’ve also ran the classifier on an entire sentinel tile (100km^2) and that took just over an hour. The result was still a blank classification map.

sorry, I actually meant the black outcome. I wondered if it maybe just isn’t displayed correctly. Maybe you can check, if there are values from 1-3 or if everythin is nan (not a number).

In the latter case: Right click on the result band ‘labeled classes’, select properties and see what is entered in the no data value.
Maybe the -1 is somehow messing it up.

Ok. I’ve checked the Pixel Info and everywhere is either NaN or Invalid pos. I played around with the no data value (changed to positive values and un-ticked the No-Data Value Used box) and nothing happens. I also changed the Confidence condition to see if that was affecting the result but that didn’t change anything either. Here’s the Labeled Classes properties default settings:

@ABraun could you please tell me how to these geometries?
I would like to select an area to became training area, and when I click that Icon, it opens a window called ‘New Vector Data Countainer’, I change the name and… what next?

I see that on the product explorer > vector data menu, this new vector is added, but I don’t know how to draw the shape I want.

Thank you in advance!

first you create a container with the right name. Then you select it by clicking on the corresponding class under Vector Data and use one of the digitizing tools: Rectangle, polygon or circle.

You can just digitize it by clicking in the image. You can then check if your geometry was placed in the right container:

Dear @ABraun thank you for the reply.
I managed to do it, but when I check the geometry it cames out blank on the polygon box:

Here is a screen shot of some of the polygons:

I wonder if after drawing them I should save the vectors somehow?..

I tried to do a KNN classifier, and I got this (I selected the option “Add Opened” in Prodcut-Reader window:

And besides not showing the vectors in training vector window, it also says "Error in Graph: [NodeId: KNN-Classifier] Source products are off different dimensions’’.

I wonder howcome, since the product where I drew the polygons, was built with math bands after resampling all the bands to the same resolution (I can even create composite with all of them). They all have the same resolution.

Any idea/tip on this @ABraun ?


yes, you have to select File > Save product first. Then your changes will be applied.

1 Like

I did it File > Save product and it stills showing blank on the style_css box…

Nevermind. This box stills empty, but the vector appear now… : ) THank you @ABraun

@andy: Did you find a solution to your problem?