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

Fixing very minor typo in the ImageTransformations.imresize function documentation. #171

Open
MendeBadra opened this issue Sep 16, 2024 · 0 comments

Comments

@MendeBadra
Copy link

"""
imresize(img, sz; [method]) -> imgr
imresize(img, inds; [method]) -> imgr
imresize(img; ratio, [method]) -> imgr
upsample/downsample the image `img` to a given size `sz` or axes `inds` using interpolations. If
`ratio` is provided, the output size is then `ceil(Int, size(img).*ratio)`.
!!! tip
This interpolates the values at sub-pixel locations. If you are shrinking the image, you risk
aliasing unless you low-pass filter `img` first.
# Arguments
- `img`: the input image array
- `sz`: the size of output array
- `inds`: the axes of output array
If `inds` is passed, the output array `imgr` will be `OffsetArray`.
# Parameters
!!! info
To construct `method`, you may need to load `Interpolations` package first.
- `ratio`: the upsample/downsample ratio used.
The output size is `ceil(Int, size(img).*ratio)`. If `ratio` is larger than `1`, it is
an upsample operation. Otherwise it is a downsample operation. `ratio` can also be a tuple,
in which case `ratio[i]` specifies the resize ratio at dimension `i`.
- `method::InterpolationType`:
specify the interpolation method used for reconstruction. conveniently, `methold` can
also be a `Degree` type, in which case a `BSpline` object will be created.
For example, `method = Linear()` is equivalent to `method = BSpline(Linear())`.
# Examples
```julia
using ImageTransformations, TestImages, Interpolations
img = testimage("lighthouse") # 512*768
# pass integers as size
imresize(img, 256, 384) # 256*384
imresize(img, (256, 384)) # 256*384
imresize(img, 256) # 256*768
# pass indices as axes
imresize(img, 1:256, 1:384) # 256*384
imresize(img, (1:256, 1:384)) # 256*384
imresize(img, (1:256, )) # 256*768
# pass resize ratio
imresize(img, ratio = 0.5) #256*384
imresize(img, ratio = (2, 1)) # 1024*768
# use different interpolation method
imresize(img, (256, 384), method=Linear()) # 256*384 bilinear interpolation
imresize(img, (256, 384), method=Lanczos4OpenCV()) # 256*384 OpenCV-compatible Lanczos 4 interpolation
```
For downsample with `ratio=0.5`, [`restrict`](@ref) is a much faster two-fold implementation that
you can use.
"""

In lines 37-38 there is a typo, namely:

line 38: ratio is provided, the output size is then ceil(Int, size(img).*ratio)

But running this returns error because obviously size(img) returns a tuple. To fix this I suggest:

sz = ceil.(Int, size(img).*ratio)

to broadcast the ceil function.

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

1 participant