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.
How do I save the XY coordinates of a Binary Image in R?
Asked Answered
Save the XY coordinates of what? –
Yi
Exactly what he said. The phrase "XY coordinates of a binary image" might be meaningful to someone who uses imageJ all the time but it is whooshing over our heads. You are also expect to provide some sort of data/file/link so there is something to work with. –
Heirloom
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
Thanks for the help! I went to do this on the image I put above, but when I went to plot the points, the entire plot turned up black. Is there a way to save only the coordinates of the black pixels (those being of a color value of 255)? –
Untuck
Since I have no idea how you plotted the image it's impossible to help with that. But, if you had used
ggplot2
, then ggplot(img_df, aes(x, y, color=z)) + geom_point() + scale_color_identity()
should plot it with black & white. –
Heading © 2022 - 2024 — McMap. All rights reserved.