Skip to content

Commit 3fe10ed

Browse files
committed
rewrite/update the docstring
1 parent 6466463 commit 3fe10ed

File tree

4 files changed

+225
-139
lines changed

4 files changed

+225
-139
lines changed

src/invwarpedview.jl

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
InvWarpedView(img, tinv, [indices]) -> wv
33
44
Create a view of `img` that lazily transforms any given index `I`
5-
passed to `wv[I]` to correspond to `img[inv(tinv)(I)]`. While
6-
technically this approach is known as backward mode warping, note
7-
that `InvWarpedView` is created by supplying the forward
8-
transformation
5+
passed to `wv[I]` so that `wv[I] == img[inv(tinv)(I)]`.
96
107
The conceptual difference to [`WarpedView`](@ref) is that
118
`InvWarpedView` is intended to be used when reasoning about the
@@ -14,12 +11,10 @@ Furthermore, `InvWarpedView` allows simple nesting of
1411
transformations, in which case the transformations will be
1512
composed into a single one.
1613
17-
The optional parameter `indices` can be used to specify the
18-
domain of the resulting `wv`. By default the indices are computed
19-
in such a way that `wv` contains all the original pixels in
20-
`img`.
14+
See [`invwarpedview`](@ref) for a convenient constructor of `InvWarpedView`.
2115
22-
see [`invwarpedview`](@ref) for more information.
16+
For detailed explaination of warp, associated arguments and parameters,
17+
please refer to [`warp`](@ref).
2318
"""
2419
struct InvWarpedView{T,N,A,F,I,FI<:Transformation,E} <: AbstractArray{T,N}
2520
inner::WarpedView{T,N,A,F,I,E}
@@ -67,28 +62,20 @@ function Base.showarg(io::IO, A::InvWarpedView, toplevel)
6762
end
6863

6964
"""
70-
invwarpedview(img, tinv, [indices], [degree = Linear()], [fill = NaN]) -> wv
65+
invwarpedview(img, tinv, [indices]; kwargs...) -> wv
7166
7267
Create a view of `img` that lazily transforms any given index `I`
73-
passed to `wv[I]` to correspond to `img[inv(tinv)(I)]`. While
74-
technically this approach is known as backward mode warping, note
75-
that `InvWarpedView` is created by supplying the forward
76-
transformation. The given transformation `tinv` must accept a
77-
`SVector` as input and support `inv(tinv)`. A useful package to
78-
create a wide variety of such transformations is
79-
[CoordinateTransformations.jl](https://github.com/FugroRoames/CoordinateTransformations.jl).
80-
81-
When invoking `wv[I]`, values for `img` must be reconstructed at
82-
arbitrary locations `inv(tinv)(I)`. `InvWarpedView` serves as a
83-
wrapper around [`WarpedView`](@ref) which takes care of
84-
interpolation and extrapolation. The parameters `degree` and
85-
`fill` can be used to specify the b-spline degree and the
86-
extrapolation scheme respectively.
87-
88-
The optional parameter `indices` can be used to specify the
89-
domain of the resulting `wv`. By default the indices are computed
90-
in such a way that `wv` contains all the original pixels in
91-
`img`.
68+
passed to `wv[I]` so that `wv[I] == img[inv(tinv)(I)]`.
69+
70+
Except for the lazy evaluation, the following two lines are equivalent:
71+
72+
```julia
73+
warp(img, inv(tform), [indices]; kwargs...)
74+
invwarpedview(img, tform, [indices]; kwargs...)
75+
```
76+
77+
For detailed explaination of warp, associated arguments and parameters,
78+
please refer to [`warp`](@ref).
9279
"""
9380
function invwarpedview(A::AbstractArray, tinv::Transformation, indices::Tuple=autorange(A, tinv); kwargs...)
9481
InvWarpedView(box_extrapolation(A; kwargs...), tinv, indices)

src/resizing.jl

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -256,39 +256,66 @@ odims(original, i, short_size::Tuple{}) = axes(original, i)
256256
odims(original, i, short_size) = oftype(first(short_size), axes(original, i))
257257

258258
"""
259-
imresize(img, sz) -> imgr
260-
imresize(img, inds) -> imgr
261-
imresize(img; ratio) -> imgr
259+
imresize(img, sz; [method]) -> imgr
260+
imresize(img, inds; [method]) -> imgr
261+
imresize(img; ratio, [method]) -> imgr
262262
263-
Change `img` to be of size `sz` (or to have indices `inds`). If `ratio` is used, then
264-
`sz = ceil(Int, size(img).*ratio)`. This interpolates the values at sub-pixel locations.
265-
If you are shrinking the image, you risk aliasing unless you low-pass filter `img` first.
263+
upsample/downsample the image `img` to a given size `sz` or axes `inds` using interpolations. If
264+
`ratio` is provided, the output size is then `ceil(Int, size(img).*ratio)`.
266265
267-
The keyword `method` takes any InterpolationType from Interpolations.jl or a Degree,
268-
which is used to define a BSpline interpolation of that degree, in order to set
269-
the interpolation method used in the image resizing.
266+
!!! tip
267+
This interpolates the values at sub-pixel locations. If you are shrinking the image, you risk
268+
aliasing unless you low-pass filter `img` first.
269+
270+
# Arguments
271+
272+
- `img`: the input image array
273+
- `sz`: the size of output array
274+
- `inds`: the axes of output array
275+
If `inds` is passed, the output array `imgr` will be `OffsetArray`.
276+
277+
# Parameters
278+
279+
!!! info
280+
To construct `method`, you may need to load `Interpolations` package first.
281+
282+
- `ratio`: the upsample/downsample ratio used.
283+
The output size is `ceil(Int, size(img).*ratio)`. If `ratio` is larger than `1`, it is
284+
an upsample operation. Otherwise it is a downsample operation. `ratio` can also be a tuple,
285+
in which case `ratio[i]` specifies the resize ratio at dimension `i`.
286+
- `method::InterpolationType`:
287+
specify the interpolation method used for reconstruction. conveniently, `methold` can
288+
also be a `Degree` type, in which case a `BSpline` object will be created.
289+
For example, `method = Linear()` is equivalent to `method = BSpline(Linear())`.
270290
271291
# Examples
292+
272293
```julia
273-
julia> img = testimage("lena_gray_256") # 256*256
274-
julia> imresize(img, 128, 128) # 128*128
275-
julia> imresize(img, 1:128, 1:128) # 128*128
276-
julia> imresize(img, (128, 128)) # 128*128
277-
julia> imresize(img, (1:128, 1:128)) # 128*128
278-
julia> imresize(img, (1:128, )) # 128*256
279-
julia> imresize(img, 128) # 128*256
280-
julia> imresize(img, ratio = 0.5) #128*128
281-
julia> imresize(img, ratio = (2, 1)) # 256*128
282-
julia> imresize(img, (128,128), method=Linear()) #128*128
283-
julia> imresize(img, (128,128), method=BSpline(Linear())) #128*128
284-
julia> imresize(img, (128,128), method=Lanczos4OpenCV()) #128*128
285-
286-
σ = map((o,n)->0.75*o/n, size(img), sz)
287-
kern = KernelFactors.gaussian(σ) # from ImageFiltering
288-
imgr = imresize(imfilter(img, kern, NA()), sz)
294+
using ImageTransformations, TestImages, Interpolations
295+
296+
img = testimage("lighthouse") # 512*768
297+
298+
# pass integers as size
299+
imresize(img, 256, 384) # 256*384
300+
imresize(img, (256, 384)) # 256*384
301+
imresize(img, 256) # 256*768
302+
303+
# pass indices as axes
304+
imresize(img, 1:256, 1:384) # 256*384
305+
imresize(img, (1:256, 1:384)) # 256*384
306+
imresize(img, (1:256, )) # 256*768
307+
308+
# pass resize ratio
309+
imresize(img, ratio = 0.5) #256*384
310+
imresize(img, ratio = (2, 1)) # 1024*768
311+
312+
# use different interpolation method
313+
imresize(img, (256, 384), method=Linear()) # 256*384 bilinear interpolation
314+
imresize(img, (256, 384), method=Lanczos4OpenCV()) # 256*384 OpenCV-compatible Lanczos 4 interpolation
289315
```
290316
291-
See also [`restrict`](@ref).
317+
For downsample with `ratio=0.5`, [`restrict`](@ref) is a much faster two-fold implementation that
318+
you can use.
292319
"""
293320
function imresize(original::AbstractArray{T,0}, new_inds::Tuple{}; kwargs...) where T
294321
Tnew = imresize_type(first(original))

0 commit comments

Comments
 (0)