| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import numpy as np
- def wavelet(image, width=None):
- shape = image.shape
- if len(shape) != 2 or shape[0] != shape[1]:
- raise(f"Expected quadratic image but got data with shape: {shape}")
- if width is None:
- width = shape[0]
- if shape[0] < width:
- raise(f"Image with shape {shape} is smaller then the requested size {width}.")
- result = image.copy()
- half = width // 2
- for y in range(half):
- for x in range(half):
- px = 2 * x
- py = 2 * y
- result[y, x] = image[py, px]
- result[y, x + half] = image[py, px + 1] - image[py, px]
- result[y + half, x] = image[py + 1, px] - image[py, px]
- result[y + half, x + half] = image[py + 1, px + 1] - image[py, px]
- return result
- def refine(image):
- shape = image.shape
- if len(shape) != 2 or shape[0] != shape[1]:
- raise(f"Expected quadratic image but got data with shape: {shape}")
- width = shape[0]
- while width > 1:
- image = wavelet(image, width)
- width = width // 2
- return image
- def rotate(image):
- shape = image.shape
- if len(shape) != 2 or shape[0] != shape[1]:
- raise(f"Expected quadratic image but got data with shape: {shape}")
- result = image.copy()
- w = shape[0]
- for y in range(w):
- for x in range(w):
- result[x,y] = image[y,x]
- return result
- def mirror(image):
- shape = image.shape
- if len(shape) != 2 or shape[0] != shape[1]:
- raise(f"Expected quadratic image but got data with shape: {shape}")
-
- result = image.copy()
- w = shape[0]
- for y in range(w):
- for x in range(w):
- result[w - y - 1, x] = image[y,x]
- return result
|