8000 Refactor geometric.py and Augmenter, add module imgaug.validation, fix various small issues by aleju · Pull Request #413 · aleju/imgaug · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Refactor geometric.py and Augmenter, add module imgaug.validation, fix various small issues #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
344e83f
Decrease code duplication in Affine
aleju Sep 8, 2019
c66ff4f
Decrease code duplication between Affine and PiecewiseAffine
aleju Sep 8, 2019
339423e
Decrease code duplication in PiecewiseAffine
aleju Sep 8, 2019
9a9efb0
Refactor PiecewiseAffine to use sampling class
aleju Sep 8, 2019
cb80094
Make cval, mode, order configurable in PiecewAffine for HMs/SMs
aleju Sep 8, 2019
badc8ee
Reduce code duplication in PerspectiveTransform
aleju Sep 9, 2019
b0bdcbf
Cleanup code of ElasticTransformation
aleju Sep 10, 2019
3618f79
Decrease code duplication in Rot90
aleju Sep 11, 2019
61ecef4
Shorten code in AllChannelsCLAHE
aleju Sep 11, 2019
e976030
Add ArgsCopyingMagicMock helper for tests
aleju Sep 11, 2019
9e2885d
Fix AllChannelsCLAHE tests failing due to args not copied
aleju Sep 11, 2019
e8bf44a
Fix color quantization tests
aleju Sep 11, 2019
5da6100
Fix Rot90 test using wrong interpolation
aleju Sep 11, 2019
9ecb29b
Improved code quality of Augmenter.augment_images()
aleju Sep 11, 2019
9794a6e
Add link for source to ArgCopyingMagicMock
aleju Sep 11, 2019
171b216
Refactor ArgCopyingMagicMock
aleju Sep 11, 2019
8000 0e3680d
Remove redundant np.squeeze() call in imresize_single_image()
aleju Sep 11, 2019
5216a14
Change todo
aleju Sep 11, 2019
ad6fae4
Improve code quality of Augmenter.augment_heatmaps()
aleju Sep 11, 2019
2e53835
Improve code quality of Augmenter.augment_segmentation_maps()
aleju Sep 11, 2019
c028985
Improve code quality of Augmenter.augment_keypoints()
aleju Sep 11, 2019
7faa204
Remove unnecessary code from augment_polygons() and augment_line_stri…
aleju Sep 11, 2019
5b700c1
Improve code quality of Augmenter._augment_coord_augables()
aleju Sep 11, 2019
29d78af
Add refactoring updates to changelog
aleju Sep 11, 2019
064a4ff
Decrease code duplication in Sequential
aleju Sep 12, 2019
1f2c646
Improve code quality of SomeOf
aleju Sep 12, 2019
cd2d645
Decrease code duplication in Sometimes
aleju Sep 12, 2019
c36bc11
Decrease code duplication in AssertShape
aleju Sep 12, 2019
c55bea1
Improve code quality of ChannelShuffle
aleju Sep 12, 2019
aa9d396
Change KeypointsOnImage.from_keypoint_image to return (x+0.5, y+0.5)
aleju Sep 12, 2019
dd7d08d
Add image-keypoint alignment test
aleju Sep 12, 2019
dd1e1e8
Add recent refactoring changes to changelog
aleju Sep 12, 2019
2ee2e4d
Fix wrong PR IDs in changelog
aleju Sep 12, 2019
a741f9d
Add missing module .validation
aleju Sep 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,42 @@
`JpegCompression`.
* [rarely breaking] Removed attribute `minimum_quality` from
`JpegCompression`.
* Refactored `Affine` to improve code quality and decrease code
duplication. #413
* Refactored `PiecewiseAffine` to improve code quality and decrease code
duplication. #413
* Refactored `PerspectiveTransform` to improve code quality and decrease code
duplication. #413
* Refactored `ElasticTransformation` to improve code quality and decrease code
duplication. #413
* [rarely breaking] Renamed `ElasticTransformation.generate_shift_maps()` to
`ElasticTransformation._generate_shift_maps()`.
* [rarely breaking] Renamed `ElasticTransformation.map_coordinates()` to
`ElasticTransformation._map_coordinates()`.
* Refactored `Rot90` to improve code quality and decrease code
duplication. #413
* Added `imgaug.testutils.ArgCopyingMagicMock`. #413
* Refactored `Augmenter.augment_images()`, `Augmenter.augment_heatmaps()`,
`Augmenter.augment_segmentation_maps()`, `Augmenter.augment_polygons()`,
`Augmenter.augment_line_strings()` and `Augmenter._augment_coord_augables()`
to improve code quality and remove redundancies. #413
* Refactored `imgaug.imgaug.imresize_single_image()`. #413
* Added module `imgaug.validation`. #413
* Added `imgaug.validation.convert_iterable_to_string_of_types()`.
* Added `imgaug.validation.is_iterable_of()`.
* Added `imgaug.validation.assert_is_iterable_of()`.
* Refactored `Sequential` to reduce code duplication. #413
* Refactored `SomeOf` to improve code quality. #413
* Refactored `Sometimes` to reduce code duplication. #413
* Refactored `AssertShape` to reduce code duplication. #413
* Refactored `ChannelShuffle` to improve code quality. #413
* [rarely breaking] Changed `KeypointsOnImage.from_keypoints_image()` to
return `(x+0.5, y+0.5)` instead of `(x, y)` where `(x, y)` denotes the
coordinates of the pixel in which a maximum was found. This change matches
the standard that all pixels are given with subpixel accuracy and therefore
any whole pixel with a maximum should denote the coordinates of that
pixel's center. #413


