[R-sig-Geo] EBImage: converting watershed IndexedImage to polygons
Andrew Niccolai
andrew.niccolai at yale.edu
Sat Jul 21 00:02:30 CEST 2007
Hello R-spatial group, I hope this email finds everyone well. I have been
using the R package EBImage to convert .tif/.jpg images of forests into
watershed segmentation rasters. However, I am having difficulty converting
these watershed images into polygons. For those not familiar with EBImage
or watershed segmentation, the package essentially does an iterative series
of image erosion and dilating to try to create boundaries between objects
within an image that "bleed" into each other. However, these images create
objects without any label values so within any image object resides several
similar but slightly different values encapsulated by an edge with much
lower (but slightly different) values.
I was wondering if anyone had any thoughts/suggestions for converting
IndexedImages to polygons? I have an IndexedImage created using code along
these lines:
rgb <- abs(img.red - img.green)
#display(rgb)
rgb.u <- umask(rgb, r=11, s=5)
#display(rgb.u)
t <- thresh( blur(rgb.u, 4, 2), 15, 15)
t <- opening( closing(t, morphKern(9)) ) t <- erode(t,morphKern(9), iter=5)
#display(t)
w <- watershed( distmap(t) )
#display(normalize(w))
w2 <- getFeatures(w)
When I run getFeatures, I can see 362 rows in the array. This corresponds
to what I assume are the number of objects in my watershed image. However,
when I try to write out either w or normalize(w) I get either a binary image
(w) or an image with normalized values within each object and not a uniform
label id with each object. Ideally, I would like to create an image with
362 objects with each object "filled" with a label value representing that
unique object. Then I think I can convert the raster image to polygons
(although suggestions here are welcome as well).
Any help would be greatly appreciated.
Thank you,
Andrew
Andrew Niccolai
Doctoral Candidate
Yale School of Forestry
More information about the R-sig-Geo
mailing list