def get_image_grid(img, rows, cols, x0, y0, scale) -> List[List[Sprite]]:
    oimage = ni.get_array_from_file(img) 
    img_rows, img_cols, _ = oimage.shape
    
    imag_grid = []
    rows_step = img_rows // rows
    cols_step = img_cols // cols

    for i in range(rows):
        pointf_row = []
        imag_row = [] 
        for j in range(cols): 
            mini = i * rows_step
            maxi = (i+1) * rows_step
            minj = j * cols_step
            maxj = (j+1) * cols_step

            sub_img = oimage [mini:maxi, minj:maxj, :]
            p = w.create_sprite(Drable)
            p.set_ij(i , j)
            z = w.create_sprite(Pointf)
            z.set_ij(i , j)
            p.texture = ni.get_texture_from_array(sub_img)
            p.scale = scale
            p.x = x0 + j*(1+p.width)
            p.y = y0 + i*(1+p.height)
            z.x = p.x
            z.y = p.y         
            pointf_row.append(z)
            imag_row.append(p)

        imag_grid.append(imag_row)
        pointf.append(pointf_row)
    
    return imag_grid, pointf
def load_images(img_dir: str):
    face_images = []
    dir_path = os.path.dirname(os.path.realpath(__file__))
    img_dir_path = dir_path + "/" + img_dir
    for file in os.listdir(img_dir_path):
        filepath = img_dir_path + file
        if filepath.lower().endswith(('.png', '.jpg', '.jpeg')):
            face_images.append(Image.get_array_from_file(img_dir + "/" + file))
    return face_images
def split_png(file, rows, cols) -> List[List[ndarray]]:
    pictures = ni.get_array_from_file(file)
    n, m, _ = pictures.shape
    di = n // rows
    dy = m // cols

    return [[
        pictures[i * di:(i + 1) * di, j * di:(j + 1) * dy, :]
        for j in range(cols)
    ] for i in range(rows)]
Beispiel #4
0
def sprite_array(row, col, file):
    array = np.get_array_from_file(file)
    m, n, _ = array.shape
    di = m // row
    dj = n // col
    result = []
    for i in range(row):
        row = []
        for j in range(col):
            row.append(array[i * di:(i + 1) * di, j * dj:(j + 1) * dj, :])
        result.append(row)
    return result
Beispiel #5
0
 def split_sprite_sheet(self, file: str):
     self.array = np.get_array_from_file(file)
     m, n, _ = self.array.shape  # pixels
     di = m // self.rows
     dj = n // self.cols
     sub_arrays = [[self.array[i*di:(i+1)*di, j*di:(j+1)*dj, :]
                   for j in range(self.cols)] for i in range(self.rows)]
     for i in range(self.rows):
         for j in range(self.cols):
             cell = self.__cells[i][j]
             cell.texture = np.get_texture_from_array(sub_arrays[i][j])
             cell.scale_to_width(self.scale)
Beispiel #6
0
from turtle import position, window_height, window_width
from pycat.base import NumpyImage
from pycat.core import Window

w = Window(width=600, height=400)

oimage = NumpyImage.get_array_from_file("hummmm.png")
print(oimage.shape)

image01 = NumpyImage.get_texture_from_array(oimage[:84, :150:])
image02 = NumpyImage.get_texture_from_array(oimage[:84, 150::])
image03 = NumpyImage.get_texture_from_array(oimage[84:, :150:])
image04 = NumpyImage.get_texture_from_array(oimage[84:, 150::])

x0y0 = w.create_sprite(x=225, y=158)
x1y0 = w.create_sprite(x=375, y=158)
x0y1 = w.create_sprite(x=225, y=242)
x1y1 = w.create_sprite(x=375, y=242)

x0y0.texture = image01
x1y0.texture = image02
x0y1.texture = image03
x1y1.texture = image04

w.run()
Beispiel #7
0
from pycat.core import Window
from pycat.base import NumpyImage as Image

w = Window()
image01 = Image.get_array_from_file("4_0.jpg")
image02 = Image.get_array_from_file("10_0.jpg")
image03 = Image.get_array_from_file("11_0.jpg")
image04 = Image.get_array_from_file("16_0.jpg")
image06 = Image.get_array_from_file("22_0.jpg")

rows1, cols1, channels1 = image01.shape
rows2, cols2, channels2 = image02.shape
rows3, cols3, channels3 = image03.shape
rows4, cols4, channels4 = image04.shape
rows6, cols6, channels6 = image06.shape

isprite1 = w.create_sprite()
isprite1.scale = 1.6
isprite1.texture = Image.get_texture_from_array(image01)
isprite1.position = (430, 460)

isprite2 = w.create_sprite()
isprite2.scale = 1.6
isprite2.texture = Image.get_texture_from_array(image02)
isprite2.position = (860, 460)

isprite3 = w.create_sprite()
isprite3.scale = 1.6
isprite3.texture = Image.get_texture_from_array(image03)
isprite3.position = (360, 290)
Beispiel #8
0
from pycat.core import Window
from pycat.base import NumpyImage

w = Window()
original_image = NumpyImage.get_array_from_file("view.PNG")
print(original_image.shape)

sub = original_image[:386, :567, :]
sub2 = original_image[386:, 567:, :]
# sub3 = original_image[386:, :567, :]
# sub4 = original_image[:386, 567:, :]

s = w.create_sprite(x=250, y=200)
s.texture = NumpyImage.get_texture_from_array(sub)
s2 = w.create_sprite(x=900, y=400)
s2.texture = NumpyImage.get_texture_from_array(sub2)
w.run()
from pycat.core import Window, Sprite, KeyCode
from pycat.base import NumpyImage as Image
import random
w = Window()
original_image = Image.get_array_from_file("baboon.jpeg")


def get_max_rgb_image():
    rows, cols, channels = original_image.shape
    new_image = Image(rows, cols)
    for i in range(rows):
        for j in range(cols):
            r, g, b, a = original_image[i][j]
            new_image[i][j] = max(r, g, b)
    return new_image


def get_luminance_image():
    rows, cols, channels = original_image.shape
    luminance_image = Image(rows, cols)
    for i in range(rows):
        for j in range(cols):
            r, g, b, a = original_image[i][j]
            luminance_image[i][j] = .299 * r + .587 * g + .114 * b
    return luminance_image


def get_complement_image():
    rows, cols, channels = original_image.shape
    complement_image = Image(rows, cols, channels)
    for i in range(rows):
Beispiel #10
0
    def on_left_click(self):
        original_image = Image.get_array_from_file(random.choice(face))

        image = original_image[self.i0:self.i1, self.j0:self.j1, :]
        self.texture = Image.get_texture_from_array(image)
Beispiel #11
0
def load_images(img_dir: str):
    face_images = []
    dir_path = os.path.dirname(os.path.realpath(__file__))
    img_dir_path = dir_path + "/" + img_dir
    for file in os.listdir(img_dir_path):
        filepath = img_dir_path + file
        if filepath.lower().endswith(('.png', '.jpg', '.jpeg')):
            face_images.append(img_dir + "/" + file)
    return face_images


face = load_images("resized_faces")
print(face)

window = Window()
original_image = Image.get_array_from_file(random.choice(face))
print(original_image.shape)
rows, cols, channels = original_image.shape


class MyCustomSprite(Sprite):
    def on_create(self):
        self.i0 = 0
        self.i1 = 0
        self.j0 = 0
        self.j1 = 0

    def on_update(self, dt):
        pass

    def set_range(self, i0, i1, j0, j1):
from pycat.core import Window
from pycat.base import NumpyImage as Image
import os
import random

window = Window()
original_image = Image.get_array_from_file("average_face.jpg")
print(original_image.shape)
rows, cols, channels = original_image.shape


def load_images(img_dir: str):
    face_images = []
    dir_path = os.path.dirname(os.path.realpath(__file__))
    img_dir_path = dir_path + "/" + img_dir
    for file in os.listdir(img_dir_path):
        filepath = img_dir_path + file
        if filepath.lower().endswith(('.png', '.jpg', '.jpeg')):
            face_images.append(Image.get_array_from_file(img_dir + "/" + file))
    return face_images


face_images = load_images("resized_faces")
original_image = random.choice(face_images)

image_sprite = window.create_sprite()
image_sprite.texture = Image.get_texture_from_array(original_image)
image_sprite.position = (400, 400)
original_image = random.choice(face_images)
left_eye_image = original_image[50:70, 25:40, :]
left_eye = window.create_sprite()
Beispiel #13
0

def load_images(img_dir: str):
    face_images = []
    dir_path = os.path.dirname(os.path.realpath(__file__))
    img_dir_path = dir_path + "/" + img_dir
    for file in os.listdir(img_dir_path):
        filepath = img_dir_path + file
        if filepath.lower().endswith(('.png', '.jpg', '.jpeg')):
            face_images.append(img_dir + "/" + file)
    return face_images


face_list = load_images("resized_faces")

image01 = Image.get_array_from_file(random.choice(face_list))
image02 = Image.get_array_from_file(random.choice(face_list))
image03 = Image.get_array_from_file(random.choice(face_list))
image04 = Image.get_array_from_file(random.choice(face_list))
image06 = Image.get_array_from_file(random.choice(face_list))

rows1, cols1, channels1 = image01.shape
rows2, cols2, channels2 = image02.shape
rows3, cols3, channels3 = image03.shape
rows4, cols4, channels4 = image04.shape
rows6, cols6, channels6 = image06.shape

isprite1 = w.create_sprite()
isprite1.scale = 1.6
isprite1.texture = Image.get_texture_from_array(image01)
isprite1.position = (430, 460)