-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageProcessor.py
More file actions
37 lines (31 loc) · 1.33 KB
/
ImageProcessor.py
File metadata and controls
37 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from PIL import Image
import numpy as np
class ImageProcessor:
def __init__(self, h, v):
self.h = h
self.v = v
def processImageArray(self, imageArray):
img = Image.fromarray(imageArray)
resultImage = img.resize((self.h, self.v), resample=Image.Resampling.BILINEAR)
return resultImage
def calculateColors(self, image):
colorsList = []
image_rgb = image.convert('RGB')
# Quick reminder that we're counting leds from right-bottom corner of the screen and going anticlockwise
for i in range(0, self.v, 1):
colorsList.append((image_rgb.getpixel((self.h-1, i))))
for i in range(self.h-1, -1, -1):
colorsList.append((image_rgb.getpixel((i, self.v-1))))
for i in range(self.v-1, -1, -1):
colorsList.append((image_rgb.getpixel((0, i))))
for i in range(0, self.h, 1):
colorsList.append((image_rgb.getpixel((i, 0))))
return colorsList
def processImage(self, input, output):
img = Image.open(input)
resultImage = img.resize((self.h, self.v), resample=Image.Resampling.BILINEAR)
resultImage.save(output)
def imageProcessingTest():
imageProcessor = ImageProcessor(13,7)
imageProcessor.processImage('test_image.png', 'test_image_processed.png')
#imageProcessingTest()