import cv2 import numpy as np from utils import halftoning, plot_histogram from argparser import Parser args = Parser() img_path = args.get_arg('image') output_filename = args.get_arg('output_path') error_dist = args.get_arg('error_dist') sweep_mode = args.get_arg('sweep_mode') display_mode = args.get_arg('display_mode') img_path = 'images/peppers.png' if img_path is None else img_path img = cv2.imread(img_path, cv2.IMREAD_COLOR) res_img = halftoning(np.array(img), edist_id=error_dist, sweep_mode=sweep_mode) if output_filename is not None: cv2.imwrite(output_filename, res_img) if display_mode == 'hist': plot_histogram(res_img) elif display_mode is None or display_mode == 'images': cv2.imshow('source image', img) cv2.imshow('resulting image', res_img) cv2.waitKey(0) cv2.destroyAllWindows()
import cv2 import numpy as np import sys from argparser import Parser from masks import get_mask from filter_utils import show_filtered_image, filter_image, add_filters, show_src_and_filtered_image MASK_COUNT = 11 parser = Parser() filename = parser.get_arg('image') mask_id = parser.get_arg('mask') output_filename = parser.get_arg('output_path') output_combined_filename = parser.get_arg('output_combined_path') hflip = parser.get_arg('hflip') skip_image_show = parser.get_arg('skip_image_show') img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE) flip_axis = 1 if hflip else None (filtered_image, combined_filters_image) = show_filtered_image( img,\ mask_id,\ flip_axis=flip_axis,\ show_images=not skip_image_show\ ) if (output_filename): cv2.imwrite(output_filename, filtered_image) if (combined_filters_image is not None and output_combined_filename): cv2.imwrite(output_combined_filename, combined_filters_image)
import cv2 import numpy as np from matplotlib import pyplot as plt from argparser import Parser from codify import codify from decodify import decodify from bitplane_utils import extract_rgb_bitplane, merge_rgb args = Parser() # Command arguments mode = args.get_arg('mode') imgin_path = args.get_arg('imagein') imgout_path = args.get_arg('imageout') textin_path = args.get_arg('textin') textout_path = args.get_arg('textout') bitplan = args.get_arg('bitplan') img = cv2.imread(imgin_path, cv2.IMREAD_COLOR) if mode == 'codify': res_img = codify(img, open(textin_path).read(), bitplan=bitplan) cv2.imwrite(imgout_path, res_img) elif mode == 'decodify': decodified_msg = decodify(img, bitplan=bitplan) textout_file = open(textout_path, 'w') textout_file.write(str(decodified_msg)) textout_file.close() elif mode == 'bitplanes': for bitplane in [0, 1, 2, 7]: bitplane_blue, bitplane_green, bitplane_red = extract_rgb_bitplane(img, bitplane) bitplanes_img = merge_rgb(bitplane_blue, bitplane_green, bitplane_red)
import cv2 from argparser import Parser from interpolations import closest_neighboor args = Parser() mode = args.get_arg('mode') input_path = args.get_arg('input-image') output_path = args.get_arg('output-image') angle = args.get_arg('angle') scale_factor = args.get_arg('scale-factor') dimension = args.get_arg('image-dimension') img = cv2.imread(input_path, cv2.IMREAD_GRAYSCALE) interpolated_img = closest_neighboor(img, scale_factor=scale_factor) cv2.imshow('source img', img) cv2.imshow('interpolated img', interpolated_img) cv2.waitKey(0) cv2.destroyAllWindows()
import cv2 import numpy as np from matplotlib import pyplot as plt from argparser import Parser from thresholding_method import ThresholdingMethod, ThresholdingConfig args = Parser() # Command arguments img_path = args.get_arg('image') out_path = args.get_arg('out') method = args.get_arg('method') T = args.get_arg('T') n = args.get_arg('n') k = args.get_arg('k') R = args.get_arg('R') p = args.get_arg('p') q = args.get_arg('q') display_mode = args.get_arg('display_mode') img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED) thres_method = ThresholdingMethod(method) res_img = thres_method.exec(img, ThresholdingConfig(T=T, n=n, k=k, R=R, p=p, q=q)) if (out_path): cv2.imwrite(out_path, res_img) if display_mode == 'hist': (h, w) = res_img.shape print(np.count_nonzero(res_img == 0) / (h * w)) plt.hist(img.ravel(), 256, [0, 256])