This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
# Open image | |
image = Image.open('image.jpg') | |
# Filter | |
def filter(image): | |
# Get image dimesions | |
width, height = image.size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
# Open image | |
image = Image.open('image.jpg') | |
# Show image | |
image.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.einsum("ik,kj->ij", A, B) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |