예제 #1
0
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
예제 #2
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)
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
예제 #4
0
 def on_update(self, dt):
     if window.get_key_down(KeyCode._1):
         self.texture = Image.get_texture_from_array(original_image)
     if window.get_key_down(KeyCode._2):
         self.texture = max_rgb_image.texture
     if window.get_key_down(KeyCode._3):
         self.texture = luminance_image.texture
     if window.get_key_down(KeyCode._4):
         self.texture = complement_image.texture
예제 #5
0
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)]
 def on_update(self, dt):
     if w.get_key_down(KeyCode.UP):
         self.texture = Image.get_texture_from_array(original_image)
     if w.get_key_down(KeyCode.DOWN):
         self.texture = max_rgb_image.texture
     if w.get_key_down(KeyCode.LEFT):
         self.texture = luminance_image.texture
     if w.get_key_down(KeyCode.RIGHT):
         self.texture = complement_image.texture
     if w.get_key_down(KeyCode.Z):
         self.texture = ohman_image.texture
예제 #7
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
예제 #8
0
def create_sprite(splited, scale, x0, y0, w: Window, Csprite=Sprite):
    rows, cols = len(splited), len(splited[0])
    grid = []
    for i in range(rows):
        row = []
        for j in range(cols):
            p = w.create_sprite(Csprite)
            p.texture = ni.get_texture_from_array(splited[i][j])
            p.scale = scale
            p.x = x0 + j * (2 + p.width)
            p.y = y0 + i * (2 + p.height)
            r = row.append(p)
        grid.append(r)
예제 #9
0
 def data(self):
     size = (self.rows, self.cols)
     texture_dict = dict()
     array_index = [[0 for j in range(self.cols)] for i in range(self.rows)]
     texture_arrays = []
     current_index = 0
     for i in range(self.rows):
         for j in range(self.cols):
             t = self.__cells[i][j].texture
             if t not in texture_dict:
                 texture_dict[t] = current_index
                 texture_arrays.append(np.get_array_from_texture(t))
                 current_index += 1
             array_index[i][j] = texture_dict[t]
     print(current_index)
     return (size, texture_arrays, array_index)
예제 #10
0
def create(w: Window,
           sub_array: List[List[ndarray]],
           scale=1,
           sprite_cls=Sprite):
    s, n = len(sub_array), len(sub_array[0])
    grid: List[List[Sprite]] = []
    for i in range(s):
        row = []
        for j in range(n):
            s = w.create_sprite(sprite_cls)
            s.texture = np.get_texture_from_array(sub_array[i][j])
            s.scale = scale
            s.x = s.width / 2 + (j * s.width)
            s.y = s.height / 2 + (i * s.height)
            row.append(s)
        grid.append(row)
예제 #11
0
 def data(self):
     size = (self.rows, self.cols)
     texture_dict = dict()
     array_index = [[0 for j in range(self.cols)] for i in range(self.rows)]
     texture_arrays = []  # stores the actual pixel data
     current_index = 0
     # we should add tag and layer data too!
     for i in range(self.rows):
         for j in range(self.cols):
             cell = self.__cells[i][j]
             t = cell.texture
             if t not in texture_dict:
                 texture_dict[t] = current_index
                 texture_arrays.append(np.get_array_from_texture(t))
                 current_index += 1
             array_index[i][j] = texture_dict[t]
     print(current_index)
     return (size, self.__cells[0][0].scale, texture_arrays, array_index)
예제 #12
0
 def create_from_data_file(cls,
                           file,
                           x: float = None,
                           y: float = None,
                           scale: float = 10,
                           cell_gap: float = 1,
                           cell_cls: Callable[..., T] = Sprite):
     size, texture_arrays, array_index = pickle.load(open(file, 'rb'))
     grid = cls(size[0], size[1], x, y, scale, cell_gap, cell_cls)
     m, n = size
     for i in range(m):
         for j in range(n):
             cell = grid.__cells[i][j]
             width = cell.width
             array = texture_arrays[array_index[i][j]]
             t = np.get_texture_from_array(array)
             cell.texture = t
             cell.scale_to_width(width)
     return grid
예제 #13
0
    def data(self):
        size = (self.rows, self.cols)
        texture_dict: Dict[Texture, int] = dict()
        array_index = [[0 for j in range(self.cols)] for i in range(self.rows)]
        tags = [[[] for j in range(self.cols)] for i in range(self.rows)]
        texture_arrays = []  # stores the actual pixel data
        current_index = 0
        # we should add tag and layer data too!
        for i in range(self.rows):
            for j in range(self.cols):
                cell = self.__cells[i][j]
                for tag in cell.tags:
                    tags[i][j].append(tag)

                t = cell.texture
                if t not in texture_dict:
                    texture_dict[t] = current_index
                    current_index += 1
                    texture_arrays.append(np.get_array_from_texture(t))
                    
                array_index[i][j] = texture_dict[t]
        print(current_index)
        return (size, texture_arrays, array_index, tags)
예제 #14
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)
예제 #15
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)
예제 #16
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()
예제 #17
0
 def get_image_array(self) -> ndarray:
     array = IP.get_array_from_texture(self.texture)
     return array[:, :, :3]
예제 #18
0
 def set_texture(self, array: ndarray):
     self.texture = IP.get_texture_from_array(array)
예제 #19
0
 def get_luminance_array(self, array: ndarray = None) -> ndarray:
     if array is None:
         IP.get_luminance_array(self.get_image_array())
     return IP.get_luminance_array(array)
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()
 def on_create(self):
     self.texture = Image.get_texture_from_array(original_image)
     self.scale = 2
     self.position = w.center
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):
예제 #23
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)
예제 #24
0
window = Window()


class ImageSprite(Sprite):
    def on_create(self):
        self.image = "baboon.jpeg"
        self.scale = 2
        self.y = window.height / 2


input_sprite = window.create_sprite(ImageSprite)
input_sprite.x = (window.width - input_sprite.width) / 2
output_sprite = window.create_sprite(ImageSprite)
output_sprite.x = (window.width + output_sprite.width) / 2

image = NumpyImage.get_array_from_texture(input_sprite.texture)
rows, cols, channels = image.shape

img = NumpyImage(rows, cols)
for i in range(rows):
    for j in range(cols):
        intensity = (j * 255) // (cols - 1)
        img[i, j] = intensity

# for i in range(rows):
#     for j in range(cols):
#         channel_sum = 0
#         # print(image[i][j])
#         for k in range(channels - 1):
#             channel_sum = max(channel_sum, image[i][j][k])
#         image[i][j] = [channel_sum, channel_sum, channel_sum, 255]
예제 #25
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()
예제 #26
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):