Skip to content

Instantly share code, notes, and snippets.

@MaxvanHaastrecht
MaxvanHaastrecht / street_map.py
Last active January 24, 2022 05:39
Importing roads and plotting as a city street map
import geopandas as gpd
import matplotlib.pyplot as plt
# Import all roads NL
map_df = gpd.read_file('roads.shp')
# Show data format
map_df.head()
# Set image properties
fig, ax = plt.subplots(1, figsize=(10,14))
@MaxvanHaastrecht
MaxvanHaastrecht / image_grid.py
Created September 19, 2021 13:47
Creating a grid of images
from PIL import Image
# Load created images; for example 4
amsterdam = Image.open('Amsterdam.png')
hague = Image.open('The_Hague.png')
rotterdam = Image.open('Rotterdam.png')
utrecht = Image.open('Utrecht.png')
# Retrieve width and height original images
width = amsterdam.size[0]
@MaxvanHaastrecht
MaxvanHaastrecht / colouring_book.py
Created September 24, 2021 13:37
Creating a personalised colouring book from your own photos
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
import skimage.color as color
import skimage.segmentation as seg
# Read the image you want to process
image = io.imread('image.png')
@MaxvanHaastrecht
MaxvanHaastrecht / PuLP_TSP.py
Created December 28, 2021 15:26
Creating a TSP ILP in PuLP
import pulp as pl
# Define PuLP model
model = pl.LpProblem('TSP', pl.LpMinimize)
# Define binary variables
x = pl.LpVariable.dicts('x', ((i, j) for i in range(n_perm) for j in range(n_perm)), cat = 'Binary')
# Set the objective function
model += pl.lpSum(cost_dict[permutations[i], permutations[j]] * x[i, j] for i in range(n_perm) for j in range(n_perm))