def turnhalftone(path, sample, scale, cyan=5): sample = int(sample) scale = int(scale) h = halftone.Halftone(path) h.make(angles=[24, 75, 0, 45], antialias=False, filename_addition='_halftone', percentage=50, sample=sample, scale=scale, style='grayscale')
def main(): img = cv2.imread('Lenna.jpg', 3) print(img.shape) img = tr.RGB2YCBCR(img) Y, Cr, Cb = cv2.split(img) pathlib.Path('./SecondAttempt').mkdir(parents=True, exist_ok=True) (Sl, (Sh1, Sv1, Sd1), (Sh2, Sv2, Sd2)) = pywt.wavedec2(Y, 'db1', level=2) ReducedCb = downscale_local_mean(Cb, (2, 2)) ReducedCr = downscale_local_mean(Cr, (2, 2)) CbPlus = ReducedCb CbMinus = ReducedCb for i in range(0, ReducedCb.shape[0]): for j in range(0, ReducedCb.shape[1]): if ReducedCb[i, j] < 0: CbPlus[i, j] = 0 elif ReducedCb[i, j] > 0: CbMinus[i, j] = 0 CrPlus = ReducedCr CrMinus = ReducedCr for i in range(0, ReducedCr.shape[0]): for j in range(0, ReducedCr.shape[1]): if ReducedCr[i, j] < 0: CrPlus[i, j] = 0 elif ReducedCb[i, j] > 0: CrMinus[i, j] = 0 ReducedCbMinus = downscale_local_mean(CbMinus, (2, 2)) # Sd1 = ReducedCbMinus # Sh2 = CrPlus # Sv2 = CbPlus # Sd2 = CrMinus NewYSecondTry = pywt.waverec2( (Sl, (Sh1, Sv1, ReducedCbMinus), (CrPlus, CbPlus, CrMinus)), 'db1') cv2.imwrite("./SecondAttempt/NewYSecondTry.jpg", NewYSecondTry) cv2.waitKey(0) cv2.destroyAllWindows() h = hf.Halftone('./SecondAttempt/NewYSecondTry.jpg') h.make(angles=[0, 15, 30, 45], antialias=True, percentage=10, sample=1, scale=2, style='grayscale')
def main(palette, width, height, social, text, search): palettes = { 'classic': { 'colorstr': '#000000', 'txtcolor': (255, 255, 255) }, 'white': { 'colorstr': '#ffffff', 'txtcolor': (0, 0, 0) }, 'barbara': { 'colorstr': '#e34234', 'txtcolor': (255, 255, 255) }, 'town': { 'colorstr': '#e0B0ff', 'txtcolor': (0, 0, 0) }, } pic = None while not pic: try: pic, word = get_image(width, height, search) except Exception as e: print(e) continue if text: word = text.upper() else: word = word.upper() if palette: color = palettes[palette] else: color = palettes[random.choice(list(palettes.keys()))] if height <= width: b_width = height // 40 f_margin = width // 8 elif width < height: b_width = width // 40 f_margin = height // 8 b_double = b_width * 2 h = halftone.Halftone('fimage.jpg') h.make(style='grayscale', angles=[random.randrange(360)]) pic = Image.open('fimage_halftoned.jpg') pic = pic.filter(ImageFilter.DETAIL) pic = pic.filter(ImageFilter.SHARPEN) pic = select_section(pic, width, height, b_width) border = Image.new('RGB', (width, height), color=color['colorstr']) border.paste(pic, (b_width, b_width)) pic = border font = get_font_size(word, width, height, f_margin) x, y = font.getsize_multiline(word) inset = Image.new('RGB', (x + b_double, y + b_double), color=color['colorstr']) draw = ImageDraw.Draw(inset) draw.text((b_width, b_width), word, color['txtcolor'], font=font) pic.paste(inset, ((width - (x + b_double)) // 2, (height - (y + b_double)) // 2)) pic.save('output.png') if social: try: post_to_mastodon('output.png', word) except Exception as e: print(e) try: post_to_twitter('output.png', word) except Exception as e: print(e) cleanup()
def testOthers(self): h = halftone.Halftone('1.jpg') h.make(style='color', filename_add='4', percentage=100, antialias=True) h.make(style='color', filename_add='5', percentage=0, antialias=True)
def testhalftone_gray(self): h = halftone.Halftone('1.jpg') h.make(style='grayscale', filename_add='1')
import cv2 from encrypt import encrypt import halftone def resize(img, shape): return cv2.resize(img, (shape[1], shape[0])) secret_path = 'secret_image/top_secret.jpg' secrethalftone_path = 'secret_image/top_secret_halftoned.jpg' share1_path = 'share1.jpg' share2_path = 'share2.jpg' secret = cv2.imread(secret_path, 0) secret = resize(secret, (400, 600)) share1 = cv2.imread(share1_path, 0) share1 = resize(share1, (400, 600)) share2 = cv2.imread(share2_path, 0) share2 = resize(share2, (400, 600)) cv2.imwrite(secret_path, secret) h = halftone.Halftone(secret_path) h.make(sample=2, scale=5) # main secret = cv2.imread(secrethalftone_path, 0) encrypt(secret, share1, share2)