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

imresize/imrotate fixed point #129

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

ginkulv
Copy link

@ginkulv ginkulv commented Jun 6, 2021

Resolves #121.
First of all, I haven't implemented imresize(img, inds, p::FixedPointType). It didn't make sense to me when I thought about it. As I understand it, the point of this transformation is adjusting the axes in the way that the fixed_point is, well, fixed. And here we explicitly define the axes beforehand.

The second thing is about fixed_point itself. When it's defined as Union{Dims{N}, CartesianIndex} the following functions have the same set of arguments:

imresize(original::AbstractArray{T,N}, new_size::Dims{N}; kwargs...)
imresize(original::AbstractArray{T,N}, fixed_point::Union{Dims{N}, CartesianIndex}; ratio, kwargs...)

when a Tuple is passed. By this reason right now it only takes CartesianIndex.

Please, correct me, if I'm wrong. If it looks fine to you, I'll move on writing tests and implementing it for imrotate.

@johnnychen94
Copy link
Member

Maybe we can provide a FixedPoint trait type here so as to not worry about the method ambiguity:

struct FixedPoint{N}
    p::CartesianIndex{N}
end

imresize(img, (512, 512), FixedPoint(1, 1))

Another choice is to introduce a new name for every function, i.e., fixed_imrotate, fixed_imresize but I personally don't quite like it.

@ginkulv
Copy link
Author

ginkulv commented Jun 7, 2021

I think your solution nicely and obviously separates functions with a fixed point and without, so I'd proceed with it. I guess, it's going to be in a new file for further using in imrotate.

@ginkulv
Copy link
Author

ginkulv commented Jun 8, 2021

Always forget about tests until they fail...
Anyway, it appears there is already a FixedPoint type belonging to the FixedPointNumbers package. I'm thinking of renaming the new struct to CenterPoint, is it appropriate?

@johnnychen94
Copy link
Member

CenterPoint looks good to me.

Another possible name can be InvariantPoint from https://en.wikipedia.org/wiki/Fixed_point_(mathematics)

Copy link
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are definitely needed..

src/resizing.jl Outdated
offset = cp.I .- new_size .* (cp.I .- topleft) .÷ size(original) .- 1
resized = OffsetArray(similar(original, Tnew, new_size), offset)
imresize!(resized, original; kwargs...)
resized[cp] = original[cp]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that resized[cp] can be different from original[cp] because of the warp method we're using. But I don't think we need to overwrite resized[cp] here.

Looks like there's no fixed point at all 😢

Comment on lines 7 to 9
```jldoctest
img[cp] == imgr[cp]
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this jldoctest is definitely broken. Using

Suggested change
```jldoctest
img[cp] == imgr[cp]
```
```julia
img[cp] == imgr[cp]
```

would be fine.

The more concerning issue here is that maybe there isn't such a fixed point concept at all. All we're introducing is a warp center point. Looks like it is this property that holds true:

CartesianIndices(img)[cp] == CartesianIndices(imgr)[cp]

I'm in a bad state here and don't have enough bandwidth to think this carefully. Can you double-check it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I could make such a bad mistake, sorry. I will test it carefully.

Copy link
Author

@ginkulv ginkulv Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't notice 'at all' and got the meaning of your comment wrong.

All we're introducing is a warp center point.

Honestly, that's what I was thinking about. Not to disturb your state, but can you give any tips of how this idea looks in your head? Othewise I'm afraid I don't understand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the back-and-forth and the inaccuracy.

In https://evizero.github.io/Augmentor.jl/dev/operations/#Affine-Transformations, the scale/resize is no different from imresize. I was thinking of a generic solution to the Zoom operator there where the center point is invariant. The term "fixed point" showed itself in my head when I wrote down #121.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed response, got stuck with exams. Unfortunately, I still can't fully understand your concerns. I made a poor visualization of what it does right now when I create a new image with imresize(img, FixedPoint(100, 100); ratio=0.5).
resizing
To me it looks like it works as expected and implements the Zoom operator, except it doesn't crop the image. Hopefully, my point is clear and makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'll recheck next weekend (also busy with school stuff). In the meantime, if you can add up some tests when you're available it would be great.

Comment on lines +50 to +52
test_imresize_interface(img, (5,5), (5,5), CenterPoint(1, 1))
test_imresize_interface(img, (20,20), CenterPoint(1, 1), ratio = 2)
test_imresize_interface(img, (20,10), CenterPoint(1, 1), ratio = (2, 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only makes sure the function gets called and outputs something. We also need to test if the output is correct, for example:

  • test if imresize(img, (20,20), CenterPoint(1, 1)) works the same as imresize(img, (20,20))
  • test if imresize(img, (20, 20), CenterPoint(5, 5); method=Constant())[5, 5] == img[5, 5] (If I'm right about the implementation, I'm not sure if it's [5, 5] here).
  • If it's not supported, test if imresize(imag, (20, 20), CenterPoint(-10, -10)) errors.

Also, OffsetArray is used widely in the ecosystem, so it would be great to also test OffsetArray(img, -1, -1) works normally for the above test cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About testing if the CenterPoint doesn't change, without overriding the value it can be actully quite different, so either we should override it or it won't be ensured. Except this point I'm working on it.

Copy link
Member

@johnnychen94 johnnychen94 Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I also noticed this. BSpline(Constant()) is the nearest interpolation, I believe by using this method, it won't doesn't change the value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right.

@codecov
Copy link

codecov bot commented Jul 25, 2021

Codecov Report

Merging #129 (dd9d5c7) into master (c73b48e) will increase coverage by 0.89%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #129      +/-   ##
==========================================
+ Coverage   91.74%   92.64%   +0.89%     
==========================================
  Files           8        9       +1     
  Lines         218      231      +13     
==========================================
+ Hits          200      214      +14     
+ Misses         18       17       -1     
Impacted Files Coverage Δ
src/ImageTransformations.jl 83.33% <ø> (ø)
src/centerpoint.jl 100.00% <100.00%> (ø)
src/resizing.jl 100.00% <100.00%> (ø)
src/warp.jl 100.00% <0.00%> (ø)
src/compat.jl 83.33% <0.00%> (+5.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c73b48e...dd9d5c7. Read the comment docs.

@johnnychen94
Copy link
Member

johnnychen94 commented Jul 26, 2021

@ginkulv Sorry for the delay! This fixed point thing is more complicated than I thought it could be, so instead of commenting here, I'll open a PR for it for discussion.

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

Successfully merging this pull request may close these issues.

imresize/imrotate fixed point
2 participants