The problem is to determine number of objects in the area defined by polygon of arbitrary shape. Suppose trees are planted randomly in a rectangular area. The trees are being eaten by some bug and after some time die. Some trees do survive. Both surviving and dead trees form the clusters. In general there are more than 2 clusters. The question is 1) how to detect boundaries between clusters of surviving and dead trees, 2) count the number of trees within each cluster, 3) determine the area of each cluster. I am determining the boundaries using R function boundaries from raster library but got stuck with 2) and 3). Any help is appreciated.