## Improved Segmentation Map Augmentation #302

Expand Down
5 changes: 4 additions & 1 deletion imgaug/augmentables/kps.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,12 @@ def from_keypoint_image(image, if_not_found_coords={"x": -1, "y": -1},
for i in sm.xrange(nb_keypoints):
maxidx_flat = np.argmax(image[..., i])
maxidx_ndim = np.unravel_index(maxidx_flat, (height, width))

found = (image[maxidx_ndim[0], maxidx_ndim[1], i] >= threshold)
if found:
keypoints.append(Keypoint(x=maxidx_ndim[1], y=maxidx_ndim[0]))
x = maxidx_ndim[1] + 0.5
y = maxidx_ndim[0] + 0.5
keypoints.append(Keypoint(x=x, y=y))
else:
if drop_if_not_found:
# dont add the keypoint to the result list, i.e. drop it
Expand Down
27 changes: 16 additions & 11 deletions imgaug/augmenters/blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,7 @@ def blur_gaussian_(image, sigma, ksize=None, backend="auto", eps=1e-3):
# ksize = ((sig - 0.8)/0.3 + 1)/0.5 + 1

if ksize is None:
if sigma < 3.0:
ksize = 3.3 * sigma # 99% of weight
elif sigma < 5.0:
ksize = 2.9 * sigma # 97% of weight
else:
ksize = 2.6 * sigma # 95% of weight

# we use 5x5 here as the minimum size as that simplifies
# comparisons with gaussian_filter() in the tests
# TODO reduce this to 3x3
ksize = int(max(ksize, 5))
ksize = _compute_gaussian_blur_ksize(sigma)
else:
assert ia.is_single_integer(ksize), (
"Expected 'ksize' argument to be a number, "
Expand All @@ -283,6 +273,21 @@ def blur_gaussian_(image, sigma, ksize=None, backend="auto", eps=1e-3):
return image


def _compute_gaussian_blur_ksize(sigma):
if sigma < 3.0:
ksize = 3.3 * sigma # 99% of weight
elif sigma < 5.0:
ksize = 2.9 * sigma # 97% of weight
else:
ksize = 2.6 * sigma # 95% of weight

# we use 5x5 here as the minimum size as that simplifies
# comparisons with gaussian_filter() in the tests
# TODO reduce this to 3x3
ksize = int(max(ksize, 5))
return ksize


# TODO offer different values for sigma on x/y-axis, supported by cv2 but not
# by scipy
# TODO add channelwise flag - channelwise=False would be supported by scipy
Expand Down
3 changes: 1 addition & 2 deletions imgaug/augmenters/contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,7 @@ def _augment_images(self, images, random_state, parents, hooks):
c_param += 1

# combine channels to one image
image_warped = np.array(image_warped, dtype=image_warped[0].dtype)
image_warped = image_warped.transpose((1, 2, 0))
image_warped = np.stack(image_warped, axis=-1)

images[i] = image_warped
return images
Expand Down
Loading
0