Skip to content

Commit

Permalink
Merge pull request #425 from kwcckw/rel
Browse files Browse the repository at this point in the history
Updated version to 8.2.6.
  • Loading branch information
kwcckw authored Dec 31, 2023
2 parents 1d38764 + 6dfce58 commit 09282c5
Show file tree
Hide file tree
Showing 31 changed files with 1,805 additions and 12 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ The benchmark results are computed with Augraphy 8.2 and Tobacco3482 dataset (re
|ColorPaper | 4.83| 105.66| 4.99| 105.66| 4.96| 105.66| 4.96| 105.66|
|ColorShift | 0.79| 126.94| 0.82| 126.94| 0.77| 126.94| 0.76| 126.94|
|DelaunayTessellation| 0.11| 60.41| 0.12| 60.29| 0.11| 60.36| 0.10| 60.37|
|DepthSimulatedBlur | 0.01| 76.08| 0.01| 76.08| 0.01| 76.08| 0.01| 76.08|
|DirtyDrum | 0.83| 482.51| 0.94| 481.56| 0.90| 481.68| 0.92| 481.52|
|DirtyRollers | 1.47| 249.55| 1.77| 249.43| 1.80| 249.43| 1.78| 249.43|
|DirtyScreen | 0.78| 435.36| 0.78| 435.36| 0.77| 435.36| 0.77| 435.36|
|Dithering | 3.39| 126.82| 3.66| 126.80| 3.66| 126.81| 3.79| 126.80|
|DotMatrix | 0.53| 80.75| 0.57| 80.52| 0.57| 80.52| 0.57| 80.52|
|DoubleExposure | 1.64| 63.40| 1.67| 63.40| 1.62| 63.40| 1.65| 63.40|
|Faxify | 1.37| 138.34| 1.43| 141.28| 1.41| 136.95| 1.27| 149.24|
|Folding | 3.18| 57.50| 1.24| 60.40| 3.44| 57.60| 3.55| 57.20|
|Gamma | 29.26| 25.36| 26.90| 25.36| 28.23| 25.36| 32.03| 25.36|
Expand All @@ -144,14 +147,17 @@ The benchmark results are computed with Augraphy 8.2 and Tobacco3482 dataset (re
|InkColorSwap | 3.47| 51.99| 3.58| 51.99| 3.51| 51.99| 3.61| 51.99|
|InkMottling | 5.41| 55.99| 5.47| 55.99| 5.49| 55.99| 5.39| 55.99|
|InkShifter | 0.17| 426.86| 0.15| 426.43| 0.17| 426.78| 0.17| 426.58|
|LCDScreenPattern | 2.14| 494.09| 2.12| 493.62| 2.14| 494.74| 2.13| 496.46|
|Jpeg | 5.55| 25.87| 5.60| 25.86| 5.52| 25.87| 5.66| 25.87|
|LensFlare | 0.02| 405.97| 0.01| 405.82| 0.01| 405.82| 0.01| 405.82|
|Letterpress | 0.35| 135.71| 0.33| 140.72| 0.34| 137.25| 0.34| 136.31|
|LightingGradient | 0.37| 638.31| 0.38| 638.30| 0.39| 638.30| 0.40| 638.30|
|LinesDegradation | 1.28| 174.76| 1.27| 174.93| 1.28| 174.92| 1.31| 174.59|
|LowInkPeriodicLines | 5.17| 12.75| 5.26| 12.75| 5.56| 12.75| 5.10| 12.75|
|LowInkRandomLines | 91.52| 12.75| 86.12| 12.75| 87.58| 12.75| 98.28| 12.75|
|LowLightNoise | 0.27| 481.95| 0.28| 481.95| 0.27| 481.95| 0.27| 481.95|
|Markup | 2.33| 161.88| 2.41| 158.13| 2.58| 146.27| 2.60| 147.53|
|Moire | 0.97| 575.74| 1.03| 575.57| 1.05| 575.57| 1.05| 575.57|
|NoiseTexturize | 0.83| 249.36| 0.85| 249.36| 0.80| 249.36| 0.82| 249.36|
|NoisyLines | 0.89| 446.65| 0.83| 448.43| 0.86| 447.88| 0.85| 448.52|
|PageBorder | 0.49| 193.95| 0.49| 188.46| 0.48| 188.30| 0.49| 192.04|
Expand All @@ -161,6 +167,7 @@ The benchmark results are computed with Augraphy 8.2 and Tobacco3482 dataset (re
|SectionShift | 117.15| 12.96| 101.71| 13.02| 107.88| 12.95| 115.22| 12.96|
|ShadowCast | 0.75| 50.79| 0.68| 50.80| 0.68| 50.80| 0.74| 50.80|
|Squish | 0.72| 450.44| 0.72| 450.79| 0.73| 450.83| 0.76| 451.00|
|Stains | 1.11| 469.14| 1.14| 469.14| 1.16| 469.14| 1.11| 469.14|
|SubtleNoise | 1.44| 215.55| 1.47| 215.55| 1.47| 215.55| 1.48| 215.55|
|VoronoiTessellation | 0.07| 58.07| 0.07| 57.74| 0.07| 57.89| 0.07| 58.13|
|WaterMark | 2.09| 363.62| 1.86| 404.62| 1.78| 409.50| 2.02| 380.21|
Expand Down Expand Up @@ -188,7 +195,7 @@ BibTeX:
author = {The Augraphy Project},
title = {Augraphy: an augmentation pipeline for rendering synthetic paper printing, faxing, scanning and copy machine processes},
url = {https://github.com/sparkfish/augraphy},
version = {8.2.5}
version = {8.2.6}
}
```

Expand Down
2 changes: 1 addition & 1 deletion augraphy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from augraphy.default import *
from augraphy.utilities import *

__version__ = "8.2.5"
__version__ = "8.2.6"
14 changes: 14 additions & 0 deletions augraphy/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from augraphy.augmentations.colorpaper import ColorPaper
from augraphy.augmentations.colorshift import ColorShift
from augraphy.augmentations.delaunay import DelaunayTessellation
from augraphy.augmentations.depthsimulatedblur import DepthSimulatedBlur
from augraphy.augmentations.dirtydrum import DirtyDrum
from augraphy.augmentations.dirtyrollers import DirtyRollers
from augraphy.augmentations.dirtyscreen import DirtyScreen
from augraphy.augmentations.dithering import Dithering
from augraphy.augmentations.dotmatrix import DotMatrix
from augraphy.augmentations.doubleexposure import DoubleExposure
from augraphy.augmentations.faxify import Faxify
from augraphy.augmentations.folding import Folding
from augraphy.augmentations.gamma import Gamma
Expand All @@ -22,13 +25,16 @@
from augraphy.augmentations.inkmottling import InkMottling
from augraphy.augmentations.inkshifter import InkShifter
from augraphy.augmentations.jpeg import Jpeg
from augraphy.augmentations.lcdscreenpattern import LCDScreenPattern
from augraphy.augmentations.lensflare import LensFlare
from augraphy.augmentations.letterpress import Letterpress
from augraphy.augmentations.lightinggradient import LightingGradient
from augraphy.augmentations.linesdegradation import LinesDegradation
from augraphy.augmentations.lowinkperiodiclines import LowInkPeriodicLines
from augraphy.augmentations.lowinkrandomlines import LowInkRandomLines
from augraphy.augmentations.lowlightnoise import LowLightNoise
from augraphy.augmentations.markup import Markup
from augraphy.augmentations.moire import Moire
from augraphy.augmentations.noisetexturize import NoiseTexturize
from augraphy.augmentations.noisylines import NoisyLines
from augraphy.augmentations.pageborder import PageBorder
Expand All @@ -39,6 +45,7 @@
from augraphy.augmentations.sectionshift import SectionShift
from augraphy.augmentations.shadowcast import ShadowCast
from augraphy.augmentations.squish import Squish
from augraphy.augmentations.stains import Stains
from augraphy.augmentations.subtlenoise import SubtleNoise
from augraphy.augmentations.voronoi import VoronoiTessellation
from augraphy.augmentations.watermark import WaterMark
Expand All @@ -53,10 +60,13 @@
"ColorPaper",
"ColorShift",
"DelaunayTessellation",
"DepthSimulatedBlur",
"DirtyDrum",
"DirtyRollers",
"DirtyScreen",
"Dithering",
"DotMatrix",
"DoubleExposure",
"Faxify",
"Folding",
"Gamma",
Expand All @@ -67,14 +77,17 @@
"InkColorSwap",
"InkMottling",
"InkShifter",
"LCDScreenPattern",
"Jpeg",
"LensFlare",
"Letterpress",
"LightingGradient",
"LinesDegradation",
"LowInkPeriodicLines",
"LowInkRandomLines",
"LowLightNoise",
"Markup",
"Moire",
"NoiseTexturize",
"NoisyLines",
"PageBorder",
Expand All @@ -85,6 +98,7 @@
"SectionShift",
"ShadowCast",
"Squish",
"Stains",
"SubtleNoise",
"VoronoiTessellation",
"WaterMark",
Expand Down
4 changes: 2 additions & 2 deletions augraphy/augmentations/colorpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def add_color(self, image):
# convert to hsv colorspace
image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# assign hue and saturation
image_h = np.random.randint(self.hue_range[0], self.hue_range[1], size=(ysize, xsize))
image_s = np.random.randint(self.saturation_range[0], self.saturation_range[1], size=(ysize, xsize))
image_h = np.random.randint(self.hue_range[0], self.hue_range[1] + 1, size=(ysize, xsize))
image_s = np.random.randint(self.saturation_range[0], self.saturation_range[1] + 1, size=(ysize, xsize))

# assign hue and saturation channel back to hsv image
image_hsv[:, :, 0] = image_h
Expand Down
145 changes: 145 additions & 0 deletions augraphy/augmentations/depthsimulatedblur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import random

import cv2
import numpy as np

from augraphy.base.augmentation import Augmentation


class DepthSimulatedBlur(Augmentation):
"""Creates a depth-simulated blur effect from a camera by blurring a small elliptical region of image.
:param blur_centerr: Center (x,y) of blur effect. Use "random" for random location.
:type blur_center: tuple or string, optional
:param blur_major_axes_length_range: Pair of ints determining the value of major axis in the blurring ellipse.
:type blur_major_axes_length_range: tuple, optional
:param blur_minor_axes_length_range: Pair of ints determining the value of minor axis in the blurring ellipse.
:type blur_minor_axes_length_range: tuple, optional
:param blur_iteration_range: Pair of ints determining the value of number of blurring iterations.
The higher the iteration number, the smoother the transition of blurring area to non blurring area.
However, it runs slower with higher iterations number.
:type blur_iteration_range: tuple, optional
:param p: The probability this Augmentation will be applied.
:type p: float, optional
"""

def __init__(
self,
blur_center="random",
blur_major_axes_length_range=(120, 200),
blur_minor_axes_length_range=(120, 200),
blur_iteration_range=(8, 10),
p=1,
):
super().__init__(p=p)
self.blur_center = blur_center
self.blur_major_axes_length_range = blur_major_axes_length_range
self.blur_minor_axes_length_range = blur_minor_axes_length_range
self.blur_iteration_range = blur_iteration_range

# Constructs a string representation of this Augmentation.
def __repr__(self):
return f"DepthSimulatedBlur(blur_center={self.blur_center}, blur_major_axes_length_range={self.blur_major_axes_length_range}, blur_minor_axes_length_range={self.blur_minor_axes_length_range}, blur_iteration_range={self.blur_iteration_range}, p={self.p})"

# Applies the Augmentation to input data.
def __call__(self, image, layer=None, mask=None, keypoints=None, bounding_boxes=None, force=False):
if force or self.should_run():
image = image.copy()

# check and convert image into BGR format
has_alpha = 0
if len(image.shape) > 2:
is_gray = 0
if image.shape[2] == 4:
has_alpha = 1
image, image_alpha = image[:, :, :3], image[:, :, 3]
else:
is_gray = 1
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)

ysize, xsize = image.shape[:2]

axes_major = random.randint(self.blur_major_axes_length_range[0], self.blur_major_axes_length_range[1])
axes_minor = random.randint(self.blur_minor_axes_length_range[0], self.blur_minor_axes_length_range[1])

min_x = int(xsize / 5)
min_y = int(ysize / 5)
max_x = xsize - min_x
max_y = ysize - min_y

if self.blur_center == "random":
center_x = random.randint(min_x, max_x)
center_y = random.randint(min_y, max_y)
else:
center_x = self.blur_center[0]
center_y = self.blur_center[0]

step = random.randint(self.blur_iteration_range[0], self.blur_iteration_range[1])

# decremental value per step
decremental_value = int(max(1, np.ceil(min(axes_major, axes_minor) / step)))

# gaussian kernel incremental value per step
gaussian_kernels = np.linspace(3, random.randint(15, 21), step)
for i, gaussian_kernel in enumerate(gaussian_kernels):
gaussian_kernel = np.ceil(gaussian_kernel)
if not gaussian_kernel % 2:
gaussian_kernel += 1
gaussian_kernels[i] = gaussian_kernel

# Angle of rotation (in degrees)
angle = random.randint(0, 360)
# Center of ellipse
center_coordinates = (center_x, center_y)
# BGR color
color = (255, 255, 255)
# fill ellipse
thickness = -1

image_output = image.copy()

# it still run slow now, need further optimization
for i in range(step):

gaussian_kernel = (int(gaussian_kernels[i]), int(gaussian_kernels[i]))

image_ellipse = np.zeros_like(image, dtype="uint8")

axes_length = (axes_major, axes_minor) # Major and minor axes lengths

# Draw the oval on the image
cv2.ellipse(image_ellipse, center_coordinates, axes_length, angle, 0, 360, color, thickness)

# blur image
image_blur = cv2.GaussianBlur(image, gaussian_kernel, 0)

# blend blur region into image
image_output = cv2.seamlessClone(
image_output,
image_blur,
255 - image_ellipse,
(int(xsize / 2), int(ysize / 2)),
cv2.NORMAL_CLONE,
)

# increase major and minor length
axes_major = max(axes_major - decremental_value, 1)
axes_minor = max(axes_minor - decremental_value, 1)

# return image follows the input image color channel
if is_gray:
image_output = cv2.cvtColor(image_output, cv2.COLOR_BGR2GRAY)
if has_alpha:
image_output = np.dstack((image_output, image_alpha))

# check for additional output of mask, keypoints and bounding boxes
outputs_extra = []
if mask is not None or keypoints is not None or bounding_boxes is not None:
outputs_extra = [mask, keypoints, bounding_boxes]

# returns additional mask, keypoints and bounding boxes if there is additional input
if outputs_extra:
# returns in the format of [image, mask, keypoints, bounding_boxes]
return [image_output] + outputs_extra
else:
return image_output
Loading

0 comments on commit 09282c5

Please sign in to comment.