def blur_gaussian(img_paths, radius=3, size=None, write=True): """blur_gaussian(img_paths, radius=3, size=None, write=True) Takes images(s) and blurs them using a gaussian kernel based on a given radius. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be blurred. :type radius: int :param radius: The radius of the gaussian kernel. If nothing is entered for this parameter, it will default to 3. :type size: list, NoneType :param size: The dimensions of the gaussian kernel. Must be entered in :type write: bool :param write: Whether to write the blurred image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(radius, [int, float]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) INTERNAL._type_checker(size, [int, list, np.ndarray, None]) return INTERNAL._convolution_handler(img_paths, radius=radius, type_kernel="gaussian", size=size, custom=None, write=write)
def combine(img1, img2, out_path, write=True): """combine(img1, img2, out_path, write=True) Combines the data of two PyifxImages, ImageVolumes, or ImageLists to form new PyifxImages. :type img1: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img1: The first image to be added to the combination. :type img2: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img2: The second image to be added to the combination. Arguments of type ImageVolume and list can be used in conjunction, but images of type PyifxImage must be used together. :type out_path: str :param out_path: The path that the combine image(s) will be written to. :type write: bool :param write: Whether to write the image or not. :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(img1, [PyifxImage, ImageVolume, list]) INTERNAL._type_checker(img2, [PyifxImage, ImageVolume, list]) INTERNAL._type_checker(out_path, [str]) INTERNAL._type_checker(write, [bool]) return INTERNAL._combine_handler(img1, img2, out_path, write=write)
def __init__(self, input_path, output_path, prefix="_", level=1): """ __init__(self, input_path, output_path, prefix="_", level=1) The ImageVolume constructor method. :type input_path: str :param input_path: The path to the directory where the images are located. :type output_path: str :param output_path: The path where images in the volume should be saved. :type prefix: str :param prefix: The prefix for edited image file names. If nothing is entered for this parameter, it will default to "_". :type level: int :param level: The depth to which images should be imported from subdirectories. For infinite depth, set this value to 0. If nothing is entered, this value will default to 1, importing from the root directory exclusively. :return: ImageVolume instance :rtype: pyifx.misc.ImageVolume """ INTERNAL._type_checker(input_path, [str]) INTERNAL._type_checker(output_path, [str]) INTERNAL._type_checker(prefix, [str]) INTERNAL._type_checker(level, [int]) self.input_path = input_path self.output_path = output_path self.level = level self.prefix = prefix self.volume = self.volume_to_list(level)
def set_volume(self, new_volume): """set_volume(self, new_volume): Sets the instances volume property and returns the volume. :type new_volume: list :param new_volume: What the instances volume will be set to. :return: ImageVolume instance :rtype: pyifx.misc.ImageVolume """ if new_volume != []: for img in new_volume: INTERNAL._type_checker(img, [PyifxImage]) self.volume = new_volume return self
def brighten(img_paths, percent=45, write=True): """ brighten(img_paths, percent=45, write=True) Takes image(s) and brightens them. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be brightened. :type percent: int :param percent: How much the image(s) should be brightened. If nothing is entered for this parameter, it will default to 45. The parameter must be between 0 and 100 (inclusive). :type write: bool :param write: Whether to write the brightened image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(percent, [float, int]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) if percent < 0 or percent > 100: raise ValueError( "Invalid value used: percentage must be between 0 and 100.") return INTERNAL._brightness_handler(img_paths, percent / 100, "b", write=write)
def detect_edges(img_paths, write=True): """ detect_edges(img_paths, write=True) Takes image(s) and creates new images focusing on edges. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be manipulated. :type write: bool :param write: Whether to write the manipulated image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) return INTERNAL._detect_edges_handler(img_paths, write=write)
def to_grayscale(img_paths, write=True): """ to_grayscale(img_paths, write=True) Takes image(s) and converts them to grayscale. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be converted. :type write: bool :param write: Whether to write the grayscale image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) return INTERNAL._saturation_handler(img_paths, 1, "ds", write=write)
def color_overlay(img_paths, color, opacity=30, write=True): """ color_overlay(img_paths, color, opacity=30, write=True) Takes image(s) and applies a specified color over it/them. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be manipulated. :type color: numpy.ndarray, list :param color: The color to be applied over the image(s). This parameter should be specified in the format [Red, Green, Blue], with each component being between 0 and 255 (inclusive). :type opacity: int :param opacity: How visible the color should be. If nothing is entered for this parameter, it will default to 30. It should be between 0 and 100 (inclusive). :type write: bool :param write: Whether to write the darkened image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(opacity, [float, int]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) if len(color) != 3: raise ValueError( "Invalid value used: Please enter a color using the following format: [R,G,B]." ) for channel in color: INTERNAL._type_checker(channel, [int]) if channel < 0 or channel > 255: raise ValueError( "Invalid value used: Color channels must be between 0 and 255." ) if opacity < 0 or opacity > 100: raise ValueError( "Invalid value used: opacity must be between 0 and 100.") return INTERNAL._color_overlay_handler(img_paths, color, opacity / 100, write=write)
def convert_dir_to_images(self, input_dir, level=1): """ convert_dir_to_images(input_dir, level=1): Converts files from a given directory into PyifxImage instances. :type input_dir: str :param input_dir: The directory to read files from. :type level: int :param level: The depth to which images should be imported from subdirectories. For infinite depth, set this value to 0. If nothing is entered, this value will default to 1, importing from the root directory exclusively. :return: List with elements of type PyifxImage :rtype: list """ INTERNAL._type_checker(input_dir, [str]) INTERNAL._type_checker(level, [int]) if (level < 0): raise ValueError("Please enter a level greater than 0.") images = [] possible_extensions = ['.jpg', '.jpeg', '.png'] def add_to_images(internal_input_dir, depth): for f in os.listdir(internal_input_dir): new_path = os.path.join(internal_input_dir, f) if (level == 0 or depth < level) and os.path.isdir(new_path): add_to_images(new_path, depth + 1) if os.path.splitext(f)[1] in possible_extensions: images.append( PyifxImage( new_path, os.path.join( self.get_output_path(), f"{self.get_prefix()}{os.path.split(f)[1]}"))) add_to_images(input_dir, 1) self.set_volume(images) return images
def rewrite_file(img_paths): """ rewrite_file(img_paths) Takes image(s) and writes them to an output destination based on their properties. Intended for use with changes to pyifx class instances. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be rewritten. :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ NTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) return INTERNAL._rewrite_file_handler(img_paths)
def __init__(self, input_path, output_path=None, img=None, create_image=True): """ __init__(self, path, output_path=None, img=None, create_image=True) The PyifxImage constructor method. :type path: str, NoneType :param path: The path to where the image is located. Only use None as a value if the image property of the instace is being specified. :type output_path: str, NoneType :param output_path: The path to where the edited image should be saved. Only use None as a value if the instance is not going to be saved to a file. :type img: numpy.ndarray, NoneType :param img: The data used for image editing & processing. The image property of the class will be set based on the input path unless this parameter is set to a value other than None. :type create_image: bool :param create_image: Specify whether the image property should be read from the input path. If this is set to true, the image at the input path will override the specified image parameter. :return: PyifxImage instance :rtype: pyifx.misc.PyifxImage """ INTERNAL._type_checker(input_path, [str, None]) INTERNAL._type_checker(output_path, [str, None]) INTERNAL._type_checker(img, [np.ndarray, None]) INTERNAL._type_checker(create_image, [bool]) self.input_path = input_path if os.path.split( input_path)[0] != "" else "./" + input_path self.output_path = output_path if os.path.split( output_path)[0] != "" else "./" + output_path self.image = img if create_image: self.image = np.asarray(imageio.imread(input_path))
def volume_to_list(self, level=1): """ volume_to_list(self, level=1) The method used to create a list of PyifxImage instances based on the arguments entered in the constructor method. The volume property will be set based on the return value of this function. :type level: int :param level: The depth to which images should be imported from subdirectories. For infinite depth, set this value to 0. If nothing is entered, this value will default to 1, importing from the root directory exclusively. :return: PyifxImage list :rtype: list """ INTERNAL._type_checker(self.get_input_path(), [str]) INTERNAL._type_checker(self.get_output_path(), [str]) INTERNAL._type_checker(self.get_prefix(), [str]) return self.convert_dir_to_images(self.get_input_path(), level)
def convolute_custom(img_paths, kernel, write=True): """ convolute_custom(img_paths, kernel, write=True) Takes image(s) and creates new images that are convoluted over using a given kernel. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be convoluted over. :type kernel: numpy.ndarray, list :param kernel: The kernel to be used for convolution. This can be provided in either a 2-dimensional list or a numpy 2-dimensional array. :type write: bool :param write: Whether to write the convoluted image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(kernel, [np.ndarray, list]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) return INTERNAL._convolution_handler(img_paths, radius=None, type_kernel=None, size=None, custom=kernel, write=write)
def pixelate(img_paths, factor=4, write=True): """ pixelate(img_paths, factor=4, write=True) Takes image(s) and pixelates them based on a given factor. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be pixelated. :type factor: int :param factor: How much the image(s) should be pixelated. If nothing is entered for this parameter, it will default to 4. :type write: bool :param write: Whether to write the pixelated image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(factor, [int]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) INTERNAL._type_checker(write, [bool]) return INTERNAL._pixelate_handler(img_paths, factor, write=write)
def resize(img_paths, new_size, write=True): """ resize(img_paths, new_size, write=True) Takes image(s) and converts them to a given size. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be resized. :type new_size: str :param new_size: The new size to convert the image(s) to. It must be entered in the form "WidthxHeight". :type write: bool :param write: Whether to write the resized image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(write, [bool]) INTERNAL._type_checker(new_size, [str]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) return INTERNAL._resize_handler(img_paths, new_size, write)
def change_file_type(img_paths, new_type, write=True): """ change_file_type(img_paths, new_type, write=True) Takes image(s) and converts them to a given file type. :type img_paths: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list :param img_paths: The image(s) to be converted. :type new_type: str :param new_type: The file type that the image(s) should be converted to. Available types: PNG, JPG, JPEG. Can be entered with/without the dot. Parameter is case-insensitive. :type write: bool :param write: Whether to write the converted image(s). :return: PyifxImage instance, ImageVolume instance, or list with elements of type PyifxImage :rtype: pyifx.misc.PyifxImage, pyifx.misc.ImageVolume, list """ INTERNAL._type_checker(write, [bool]) INTERNAL._type_checker(new_type, [str]) INTERNAL._type_checker(img_paths, [misc.PyifxImage, misc.ImageVolume, list]) return INTERNAL._change_file_type_handler(img_paths, new_type, write=write)