### BindingsAndFasteners Augmentation Example Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/bindingsandfasteners.rst This example demonstrates how to initialize and use the BindingsAndFasteners augmentation with custom binder image, number of times, scales, edge, and offset. ```APIDOC ## BindingsAndFasteners Augmentation ### Description This augmentation applies binder effects to an image. It allows customization of the binder's appearance, placement, and repetition. ### Method Instantiate the `BindingsAndFasteners` class and then call the instance with an image. ### Endpoint N/A (This is a library function, not a web endpoint) ### Parameters #### Initialization Parameters - **overlay_types** (string) - Optional - Specifies the overlay type, e.g., "darken". - **foreground** (numpy.ndarray) - Optional - A custom binder image to use. - **ntimes** (tuple) - Optional - A tuple specifying the minimum and maximum number of times the binder should appear (e.g., (2, 3)). - **nscales** (tuple) - Optional - A tuple specifying the minimum and maximum scale of the binder (e.g., (1, 2)). - **edge** (string) - Optional - Specifies the edge of the image to place the binder on (e.g., "right"). - **edge_offset** (tuple) - Optional - A tuple specifying the offset range from the specified edge (e.g., (10, 20)). - **use_figshare_library** (int) - Optional - Flag to indicate usage of figshare library (typically 0 or 1). ### Request Example ```python binder_rectangle = np.full((50,20),fill_value=250,dtype="uint8") binder_rectangle[10:40,5:15] = 0 user_binder_clips = BindingsAndFasteners(overlay_types="darken", foreground=binder_rectangle, ntimes= (2, 3), nscales=(1, 2), edge="right", edge_offset=(10,20), use_figshare_library=0, ) img_user_binder = user_binder_clips(image) cv2.imshow("user binders",img_user_binder) ``` ### Response #### Success Response The function returns the augmented image with the binder effect applied. #### Response Example (An augmented image object, typically a NumPy array representing the image) ### Error Handling - Invalid parameter types will raise `TypeError`. - Issues with image processing might raise `OpenCVError` or similar exceptions. ``` -------------------------------- ### Download and Install Augraphy Environment Source: https://github.com/sparkfish/augraphy/blob/dev/examples/pytorch_integration_classification_example.ipynb Commands to download the required dataset using gdown and install the Augraphy library directly from the GitHub repository. ```bash !gdown --id 1uJPavzL7K3FFr9MEfZbdX3SNa1bGEdPu !unzip shabby_small.zip !pip install git+https://github.com/sparkfish/augraphy ``` -------------------------------- ### Gamma Augmentation Example 1 Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/gamma.rst Demonstrates how to initialize and use the Gamma augmentation with a specified gamma range. ```APIDOC ## POST /augmentations/gamma ### Description Applies Gamma correction to an image with a specified range of gamma values. ### Method POST ### Endpoint `/augmentations/gamma` ### Parameters #### Query Parameters - **gamma_range** (tuple) - Optional - A tuple of two floats representing the minimum and maximum gamma values to apply. Defaults to (0.5, 1.5). ### Request Example ```python # Assuming 'image' is a pre-loaded NumPy array representing the image # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) gamma = Gamma(gamma_range=(2.0, 3.0)) img_gamma = gamma(image) # Display the augmented image (optional) # cv2.imshow("gamma", img_gamma) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` ### Response #### Success Response (200) - **augmented_image** (numpy.ndarray) - The image after applying Gamma correction. #### Response Example (Image output would be displayed, not represented as JSON) ``` -------------------------------- ### Augraphy Documentation Template Example Source: https://github.com/sparkfish/augraphy/blob/dev/doc/contributing.md This Python code snippet demonstrates the minimal example of constructing a new augmentation within the Augraphy project, as required for documentation. ```python augmentation = MyNewAugmentation( param1=foo, param2=bar, param3=baz, p=0.5, ) ``` -------------------------------- ### Apply Severe Stains with Darken Blend - Python Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/stains.rst This example shows how to initialize the Stains augmentation with severe stain types and the darken blending method. It then applies this augmentation to a previously created image. ```python stains = Stains(stains_type="severe_stains", stains_blend_method="darken", ) img_stains = stains(image) cv2.imshow("stains", img_stains) ``` -------------------------------- ### Configure Augraphy Pipeline with Auxiliary Inputs Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/how_augraphy_works.rst This example demonstrates initializing an AugraphyPipeline with custom mask, keypoints, and bounding box data. It shows how the pipeline processes the image and returns the transformed auxiliary data alongside the augmented image. ```python from augraphy import * import cv2 import numpy as np image = cv2.imread("input.png") # create an example of mask mask = np.zeros((image.shape[0], image.shape[1]), dtype="uint8") mask[image[:,:,0]==0] = 255 # create an example of keypoints points = [] for y in range(image.shape[0]): for x in range(image.shape[1]): if np.sum(image[y,x])<5: if not y%5: if not x%5: points += [[x, y]] keypoints = {"words":points} # create an example of bounding boxes bounding_boxes = [[79, 220, 199, 256], [214, 219, 329, 264], [347, 220, 445, 255], [460, 219, 505, 255], [522, 220, 630, 260], [650, 220, 873, 256], [888, 220, 1075, 265], [1091, 218, 1150, 256]] # create augmentation pipeline ink_phase = [SectionShift()] paper_phase = [] post_phase = [Geometric(rotate_range=(-5,5)), Folding()] pipeline = AugraphyPipeline(ink_phase=ink_phase, paper_phase=paper_phase, post_phase=post_phase, mask=mask, keypoints = keypoints, bounding_boxes = bounding_boxes) augmented_image, augmented_mask, augmented_keypoints, augmented_bounding_boxes = pipeline(image) ``` -------------------------------- ### Apply BrightnessTexturize Augmentation Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/brightnesstexturize.rst This example shows how to apply the BrightnessTexturize augmentation to an image. It initializes the augmentation with a high texturize range and a specified deviation, then applies it to the input image. ```python brightness_texturize = BrightnessTexturize(texturize_range=(0.9, 0.99), deviation=0.1 ) img_brightness_texturize = brightness_texturize(image) cv2.imshow("brightness_texturize", img_brightness_texturize) ``` -------------------------------- ### Implementing AugmentationSequence in an Augraphy Pipeline Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/helper_and_utilities/augmentationsequence.rst This example demonstrates how to initialize an AugraphyPipeline using AugmentationSequence to manage ink and post-processing phases. It shows both flat and nested sequences to apply multiple augmentations sequentially to an input image. ```python from augraphy import * import cv2 import numpy as np # ink phase with single AugmentationSequence usage ink_phase = [ AugmentationSequence([ InkBleed(p=1), WaterMark(p=1) ], p=1) ] paper_phase = [] # post phase with two nested AugmentationSequence inside another AugmentationSequence post_phase = [ AugmentationSequence([ AugmentationSequence([ BleedThrough(p=1), DirtyDrum(p=1) ], p=1), AugmentationSequence([ Folding(p=1), DirtyRollers(p=1) ], p=1) ], p=1) ] # initialize pipeline pipeline = AugraphyPipeline(ink_phase, paper_phase, post_phase) # create input image image = np.full((1200, 1200, 3), 250, dtype="uint8") cv2.putText(image, "Lorem ipsum dolor sit amet", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.2, 0, 3) # augment image augmented_image = pipeline.augment(image)["output"] ``` -------------------------------- ### Example 3: Binding Clips Effect Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/bindingsandfasteners.rst Shows how to apply the 'clips' effect using BindingsAndFasteners. This example uses random width and height, specifies binding multiple times with a scale range, and applies the effect to a random edge with a small offset. ```APIDOC ## BindingsAndFasteners: Binding Clips ### Description This example initializes a BindingsAndFasteners augmentation instance to apply a synthetic binding clips effect. The width and height of the clips are set to "random". The binding clips are set to bind 2 to 3 times with a scale between 1 and 2, applied to a random edge with a random offset between 10 and 20 pixels. ### Method POST ### Endpoint `/augmentations/bindingsandfasteners/clips` ### Parameters #### Request Body - **overlay_types** (string) - Optional - Specifies the overlay type, e.g., "darken". - **foreground** (None) - Optional - Placeholder for custom foreground image. - **effect_type** (string) - Required - Set to "clips" for this effect. - **width_range** (string) - Optional - Set to "random" for random width. - **height_range** (string) - Optional - Set to "random" for random height. - **ntimes** (tuple) - Optional - Range for the number of times the effect is applied, e.g., (2, 3). - **nscales** (tuple) - Optional - Range for the scale factor, e.g., (1, 2). - **edge** (string) - Optional - The edge to apply the effect to, e.g., "random". - **edge_offset** (tuple) - Optional - Random offset range from the chosen edge, e.g., (10, 20). - **use_figshare_library** (integer) - Optional - Flag to use figshare library (0 or 1). ### Request Example ```python # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) binder_binding_clips = BindingsAndFasteners(overlay_types="darken", foreground=None, effect_type="clips", width_range = "random", height_range = "random", ntimes= (2, 3), nscales=(1, 2), edge="random", edge_offset=(10,20), use_figshare_library=0, ) img_binding_clips = binder_binding_clips(image) ``` ### Response #### Success Response (200) - **image** (numpy.ndarray) - The augmented image with binding clip effects. ### Response Example ```json { "image": "augmented_image_data" } ``` ``` -------------------------------- ### Setup ResNet Transfer Learning Model Source: https://github.com/sparkfish/augraphy/blob/dev/examples/pytorch_integration_classification_example.ipynb Initializes a pre-trained ResNet50 model, freezes existing parameters, and replaces the final fully connected layer for binary classification tasks using BCEWithLogitsLoss. ```python device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model = models.resnet50(pretrained=True) for params in model.parameters(): params.requires_grad_ = False model.fc = nn.Linear(model.fc.in_features, 1) model = model.to(device) criterion = BCEWithLogitsLoss() optimizer = torch.optim.Adam(model.fc.parameters(), lr=1e-3) ``` -------------------------------- ### Apply Faxify Augmentation - Python Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/faxify.rst Demonstrates the application of the Faxify augmentation to an image. This example configures monochrome, halftone, and blur effects to simulate fax output. ```Python faxify = Faxify(scale_range = (1,2), monochrome = 1, monochrome_method = "cv2.threshold", monochrome_arguments = {"thresh":128, "maxval":128, "type":cv2.THRESH_BINARY}, halftone = 1, invert = 1, half_kernel_size = (2,2), angle = (0, 360), sigma = (1,3)) img_faxify = faxify(image) cv2.imshow("faxify", img_faxify) ``` -------------------------------- ### PaperFactory Augmentation Example Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/helper_and_utilities/paperfactory.rst This example demonstrates how to use the PaperFactory to apply a paper texture to an input image. It involves creating a directory for texture images, generating a sample texture, saving it, and then configuring and running the AugraphyPipeline with PaperFactory. The factory uses the provided texture directory to extract textures. ```python # import libraries from augraphy import * import cv2 import numpy as np import os # create directory for paper texture paper_texture_dir = os.path.join(os.getcwd(), "paper_textures/") os.makedirs(paper_texture_dir, exist_ok = True) # create an empty image image_texture = np.full((1000,1000), fill_value=255, dtype="uint8") # create texture for i in range(5): i += 8 image_texture[::i,::i] = 0 # save texture image in the paper texture directory cv2.imwrite(paper_texture_dir+"texture.png", image_texture) ink_phase = [] paper_phase = [PaperFactory(texture_path=paper_texture_dir, p=1)] post_phase = [] pipeline = AugraphyPipeline(ink_phase, paper_phase, post_phase) image = np.full((1200, 1200,3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.2, 0, 3, ) augmented_image = pipeline.augment(image)["output"] ``` -------------------------------- ### Apply NoiseTexturize Augmentation - Python Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/noisetexturize.rst This example shows how to initialize and apply the NoiseTexturize augmentation. It allows customization of noise fluctuations (sigma), turbulence, and texture dimensions. The augmentation is applied to a pre-existing image. ```Python noise_texturize = NoiseTexturize(sigma_range=(2, 3), turbulence_range=(2, 5), texture_width_range=(50, 500), texture_height_range=(50, 500), ) img_noise_texturize = noise_texturize(image) cv2.imshow("noise_texturize", img_noise_texturize ``` -------------------------------- ### Apply DotMatrix Augmentation - Python Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/dotmatrix.rst This example initializes the DotMatrix augmentation with specific parameters to create a dot matrix effect. It configures dot shape, size, contour constraints, median kernel, Gaussian blur, and rotation. ```python dotmatrix = DotMatrix(dot_matrix_shape="circle", dot_matrix_dot_width_range=(5, 5), dot_matrix_dot_height_range=(5, 5), dot_matrix_min_width_range=(1, 1), dot_matrix_max_width_range=(50, 50), dot_matrix_min_height_range=(1, 1), dot_matrix_max_height_range=(50, 50), dot_matrix_min_area_range=(10, 10), dot_matrix_max_area_range=(800, 800), dot_matrix_median_kernel_value_range = (29,29), dot_matrix_gaussian_kernel_value_range=(1, 1), dot_matrix_rotate_value_range=(0, 0) ) img_dotmatrix = dotmatrix(image) cv2.imshow("dotmatrix", img_dotmatrix) ``` -------------------------------- ### Create and Display Base Image with OpenCV Source: https://github.com/sparkfish/augraphy/blob/dev/examples/Augraphy_usage_examples.ipynb Initializes a blank white image using NumPy and adds text using OpenCV. This serves as the base image for subsequent augmentation examples. ```python import numpy as np import cv2 from google.colab.patches import cv2_imshow image = np.full((2000, 2000, 3), 255, dtype="uint8") for i in range(20): font_size = 1 thickness=2 cv2.putText(image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, i*100), cv2.FONT_HERSHEY_SIMPLEX, font_size, 0, thickness) cv2_imshow(image) ``` -------------------------------- ### Initialize and Apply NoisyLines Augmentation - Python Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/noisylines.rst This example shows how to initialize the NoisyLines augmentation with specific parameters for line direction, location, number, color, thickness, noise intensity, interval, kernel value, and overlay method. It then applies the augmentation to an image. ```python noisylines = NoisyLines(noisy_lines_direction = 0, noisy_lines_location = "random", noisy_lines_number_range = (3,5), noisy_lines_color = (0,0,0), noisy_lines_thickness_range = (2,2), noisy_lines_random_noise_intensity_range = (0.01, 0.1), noisy_lines_length_interval_range = (0,100), noisy_lines_gaussian_kernel_value_range = (3,3), noisy_lines_overlay_method = "ink_to_paper", ) img_noisylines = noisylines(image) cv2.imshow("noisylines", img_noisylines) ``` -------------------------------- ### Apply Rescale Augmentation with and without Fixed DPI Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/rescale.rst This example shows how to initialize the Rescale augmentation with a target DPI and apply it within an AugraphyPipeline. It contrasts the behavior when 'fixed_dpi' is enabled versus disabled, demonstrating how the image is scaled differently for augmentation purposes. ```python rescale = Rescale(target_dpi=300) pipeline1 = AugraphyPipeline(pre_phase=[rescale], ink_phase=[InkBleed()], paper_phase=[ColorPaper()], post_phase=[BleedThrough()], fixed_dpi=1) pipeline2 = AugraphyPipeline(pre_phase=[rescale], ink_phase=[InkBleed()], paper_phase=[ColorPaper()], post_phase=[BleedThrough()], fixed_dpi=0) img_rescale1 = pipeline1(image) img_rescale2 = pipeline2(image) cv2.imshow("rescale - fixed dpi", img_rescale1) cv2.imshow("rescale - non fixed dpi", img_rescale2) ``` -------------------------------- ### Apply Watermark Augmentation - Python Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/watermark.rst This example shows how to initialize and apply the WaterMark augmentation. It configures various parameters such as watermark word, font size, thickness, rotation, location, and color to create a customized watermark effect on an image. ```python watermark= WaterMark(watermark_word = "random", watermark_font_size = (10,15), watermark_font_thickness = (20,25), watermark_font_type = cv2.FONT_HERSHEY_SIMPLEX, watermark_rotation = (0,360) , watermark_location = "center", watermark_color = (0,0,255), watermark_method = "darken") img_watermark = watermark(image) cv2.imshow("watermark", img_watermark) ``` -------------------------------- ### Initialize and Apply Brightness Augmentation Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/brightness.rst Demonstrates how to import necessary libraries, create a sample input image, and apply the Brightness augmentation with different configurations for brightening and dimming. ```python import cv2 import numpy as np from augraphy import * # Create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText(image, "Lorem ipsum dolor sit amet", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3) # Example 1: Brighten image (1.5x to 2x) brightness_brighten = Brightness(brightness_range=(1.5, 2), min_brightness=0) img_brightened = brightness_brighten(image) # Example 2: Dim image (0.2x to 0.8x) with min brightness constraints brightness_dimmer = Brightness(brightness_range=(0.2, 0.8), min_brightness=1, min_brightness_value=(120, 150)) img_dimmed = brightness_dimmer(image) ``` -------------------------------- ### Install Augraphy via pip Source: https://github.com/sparkfish/augraphy/blob/dev/examples/Augraphy_usage_examples.ipynb Uses pip to clone and install the latest version of the Augraphy library directly from the official GitHub repository. ```bash pip install git+https://github.com/sparkfish/augraphy ``` -------------------------------- ### Create and Use AugraphyPipeline Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/helper_and_utilities/augmentationpipeline.rst Demonstrates how to initialize an AugraphyPipeline with ink, paper, and post-phase augmentations. It also shows how to apply the pipeline to an image and save logs and outputs. ```python from augraphy import * import cv2 import numpy as np ink_phase = [InkBleed(p=0.7), BleedThrough(p=0.7)] paper_phase = [WaterMark(p=0.7), DirtyDrum(p=0.7)] post_phase = [DirtyRollers(p=0.7), PencilScribbles(p=0.7)] pipeline = AugraphyPipeline(ink_phase, paper_phase, post_phase, log=True, save_outputs=True) image = np.full((1200, 1200,3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.2, 0, 3, ) augmented_image = pipeline.augment(image)["output"] ``` -------------------------------- ### InkBleed Augmentation Example 1 Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/inkbleed.rst This example demonstrates how to initialize and use the InkBleed augmentation with specific intensity range, kernel size, and severity. ```APIDOC ## InkBleed Augmentation - Example 1 ### Description In this example, a InkBleed augmentation instance is initialized and the range of intensity is set to a range of moderate value (0.4, 0.7). The kernel size is set to 5x5 (5,5) to get a moderate spreadness of the effect. The severity of the ink bleed effect is set to a random low value in between 0.2 and 0.4 (0.2, 0.4). ### Method N/A (This describes the augmentation class usage) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500,3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) # Initialize InkBleed augmentation inkbleed = InkBleed(intensity_range=(0.4, 0.7), kernel_size=(5, 5), severity=(0.2, 0.4) ) # Apply augmentation img_inkbleed = inkbleed(image) cv2.imshow("inkbleed", img_inkbleed) ``` ### Response #### Success Response (200) N/A (This is a code example for image augmentation) #### Response Example N/A ``` -------------------------------- ### Initialize and Apply LightingGradient with Gaussian Mode Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/lightinggradient.rst This snippet demonstrates how to initialize the LightingGradient class with Gaussian mode, random positioning, and 50% transparency. It then applies the augmentation to a provided image. ```python lighting_gradient_gaussian = LightingGradient(light_position=None, direction=90, max_brightness=255, min_brightness=0, mode="gaussian", transparency=0.5 ) img_lighting_gradient_gaussian = lighting_gradient_gaussian(image) cv2.imshow("lighting_gradient_gaussian", img_lighting_gradient_gaussian) ``` -------------------------------- ### Initialize and Apply LCDScreenPattern Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/lcdscreenpattern.rst This snippet demonstrates how to import necessary libraries, create a base image, and apply the LCDScreenPattern augmentation with specific parameters like horizontal lines and darken overlay. ```python import cv2 import numpy as np from augraphy import * # Create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText(image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3) # Initialize LCDScreenPattern lcdscreenpattern = LCDScreenPattern( pattern_type="Horizontal", pattern_value_range=(0, 16), pattern_skip_distance_range=(3, 5), pattern_overlay_method="darken" ) # Apply augmentation img_lcdscreenpattern = lcdscreenpattern(image) cv2.imshow("lcdscreenpattern", img_lcdscreenpattern) ``` -------------------------------- ### Example 2: Binding Holes Effect Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/bindingsandfasteners.rst Illustrates the BindingsAndFasteners augmentation using the 'binding_holes' effect. This example sets random width and height, binds multiple times with a scale range, and applies the effect to the top edge with a specified offset. ```APIDOC ## BindingsAndFasteners: Binding Holes ### Description This example initializes a BindingsAndFasteners augmentation instance to apply a synthetic binding hole effect. The width and height of the holes are set to "random". The binding holes are set to bind 9 to 10 times with a scale between 1 and 2, applied to the top edge with a random offset between 40 and 50 pixels. ### Method POST ### Endpoint `/augmentations/bindingsandfasteners/binding_holes` ### Parameters #### Request Body - **overlay_types** (string) - Optional - Specifies the overlay type, e.g., "darken". - **foreground** (None) - Optional - Placeholder for custom foreground image. - **effect_type** (string) - Required - Set to "binding_holes" for this effect. - **width_range** (string) - Optional - Set to "random" for random width. - **height_range** (string) - Optional - Set to "random" for random height. - **ntimes** (tuple) - Optional - Range for the number of times the effect is applied, e.g., (9, 10). - **nscales** (tuple) - Optional - Range for the scale factor, e.g., (1, 2). - **edge** (string) - Optional - The edge to apply the effect to, e.g., "top". - **edge_offset** (tuple) - Optional - Random offset range from the chosen edge, e.g., (40, 50). - **use_figshare_library** (integer) - Optional - Flag to use figshare library (0 or 1). ### Request Example ```python # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) binder_binding_holes = BindingsAndFasteners(overlay_types="darken", foreground=None, effect_type="binding_holes", width_range = "random", height_range = "random", ntimes=(9, 10), nscales=(1, 2), edge="top", edge_offset=(40,50), use_figshare_library=0, ) img_binding_holes = binder_binding_holes(image) cv2.imshow("binding_holes", img_binding_holes) ``` ### Response #### Success Response (200) - **image** (numpy.ndarray) - The augmented image with binding hole effects. ### Response Example ```json { "image": "augmented_image_data" } ``` ### Augmented Image ![Binding holes effect](augmentations/bindingsandfasteners/binding_holes.png) ``` -------------------------------- ### Initialize and Apply LowInkRandomLines Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/lowinkrandomlines.rst Demonstrates how to create a base image and apply the LowInkRandomLines augmentation with specific parameters for line count, consistency, and noise probability. ```python import cv2 import numpy as np from augraphy import * # Create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText(image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3) # Example 1: Consistent lines low_ink_random_line_consistent = LowInkRandomLines(count_range=(30, 50), use_consistent_lines=True, noise_probability=0.1) img_consistent = low_ink_random_line_consistent(image) # Example 2: Non-consistent lines low_ink_random_line_non_consistent = LowInkRandomLines(count_range=(30, 50), use_consistent_lines=False, noise_probability=0.1) img_non_consistent = low_ink_random_line_non_consistent(image) ``` -------------------------------- ### Example 1: Punch Holes Effect Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/bindingsandfasteners.rst Demonstrates how to use the BindingsAndFasteners augmentation with the 'punch_holes' effect type. This example configures random width and height for the holes, specifies binding multiple times, sets a scale, and applies the effect to the left edge with an offset. ```APIDOC ## BindingsAndFasteners: Punch Holes ### Description This example initializes a BindingsAndFasteners augmentation instance to apply a synthetic punch hole effect. The width and height of the punch holes are randomized between 70 and 80 pixels. The holes are set to bind 3 times with a scale of 1.5, applied to the left edge with a random offset between 30 and 50 pixels. ### Method POST ### Endpoint `/augmentations/bindingsandfasteners/punch_holes` ### Parameters #### Request Body - **overlay_types** (string) - Optional - Specifies the overlay type, e.g., "darken". - **foreground** (None) - Optional - Placeholder for custom foreground image. - **effect_type** (string) - Required - Set to "punch_holes" for this effect. - **width_range** (tuple) - Optional - Range for random width of holes, e.g., (70, 80). - **height_range** (tuple) - Optional - Range for random height of holes, e.g., (70, 80). - **ntimes** (tuple) - Optional - Number of times the effect is applied, e.g., (3, 3). - **nscales** (tuple) - Optional - Scale factor for the effect, e.g., (1.5, 1.5). - **edge** (string) - Optional - The edge to apply the effect to, e.g., "left". - **edge_offset** (tuple) - Optional - Random offset range from the chosen edge, e.g., (30, 50). - **use_figshare_library** (integer) - Optional - Flag to use figshare library (0 or 1). ### Request Example ```python # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) binder_punch_holes = BindingsAndFasteners(overlay_types="darken", foreground=None, effect_type="punch_holes", width_range = (70,80), height_range = (70,80), ntimes=(3, 3), nscales=(1.5, 1.5), edge="left", edge_offset=(30,50), use_figshare_library=0, ) img_punch_holes = binder_punch_holes(image) cv2.imshow("punch_holes", img_punch_holes) ``` ### Response #### Success Response (200) - **image** (numpy.ndarray) - The augmented image with punch hole effects. ### Response Example ```json { "image": "augmented_image_data" } ``` ### Augmented Image ![Punch holes effect](augmentations/bindingsandfasteners/punch_holes.png) ``` -------------------------------- ### Initialize and Apply Jpeg Augmentation Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/jpeg.rst Demonstrates how to import necessary libraries, create a base image, and apply the Jpeg augmentation with specific quality ranges. The quality_range parameter controls the intensity of the compression artifacts. ```python import cv2 import numpy as np from augraphy import * # Create a clean image with text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText(image, "Lorem ipsum dolor sit amet", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3) # Apply Jpeg augmentation with low quality (5-10%) jpeg_5 = Jpeg(quality_range=(5, 10)) img_jpeg_5 = jpeg_5(image) # Apply Jpeg augmentation with medium quality (50-55%) jpeg_50 = Jpeg(quality_range=(50, 55)) img_jpeg_50 = jpeg_50(image) ``` -------------------------------- ### ReflectedLight Augmentation Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/reflectedlight.rst This section details the ReflectedLight augmentation, explaining its purpose and providing a code example of its implementation. ```APIDOC ## ReflectedLight Augmentation ### Description The ReflectedLight augmentation creates a reflected light effect by drawing ellipses of different brightness onto an image. This can simulate various lighting conditions or add stylistic elements. ### Method This is a conceptual representation of an augmentation process, not a direct API endpoint. The augmentation is applied using a Python class instance. ### Endpoint N/A (This is a library augmentation, not a web API endpoint) ### Parameters #### Augmentation Parameters - **reflected_light_smoothness** (float) - Optional - Controls the smoothness of the reflected light effect. Defaults to 0.8. - **reflected_light_internal_radius_range** (tuple) - Optional - A tuple representing the range (min, max) for the internal radius of the ellipse, as a percentage of the image's minimum dimension. Defaults to (0.0, 0.2). - **reflected_light_external_radius_range** (tuple) - Optional - A tuple representing the range (min, max) for the external radius of the ellipse, as a percentage of the image's minimum dimension. Defaults to (0.1, 0.8). - **reflected_light_minor_major_ratio_range** (tuple) - Optional - A tuple representing the range (min, max) for the ratio of the minor to major axes of the ellipse. Defaults to (0.1, 0.8). - **reflected_light_color** (tuple) - Optional - The color of the reflected light, specified as an RGB tuple. Defaults to white (255, 255, 255). - **reflected_light_internal_max_brightness_range** (tuple) - Optional - A tuple representing the range (min, max) for the maximum brightness of the internal ellipse, as a percentage (0.0 to 1.0). Defaults to (0.9, 1.0). - **reflected_light_external_max_brightness_range** (tuple) - Optional - A tuple representing the range (min, max) for the maximum brightness of the external ellipse, as a percentage (0.0 to 1.0). Defaults to (0.9, 0.9). - **reflected_light_location** (str or tuple) - Optional - Specifies the location of the reflected light. Can be 'random' or a tuple (x, y) for a fixed position. Defaults to 'random'. - **reflected_light_ellipse_angle_range** (tuple) - Optional - A tuple representing the range (min, max) for the angle of the ellipse in degrees. Defaults to (0, 360). - **reflected_light_gaussian_kernel_size_range** (tuple) - Optional - A tuple representing the range (min, max) for the Gaussian kernel size used in blurring the effect. Defaults to (5, 310). ### Request Example ```python # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) # Initialize ReflectedLight augmentation reflected_light = ReflectedLight( reflected_light_smoothness = 0.8, reflected_light_internal_radius_range=(0.0, 0.2), reflected_light_external_radius_range=(0.1, 0.8), reflected_light_minor_major_ratio_range = (0.1, 0.8), reflected_light_color = (255,255,255), reflected_light_internal_max_brightness_range=(0.9,1.0), reflected_light_external_max_brightness_range=(0.9,0.9), reflected_light_location = "random", reflected_light_ellipse_angle_range = (0, 360), reflected_light_gaussian_kernel_size_range = (5,310), ) # Apply augmentation img_reflected_light = reflected_light(image) # Display the augmented image (optional) # cv2.imshow("reflected_light", img_reflected_light) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` ### Response #### Success Response The augmentation returns a modified image with the reflected light effect applied. #### Response Example (Image data representing the augmented image) ``` -------------------------------- ### Integrating External Augmenters with Interop Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/helper_and_utilities/interop.rst This example demonstrates how to use the Interop class to incorporate an imgaug Rain augmenter in the ink phase and an Albumentations ElasticTransform in the post phase of an Augraphy pipeline. It shows the initialization of the pipeline, the creation of a sample image, and the execution of the augmentation process. ```python from augraphy import * import cv2 import numpy as np from augraphy.utilities.interop import Interop import imgaug.augmenters as iaa from albumentations.augmentations.geometric.transforms import ElasticTransform # Initialize phases and pipeline ink_phase = [Interop(augmentation=iaa.Rain(drop_size=(0.10, 0.20)), p=1)] paper_phase = [ColorPaper(hue_range=(0, 10), saturation_range=(128, 255), p=1)] post_phase = [Interop(augmentation=ElasticTransform(alpha_affine=100, p=1), p=1)] # Initialize pipeline pipeline = AugraphyPipeline(ink_phase, paper_phase, post_phase) # Create input image image = np.full((1200, 1200, 3), 128, dtype="uint8") cv2.putText(image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.2, 0, 3) # Augment image augmented_image = pipeline.augment(image)["output"] ``` -------------------------------- ### NoisyLines Augmentation Source: https://github.com/sparkfish/augraphy/blob/dev/doc/source/augmentations/noisylines.rst This section details the NoisyLines augmentation, explaining its purpose and providing a code example of its usage. ```APIDOC ## NoisyLines Augmentation ### Description The NoisyLines augmentation creates noisy lines by drawing horizontal or vertical lines at fixed intervals on an image. It's useful for simulating various types of image degradation or artistic effects. ### Method This documentation describes the usage of the `NoisyLines` class from the `augraphy` library. It is not a direct API endpoint but a class used within image processing workflows. ### Parameters #### Class Initialization Parameters for `NoisyLines`: - **noisy_lines_direction** (int) - Optional - Specifies the direction of the lines. `0` for horizontal, `1` for vertical. - **noisy_lines_location** (str) - Optional - Determines the location of the lines. Can be "random" or a specific coordinate. - **noisy_lines_number_range** (tuple) - Optional - A tuple `(min, max)` specifying the range for the number of lines to draw. - **noisy_lines_color** (tuple) - Optional - An RGB tuple `(R, G, B)` defining the color of the lines. - **noisy_lines_thickness_range** (tuple) - Optional - A tuple `(min, max)` for the thickness of the lines. - **noisy_lines_random_noise_intensity_range** (tuple) - Optional - A tuple `(min, max)` for the intensity of random noise applied to the lines, as a percentage (e.g., 0.01 for 1%). - **noisy_lines_length_interval_range** (tuple) - Optional - A tuple `(min, max)` for the space interval between lines. - **noisy_lines_gaussian_kernel_value_range** (tuple) - Optional - A tuple `(min, max)` for the Gaussian kernel value used for blurring the lines. - **noisy_lines_overlay_method** (str) - Optional - The method used to overlay the lines onto the image. Defaults to "ink_to_paper". ### Request Example ```python # import libraries import cv2 import numpy as np from augraphy import * # create a clean image with single line of text image = np.full((500, 1500, 3), 250, dtype="uint8") cv2.putText( image, "Lorem ipsum dolor sit amet, consectetur adipiscing elit", (80, 250), cv2.FONT_HERSHEY_SIMPLEX, 1.5, 0, 3, ) # Initialize NoisyLines augmentation noisylines = NoisyLines( noisy_lines_direction=0, # Horizontal lines noisy_lines_location="random", noisy_lines_number_range=(3, 5), noisy_lines_color=(0, 0, 0), # Black color noisy_lines_thickness_range=(2, 2), noisy_lines_random_noise_intensity_range=(0.01, 0.1), noisy_lines_length_interval_range=(0, 100), noisy_lines_gaussian_kernel_value_range=(3, 3), noisy_lines_overlay_method="ink_to_paper", ) # Apply the augmentation img_noisylines = noisylines(image) # Display the augmented image (optional) # cv2.imshow("Input image", image) # cv2.imshow("NoisyLines Augmented Image", img_noisylines) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` ### Response #### Success Response The `noisylines` object, when called with an image, returns the augmented image with noisy lines applied according to the specified parameters. #### Response Example (The output is an image object, typically displayed or saved. The exact pixel values depend on the input image and random parameters.) ```