This file contains 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 os | |
import keyboard | |
import pyaudio, wave | |
import numpy.random as random | |
# Settings | |
chunk = 1024 | |
channels = 2 | |
sample_format = pyaudio.paInt16 |
This file contains 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
# Coordinates in old image | |
x_ = x/scale_x | |
y_ = y/scale_y | |
# Finding neighboring points | |
x1 = min(int(np.floor(x_)), width-1) | |
y1 = min(int(np.floor(y_)), height-1) | |
x2 = min(int(np.ceil(x_)), width-1) | |
y2 = min(int(np.ceil(y_)), height-1) |
This file contains 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
x_nearest = int(np.round(x/scale_x)) | |
y_nearest = int(np.round(y/scale_y)) | |
pixel = image.getpixel((x_nearest, y_nearest)) |
This file contains 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 numpy as np | |
from PIL import Image | |
# Import image and get its dimensions | |
image = Image.open('image.jpg') | |
width, height = image.size | |
# Create a new empty image | |
new_width, new_height = 480, 320 | |
scaled_image = Image.new(image.mode, (new_width, new_height), 'white') |
This file contains 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
# Load image pixels | |
data = np.array(image) | |
# Half kernel size | |
a = kernel_size // 2 | |
for x in range(width): | |
for y in range(height): | |
# min and max are used for edge pixels | |
x_start = max(x - a, 0) |
This file contains 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
for x in range(width): | |
for y in range(height): | |
r, g, b = image.getpixel((x, y)) | |
r_ = 255 * (r/255)**gamma | |
g_ = 255 * (g/255)**gamma | |
b_ = 255 * (b/255)**gamma | |
new_pixel = (int(r_), int(g_), int(b_)) | |
new_image.putpixel((x, y), new_pixel) |
This file contains 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
# Calculate factor | |
if beta == 255: alpha = np.infty | |
else: alpha = (255+beta)/(255-beta) | |
for x in range(width): | |
for y in range(height): | |
r, g, b = image.getpixel((x, y)) | |
μ = (r+g+b)/3 |
This file contains 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
# Converting image into a numpy array with a dimension (width, height, 3) | |
data = np.array(image) | |
# Calculate average brightness | |
μ = np.mean(data, axis=2) | |
μ_mean = μ.mean() | |
# Calculate factor | |
if beta == 255: alpha = np.infty | |
else: alpha = (255+beta)/(255-beta) |
This file contains 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 truncate(x): | |
'''makes sure returned value is between 0 and 255''' | |
return min(255, max(0, x)) |
This file contains 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
# Brightness filter | |
for x in range(width): | |
for y in range(height): | |
r, g, b = image.getpixel((x, y)) | |
# d is the brightness increase | |
r_ = truncate(r + d) | |
g_ = truncate(g + d) | |
b_ = truncate(b + d) |
NewerOlder