I am working on classifying forest types using Sentinel-2 satellite imagery (10-m resolution; band-2, band-3, band-4 & band-8). I have ground-truthed field data as a training set. I want to set a parameter that constrains classification so that nearby pixels must be classified into the same class or that there must be a minimum of 10 neighbouring pixels within the same class. Ideally, I want the classification to take into account the heterogeneity of an area and not just classify each pixel based on the average in the training set. I would prefer a solution in R but I could also use QGIS or ArcGIS.
Details:
I have been using this helpful tutorial for the classification in R: http://ceholden.github.io/open-geo-tutorial/R/chapter_5_classification.html.
While I have successfully run the functions and algorithms to produce a classification using the randomForest package and the raster package, I am not satisfied with it because the result is lots of isolated pixels of different classes. (For example, five of the six classes are adjacent neighbours with no dominant class to use in post-processing to cluster together). Visually, I noticed that some forest types are distinguished by being heterogeneous (pixels of very different colours side-by-side) and other forest types are homogeneous (pixels of similar colours side-by-side). I want the classification algorithm to pick it on the pattern within the training set (polygons of circles 60m in diameter) and/or to take into account neighbours in the classification so that nearby pixels have the same value. I also have polygons of delineated forest types from photo-interpretation, which I could use to constrain to have only single value per polygon (the values of the photo interpretation are not accurate but the limits are good enough).
I've taken screenshots of the RGB true-colour image of three (out of six) of forest types and their respective classifications. I've chosen two for which it works well and I could use post-classification majority filter to smooth groups. And one for which there is a high heterogeneity and the classification algorithm does not work.
What function can I use in R to classify raster that takes neighbours into account?