Search code examples
rimage-processingimagejbinary-image

How do I save the XY coordinates of a Binary Image in R?


I am trying to save the XY coordinates of a binary image in R similarly to the save "Save XY Coordinates" function in ImageJ. I've looked through several image analysis packages available for R, but haven't yet figured out how to accomplish this. image


Solution

  • There are many ways to do the following in R:

    img_fil <- "~/data/ZjYqw.jpg"
    img <- magick::image_read(img_fil)
    img_df <- RSAGA::grid.to.xyz(as.matrix(as.raster(img)))
    
    head(img_df)
    ##   x   y       z
    ## 1 0 599 #ffffff
    ## 2 1 599 #ffffff
    ## 3 2 599 #ffffff
    ## 4 3 599 #ffffff
    ## 5 4 599 #ffffff
    ## 6 5 599 #ffffff