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

______________________________________________
[EMAIL PROTECTED] 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

Reply via email to