On Thu, 9 Mar 2006, Christian Jost wrote:
Dear all,
I try to figure out how to use R to count the number of pixels of the
same color in some gray-level picture. I managed to read it in either
tiff or jpeg format, but the returned pixmap object keeps its
information out of (my) reach. Is there an easy way to tabulate the
different color/graylevel pixels and their numbers? Or should I use a
completely different (free) software?
The objects are new-style class objects, so they are documented internally
- query by getSlots() or from ?"pixmap-class":
library(pixmap)
x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
z <- as(x, "pixmapGrey")
class(z)
getSlots(class(z)) # lets you know what the slots are
greydata <- slot(z, "grey") # extract the slot object
summary(c(greydata)) # c() to flatten a matrix
length(unique(c(greydata)))
length((c(greydata))) # rather a lot of different values, let's round:
rgreydata <- round(greydata*10)
length(unique(c(rgreydata))) # looks good
table(c(rgreydata))
I assume that you converted from tiff or jpeg to pnm outside pixmap.
Thanks for any hint, Christian.