Skip to content
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

nearest_aligned is not aligned #62

Open
awused opened this issue Nov 30, 2021 · 2 comments
Open

nearest_aligned is not aligned #62

awused opened this issue Nov 30, 2021 · 2 comments

Comments

@awused
Copy link

awused commented Nov 30, 2021

When using nearest_aligned the output is noticeably shifted down and to the right. This affects my models severely and causes noticeable warping in their output.

I used this code in augmentations.py to produce the output images:

if __name__ == '__main__':
    img = cv2.imread('test.png')
    img_A, _ = Scale(img=img, scale=4, algo=997, ds_kernel=None, img_type='cv2')
    cv2.imwrite('output.png', img_A)

original image

Output from nearest_aligned as per the above code:
output

Output from convert test.png -interpolate Average -filter point -resize 25% magick-nearest.png:
magick-nearest

Explicitly sampling the top left corner closely matches the offset from nearest_aligned:
convert test.png -define sample:offset=0%x0% -sample 25% magick-sampled-top-left.png
magick-sampled-top-left

@victorca25
Copy link
Owner

Any change in nearest_aligned would go in https://github.com/victorca25/augmennt, but can you test what I commented here:

Note: the default kernel size is set to 21, but 17 works.

For the cases I tested, the images were aligned, but maybe in some cases it needs a larger blur kernel.

@awused
Copy link
Author

awused commented Dec 2, 2021

I've tested it on multiple files, it's not like the input file matters. I first noticed it as warping in the output of my models, which was obviously apparent and corrected after I implemented my own local fix, but my local fix is a hack that can't be merged that only works locally because I don't trigger any other code paths that use sample().

As the code is now it's simply wrong. I cannot guess how you tested it to make it appear correct, but my tests are repeatable at both 2x and 4x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants