Re: [R] identify() - image()

About this list Date view Thread view Subject view Author view Attachment view

From: Barry Rowlingson (B.Rowlingson@lancaster.ac.uk)
Date: Thu 27 May 2004 - 03:40:42 EST


Message-id: <40B4D69A.80600@lancaster.ac.uk>

javier garcia - CEBAS wrote:
> Hi all;
> Just to ask if you know about any available function in R to identify points
> in a image plotted in X11. Something like the function identify(), but able
> to extract (x,y,value) groups from the image.

  this is what I use:

image.identify <- function(xyz, mark=T, digits=3){

   nx <- length(xyz$x) - 1
   ny <- length(xyz$y) - 1
   if(!all(dim(xyz$z)==c(nx,ny))){
     stop("Really need image specified by cell edges")
   }
   res <- data.frame()
   xy <- locator(1)
   while(!is.null(xy)){
     xbin <- as.numeric(cut(xy$x,xyz$x))
     ybin <- as.numeric(cut(xy$y,xyz$y))
     if(mark){
       points(xy$x,xy$y,pch=19,cex=.5,col="blue")

text(xy$x,xy$y,format(xyz$z[xbin,ybin],digits=digits),adj=-.2,col="blue")
     }
     cat("[",xbin,",",ybin,"] = ",xyz$z[xbin,ybin],"\n",sep='')
     res <-
rbind(res,data.frame(i=xbin,j=ybin,x=xy$x,y=xy$y,z=xyz$z[xbin,ybin]))
     xy <- locator(1)
   }
   res
}

Try:

> m=list(x=1:11,y=1:11,z=matrix(runif(100),10,10))
> image(m)
> identify.image(m)

  then click some things. Button 2 to finish.

  The returned data frame gives row and column in the 'z' matrix, x and
y coordinates, and value of the z matrix at that point.

  Baz

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:13 EST