@@ -256,39 +256,66 @@ odims(original, i, short_size::Tuple{}) = axes(original, i)
256256odims (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"""
293320function imresize (original:: AbstractArray{T,0} , new_inds:: Tuple{} ; kwargs... ) where T
294321 Tnew = imresize_type (first (original))
0 commit comments