Skip to content

Instantly share code, notes, and snippets.

View BilHim's full-sized avatar

Bilal Himite BilHim

View GitHub Profile
# Weighted average grayscale
for x in range(width):
for y in range(height):
r, g, b = image.getpixel((x, y))
r_ = g_ = b_ = 0.299*r + 0.587*g + 0.114*b
new_pixel = (int(r_), int(g_), int(b_))
new_image.putpixel((x, y), new_pixel)
# Grayscale filter
for x in range(width):
for y in range(height):
# Get original pixel colors
r, g, b = image.getpixel((x, y))
# New pixel colors
r_ = g_ = b_ = (r+g+b)/3
# Change new pixel
from PIL import Image
# Open image
image = Image.open('image.jpg')
# Filter
def filter(image):
# Get image dimesions
width, height = image.size
@BilHim
BilHim / opening_image.py
Created February 17, 2021 13:58
Opening an image in Pillow
from PIL import Image
# Open image
image = Image.open('image.jpg')
# Show image
image.show()
@BilHim
BilHim / einsum_prod.py
Created June 22, 2020 17:24
Matrix product using einsum
np.einsum("ik,kj->ij", A, B)
@BilHim
BilHim / einsum_prod_python.py
Created June 22, 2020 17:17
Matrix product in Python
# Returns matrix product of A and B
def prod(A, B):
# Dimensions
m = A.shape[0]
n = A.shape[1] # same as B.shape[0]
p = B.shape[1]
# Initialize an empty (m,p) matrix
C = np.zeros((m, p))
# Fill it
for i in range(m):
import bpy
from math import *
# Settings
width = 800
height = 800
z_height = 0.25 # Displace modifier strength
tex_res = 1 # Texture resolution (1:1)
mesh_res = 4 # Mesh resolution (8:1)
from PIL import Image
width = 800
height = 600
def getpixel(x, y):
n = 0.5 # Get value here
return int(255*n)
# Create a new image. L for grayscale
scale = 75
octaves = 8
persistence = 0.5
lacunarity = 2
land = (133, 222, 70)
water = (21, 60, 177)
def getColor(x, y):
a = pnoise2(x/scale,
def getColor(x, y):
a = pnoise2(x/scale,
y/scale,
octaves = octaves,
persistence = persistence,
lacunarity = lacunarity)
a = int(127*(a+1)) # a is between -1 and 1, this gives us values between 0 and 255
return (a,)*3