2

Hi R expert of the world, Assume I have a point pattern that generate an intensity map and that this map is color coded in 3 region in an pixeled image.... how could I get the color-coded area?

here it is an example using spatstat:

library(spatstat)
japanesepines
Z<-density(japanesepines); plot(dens) # ---> I create a density map
b <- quantile(Z, probs = (0:3)/3) # ---> I "reduce it" to 3 color-ceded zones
Zcut <- cut(Z, breaks = b, labels = 1:3); plot(Zcut)
class(Zcut) # ---> and Zcut is my resultant image ("im")

Thank you in advance Sacc

saccente
  • 21
  • 1

2 Answers2

1

In your specific example it is very easy to calculate the area because you used quantile to cut the image: This effectively divides the image into areas of equal size, so there should be three areas of size 1/3 since the window is a unit square. In general to calculate areas from a factor valued image you could use as.tess and tile.areas (continuing your example):

Ztess <- as.tess(Zcut)
tile.areas(Ztess)

In this case the areas are 0.333313, which must be due to discretization.

Ege Rubak
  • 4,347
  • 1
  • 10
  • 18
-1

I'm not exactly sure what you're after, but you can count up the number of pixels in each color using the table() function.

table(Zcut[[1]])
Jean V. Adams
  • 4,634
  • 2
  • 29
  • 46