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.
Asked
Active
Viewed 853 times
2

Anselm
- 7,450
- 3
- 28
- 37

Tim Lehmberg
- 23
- 2
-
Save the XY coordinates of what? – Mark Setchell Sep 18 '16 at 21:22
-
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. – IRTFM Sep 18 '16 at 21:35
1 Answers
1
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

hrbrmstr
- 77,368
- 11
- 139
- 205
-
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)? – Tim Lehmberg Sep 19 '16 at 15:00
-
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. – hrbrmstr Sep 19 '16 at 15:06