def load_transparent_test(self): """ load_transparent_test: Load an image with a known transparent channel. """ C = ph.load("tests/tree.png") alpha = C.alpha.sum() assert alpha.sum() > 0
def load_missing_file_test(self): """ load_missing_file_test Raise an exception if a file is missing """ C = ph.load("THIS_IS_A_MISSING_FILE.png") alpha = C.alpha.sum() assert alpha.sum() > 0
def _apply_eye_makeup(image, **kwargs): # Load the image in, transform the coordinates to the shape of the canvas if isinstance(image, str): canvas = ph.load(image) landmarks = face_finder(image)[0] elif isinstance(image, ph.Canvas): canvas = image landmarks = face_finder(canvas.img[:, :, :3])[0] else: print(f"Unknown type {type(image)}") transform(canvas, landmarks) return eye_makeup(canvas, landmarks, **kwargs)
def direct_load_test(self): """ direct_load_test: Load an image without creating a canvas. """ C = ph.Canvas(bg="yellow") C += ph.circle(color="g") C2 = ph.Canvas() with tempfile.NamedTemporaryFile(suffix=".png") as F: C.save(F.name) C2 = ph.load(F.name) dist = C.img[:, :, :3] - C2.img[:, :, :3] dist = dist.astype(float) / 255 assert_equal(dist.sum(), 0)
def person_ghost(f_image): loc = C.shape[1] // 2, C.shape[0] // 2 for i in tqdm(range(20)): C2 = C.copy() C2 += ph.filters.gaussian_blur(0.1, 0.1) pastebox(C, C2.img, ~mask, loc) return C f_image = "movies/000750.jpg" F_IMAGE = sorted(glob.glob('movies/*.jpg')) random.shuffle(F_IMAGE) for f in tqdm(F_IMAGE): f_final = os.path.join(save_dest, os.path.basename(f)) mask = load_mask(f) if mask is None: continue C = ph.load(f) C = person_ghost(f) #C.show() C.save(f_final) print(f_final)
if flip_vertical: img = cv2.flip(img, 0) if rotate_angle: img = imutils.rotate(img, rotate_angle) return img f_jpg = "data/source_images/tessa1.jpg" landmarks = face_finder(f_jpg)[0] compute_centroids(landmarks) ph.load(f_jpg).resize(0.5).save("docs/images/tessa1_src.jpg") C = ph.load(f_jpg) org = C.copy() eye, mask, full_mask = cutbox(C, landmarks["right_eye"], 50) # Blow out the mask a bit kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) mask = cv2.dilate(mask, kernel, iterations=10) minds_eye = landmarks["right_eye_centroid"] + landmarks["left_eye_centroid"] minds_eye /= 2 minds_eye[1] -= 100 minds_eye = minds_eye.round().astype(int)
def test_canvas(): canvas = ph.load("tests/tessa1.jpg") return canvas
plt.plot(df.frame_n, df[key]) plt.plot( df.frame_n, smooth(df[key], 10), 'k', ) plt.show() exit() df = df.sort_values(key)[::-1] c = ph.Canvas() for frame_n, val in zip(df.frame_n[:20], df[key][:20]): f_jpg = f'data/frames/single_movie/Die.Hard.1988.720p.BRRip.x264-x0r.mkv/{frame_n:08d}.jpg' c = ph.load(f_jpg) min_dim = min(c.img.shape[0], c.img.shape[1]) scale = 256 / min_dim #c = c.resize(scale) #c = c.resize(output_size=(256,256)) # Center crop #remaining = max(c.img.shape[0], c.img.shape[1]) - 256 #c.img = c.img[:, remaining//2:remaining//2+256] c += ph.text(f"frame:{frame_n}", font_size=0.25, y=-1.5) c += ph.text(f"{key}:{val:0.3f}", font_size=0.25, y=1.5) c.show(0)
mask = None with h5py.File(f_h5) as h5: for key in h5: if h5[key].attrs['label'] != 'person': continue #if h5[key].attrs['label'] == 'person': # continue if mask is None: mask = h5[key]['mask'][...] else: mask += h5[key]['mask'][...] C = ph.load(f_image) print(C.shape, C.img.shape) def pastebox(canvas, img, fmask, location): mask = np.zeros((*canvas.img.shape[:2], 3), canvas.img.dtype) mask[fmask] = [255] * 3 #mask[:,:] = [255,255,255] #canvas.img[fmask] = 0 #print(loc) #print(canvas.shape) #canvas.show() #exit() print(mask.shape, canvas.img.shape, img.shape)
import pixelhouse as ph from greasepaint import eyeliner, eyeshadow vaporwave_pal = ["#FF6AD5", "#C774E8", "#AD8CFF", "#8795E8", "#94D0FF"] f_jpg = "data/source_images/tessa1.jpg" def crop_eyes(canvas, f_save): canvas = canvas.copy() canvas.img = canvas.img[200:270, 122:340] return canvas.save(f_save) canvas = ph.load(f_jpg) crop_eyes(canvas, "docs/images/eyes0.jpg") canvas = eyeliner(canvas) crop_eyes(canvas, "docs/images/eyes1.jpg").show() canvas.resize(.5).save("docs/images/tessa1_liner.jpg") for k, p in enumerate(vaporwave_pal): canvas = eyeshadow(f_jpg, color=p) crop_eyes(canvas, f"docs/images/eyes{k+2}.jpg")
import pixelhouse as ph import numpy as np import glob F_FLOW = sorted(glob.glob("data/flows/*")) F_IMG = sorted(glob.glob("data/frames/*")) for f0, f1 in zip(F_IMG, F_FLOW): flow = np.load(f1) c0 = ph.load(f0).resize(output_size=(flow.shape[:2][::-1])) #flow -= flow.min() #flow/= flow.max() flow += 3 flow /= 6 print(flow.min(), flow.max()) flow = np.clip(flow, 0, 1) c1 = c0.blank() c1.img[:, :, 0] = (flow[:, :, 0] * 255).astype(np.uint8) c1.img[:, :, 2] = (flow[:, :, 1] * 255).astype(np.uint8) c1 += ph.filters.gaussian_blur() c1.show() #c0.show()
"Long", # Good, but entropy can be higher >= 0.4 "Medium", # Good, multiple character interactions "Medium Close-Up", # Good, character interactions ] for key in cols: dx = df[df[key] > 0.90] dx = dx[dx["frame_entropy"] < entropy_vals[key]] time = dx["Length (seconds)"].sum() / 60 print(f"{key} total minutes {time:0.2f}") df = df[df["frame_entropy"] < entropy_vals[target_col]] df = df[df[target_col] > 0.90] for _, row in df.iterrows(): n = int(row["Scene Number"]) for k in range(1, 4): print(k) f_img = f"data/scene_change/{name}/Die.Hard.1988.720p.BRRip.x264-x0r-Scene-{n:04d}-{k:02d}.jpg" assert os.path.exists(f_img) c = ph.load(f_img) ex = row["frame_entropy"] c += ph.text(f"Entropy {ex:0.3f}", x=1.5, y=-1.5, font_size=0.25) ex = row[target_col] c += ph.text(f"{target_col} {ex:0.3f}", x=-1.5, y=-1.5, font_size=0.25) c.show()