img2grid

Creates grid-art from images
git clone https://src.jayvii.de/pub/img2grid.git
Log | Files | Refs

commit bf71c739b3a5638965c748c31d4311df68f016da
parent 58cdb1ad88353faf8401197389800eb4866fc9b6
Author: JayVii <jayvii@posteo.de>
Date:   Sat, 21 Dec 2019 15:15:36 +0100

WIP: Trier, Porta Nigra

Diffstat:
Aporta/#img2grid.R# | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aporta/Porta_Nigra_abends.jpg | 0
Aporta/img2grid.R | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aporta/img2grid.R~ | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aporta/porta_cut.jpg | 0
Aporta/porta_cut.png | 0
Aporta/porta_cut.xcf | 0
Aporta/porta_edit.png | 0
Aporta/porta_edit.xcf | 0
Aporta/porta_grid.pdf | 0
Aporta/porta_grid.png | 0
Aporta/sky.jpg | 0
12 files changed, 180 insertions(+), 0 deletions(-)

diff --git a/porta/#img2grid.R# b/porta/#img2grid.R# @@ -0,0 +1,60 @@ +# Copyright (c) 2018 Jan "JayVii" <jayvii@posteo.de> +# SPDX-License-Identifier: GPL-3.0 + +# Load Packages {{{ ---- + +library("imager") +library("ggplot2") +library("dplyr") +library("geosphere") + +# }}} + +# Import image, grayscale, filter, and sample image {{{ ---- +file <- "./porta_cut.jpg" + +# Kudos: @aschinchon +# https://github.com/aschinchon/travelling-salesman-portrait/ +load.image(file) %>% + grayscale() %>% + threshold("35%") %>% + as.cimg() %>% + as.data.frame() %>% + sample_n(10000, weight=(1-value)) %>% +select(x,y) -> data + +# }}} + +# Scale data and calculate distances between each point +data_st <- data / max(data) +distances <- distm(x = data_st) # dirty. FIXME (assumes ellipsoid or sphere) + +# find nearest point for each pair of x/y +near <- matrix(data = NA, nrow = length(data_st$x), ncol = length(data_st$x)) +for(i in 1:length(data_st$x)){ + near[i,] <- order(distances[i,]) +} + +# plot the result {{{ ---- + +# we want a PDF file from that (10" x 10") +pdf(file = "./porta_grid.pdf", height = 10, width = 10) + + # without margins around plot + par(mar=c(0, 0, 0, 0)) + + # dummy (empty) plot, with correct xylims + plot(-data_st, type = "l", col = rgb(0,0,0,alpha = 0), axes = FALSE, + xlab = "", ylab = "", main = "") + + # add lines connecting the nearest 30 xy-pairs to current point + # also mirror data points (-) + # color is white with some low alpha value + for(i in 1:length(data_st$x)){ + lines(-data_st[near[i,1:30],], type = "l", + col = rgb(1, 1, 1, alpha = 0.2)) + } + +dev.off() + +# }}} diff --git a/porta/Porta_Nigra_abends.jpg b/porta/Porta_Nigra_abends.jpg Binary files differ. diff --git a/porta/img2grid.R b/porta/img2grid.R @@ -0,0 +1,60 @@ +# Copyright (c) 2018 Jan "JayVii" <jayvii@posteo.de> +# SPDX-License-Identifier: GPL-3.0 + +# Load Packages {{{ ---- + +library("imager") +library("ggplot2") +library("dplyr") +library("geosphere") + +# }}} + +# Import image, grayscale, filter, and sample image {{{ ---- +file <- "./porta_cut.jpg" + +# Kudos: @aschinchon +# https://github.com/aschinchon/travelling-salesman-portrait/ +load.image(file) %>% + grayscale() %>% + threshold("35%") %>% + as.cimg() %>% + as.data.frame() %>% + sample_n(10000, weight=(1-value)) %>% +select(x,y) -> data + +# }}} + +# Scale data and calculate distances between each point +data_st <- data / max(data) +distances <- distm(x = data_st) # dirty. FIXME (assumes ellipsoid or sphere) + +# find nearest point for each pair of x/y +near <- matrix(data = NA, nrow = length(data_st$x), ncol = length(data_st$x)) +for(i in 1:length(data_st$x)){ + near[i,] <- order(distances[i,]) +} + +# plot the result {{{ ---- + +# we want a PDF file from that (10" x 10") +pdf(file = "~/porta_grid.pdf", height = 10, width = 10) + + # without margins around plot + par(mar=c(0, 0, 0, 0)) + + # dummy (empty) plot, with correct xylims + plot(-data_st, type = "l", col = rgb(0,0,0,alpha = 0), axes = FALSE, + xlab = "", ylab = "", main = "") + + # add lines connecting the nearest 20 xy-pairs to current point + # also mirror data points (-) + # color is black with some low alpha value + for(i in 1:length(data_st$x)){ + lines(data_st[near[i,1:50],], type = "l", + col = rgb(0, 0, 0, alpha = 0.05)) + } + +dev.off() + +# }}} diff --git a/porta/img2grid.R~ b/porta/img2grid.R~ @@ -0,0 +1,60 @@ +# Copyright (c) 2018 Jan "JayVii" <jayvii@posteo.de> +# SPDX-License-Identifier: GPL-3.0 + +# Load Packages {{{ ---- + +library("imager") +library("ggplot2") +library("dplyr") +library("geosphere") + +# }}} + +# Import image, grayscale, filter, and sample image {{{ ---- +file <- "~/face.jpg" # not contained in repo ;) + +# Kudos: @aschinchon +# https://github.com/aschinchon/travelling-salesman-portrait/ +load.image(file) %>% + grayscale() %>% + threshold("35%") %>% + as.cimg() %>% + as.data.frame() %>% + sample_n(10000, weight=(1-value)) %>% +select(x,y) -> data + +# }}} + +# Scale data and calculate distances between each point +data_st <- data / max(data) +distances <- distm(x = data_st) # dirty. FIXME (assumes ellipsoid or sphere) + +# find nearest point for each pair of x/y +near <- matrix(data = NA, nrow = length(data_st$x), ncol = length(data_st$x)) +for(i in 1:length(data_st$x)){ + near[i,] <- order(distances[i,]) +} + +# plot the result {{{ ---- + +# we want a PDF file from that (10" x 10") +pdf(file = "~/out/me.pdf", height = 10, width = 10) + + # without margins around plot + par(mar=c(0, 0, 0, 0)) + + # dummy (empty) plot, with correct xylims + plot(-data_st, type = "l", col = rgb(0,0,0,alpha = 0), axes = FALSE, + xlab = "", ylab = "", main = "") + + # add lines connecting the nearest 20 xy-pairs to current point + # also mirror data points (-) + # color is black with some low alpha value + for(i in 1:length(data_st$x)){ + lines(-data_st[near[i,1:20],], type = "l", + col = rgb(0, 0, 0, alpha = 0.05)) + } + +dev.off() + +# }}} diff --git a/porta/porta_cut.jpg b/porta/porta_cut.jpg Binary files differ. diff --git a/porta/porta_cut.png b/porta/porta_cut.png Binary files differ. diff --git a/porta/porta_cut.xcf b/porta/porta_cut.xcf Binary files differ. diff --git a/porta/porta_edit.png b/porta/porta_edit.png Binary files differ. diff --git a/porta/porta_edit.xcf b/porta/porta_edit.xcf Binary files differ. diff --git a/porta/porta_grid.pdf b/porta/porta_grid.pdf Binary files differ. diff --git a/porta/porta_grid.png b/porta/porta_grid.png Binary files differ. diff --git a/porta/sky.jpg b/porta/sky.jpg Binary files differ.