Skip to content

Instantly share code, notes, and snippets.

@erichare
Last active June 23, 2019 20:30
Show Gist options
  • Save erichare/0d1533d49f0dfe86f06aec7c893bb6cb to your computer and use it in GitHub Desktop.
Save erichare/0d1533d49f0dfe86f06aec7c893bb6cb to your computer and use it in GitHub Desktop.
library(magick)
library(tidyverse)
im <- image_read("line.jpg")
im_proc <- im %>%
image_channel("saturation") %>%
image_threshold("white", "30%") %>%
image_negate()
dat <- image_data(im_proc)[1,,] %>%
as.data.frame() %>%
mutate(Row = 1:nrow(.)) %>%
select(Row, everything()) %>%
mutate_all(as.character) %>%
gather(key = Column, value = value, 2:ncol(.)) %>%
mutate(Column = as.numeric(gsub("V", "", Column)),
Row = as.numeric(Row),
value = ifelse(value == "00", NA, 1)) %>%
filter(!is.na(value))
ggplot(data = dat, aes(x = Row, y = Column, colour = (Column < 300))) +
geom_point() +
scale_y_continuous(trans = "reverse") +
scale_colour_manual(values = c("red4", "blue4")) +
theme(legend.position = "off")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment