Reference
List of view types
With that as an introduction, let's list all the view types supported by this package. channelview
and colorview
are opposite transformations, as are rawview
and normedview
. channelview
and colorview
typically create objects of type ChannelView
and ColorView
, respectively, unless they are "undoing" a previous view of the opposite type.
ImageCore.channelview
— Functionchannelview(A)
returns a view of A
, splitting out (if necessary) the color channels of A
into a new first dimension.
Of relevance for types like RGB and BGR, the channels of the returned array will be in constructor-argument order, not memory order (see reinterpretc
if you want to use memory order).
Example
img = rand(RGB{N0f8}, 10, 10)
A = channelview(img) # a 3×10×10 array
See also: colorview
ImageCore.colorview
— Functioncolorview(C, A)
returns a view of the numeric array A
, interpreting successive elements of A
as if they were channels of Colorant C
.
Of relevance for types like RGB and BGR, the elements of A
are interpreted in constructor-argument order, not memory order (see reinterpretc
if you want to use memory order).
Example
A = rand(3, 10, 10)
img = colorview(RGB, A)
See also: channelview
colorview(C, gray1, gray2, ...) -> imgC
Combine numeric/grayscale images gray1
, gray2
, etc., into the separate color channels of an array imgC
with element type C<:Colorant
.
As a convenience, the constant zeroarray
fills in an array of matched size with all zeros.
Example
imgC = colorview(RGB, r, zeroarray, b)
creates an image with r
in the red chanel, b
in the blue channel, and nothing in the green channel.
See also: StackedView
.
colorview(C)
Create a function that is equivalent to (As...) -> colorview(C, Ax...)
.
Examples
julia> ones(Float32, 2, 2) |> colorview(Gray)
2×2 reinterpret(reshape, Gray{Float32}, ::Matrix{Float32}) with eltype Gray{Float32}:
Gray{Float32}(1.0) Gray{Float32}(1.0)
Gray{Float32}(1.0) Gray{Float32}(1.0)
This can be slightly convenient when you want to convert a batch of channel data, for example:
julia> Rs, Gs, Bs = ntuple( i -> [randn(2, 2) for _ in 1:4], 3)
julia> map(colorview(RGB), Rs, Gs, Bs)
ImageCore.rawview
— Functionrawview(img::AbstractArray{FixedPoint})
returns a "view" of img
where the values are interpreted in terms of their raw underlying storage. For example, if img
is an Array{N0f8}
, the view will act like an Array{UInt8}
.
See also: normedview
ImageCore.normedview
— Functionnormedview([T], img::AbstractArray{Unsigned})
returns a "view" of img
where the values are interpreted in terms of Normed
number types. For example, if img
is an Array{UInt8}
, the view will act like an Array{N0f8}
. Supply T
if the element type of img
is UInt16
, to specify whether you want a N6f10
, N4f12
, N2f14
, or N0f16
result.
See also: rawview
ImageCore.StackedView
— TypeStackedView(B, C, ...) -> A
Present arrays B
, C
, etc, as if they are separate channels along the first dimension of A
. In particular,
B == A[1,:,:...]
C == A[2,:,:...]
and so on. Combined with colorview
, this allows one to combine two or more grayscale images into a single color image.
See also: colorview
.
List of value-transformations (map functions)
ImageCore.clamp01
— Functionclamp01(x) -> y
Produce a value y
that lies between 0 and 1, and equal to x
when x
is already in this range. Equivalent to clamp(x, 0, 1)
for numeric values. For colors, this function is applied to each color channel separately.
See also: clamp01!
, clamp01nan
.
ImageCore.clamp01!
— Functionclamp01!(array::AbstractArray)
Restrict values in array to [0, 1], in-place. See also clamp01
.
ImageCore.clamp01nan
— Functionclamp01nan(x) -> y
Similar to clamp01
, except that any NaN
values are changed to 0.
See also: clamp01nan!
, clamp01
.
ImageCore.clamp01nan!
— Functionclamp01nan!(array::AbstractArray)
Similar to clamp01!
, except that any NaN
values are changed to 0.
See also: clamp01!
, clamp01nan
ImageCore.scaleminmax
— Functionscaleminmax(min, max) -> f
scaleminmax(T, min, max) -> f
Return a function f
which maps values less than or equal to min
to 0, values greater than or equal to max
to 1, and uses a linear scale in between. min
and max
should be real values.
Optionally specify the return type T
. If T
is a colorant (e.g., RGB), then scaling is applied to each color channel.
Examples
Example 1
julia> f = scaleminmax(-10, 10)
(::#9) (generic function with 1 method)
julia> f(10)
1.0
julia> f(-10)
0.0
julia> f(5)
0.75
Example 2
julia> c = RGB(255.0,128.0,0.0)
RGB{Float64}(255.0,128.0,0.0)
julia> f = scaleminmax(RGB, 0, 255)
(::#13) (generic function with 1 method)
julia> f(c)
RGB{Float64}(1.0,0.5019607843137255,0.0)
See also: takemap
.
ImageCore.scalesigned
— Functionscalesigned(maxabs) -> f
Return a function f
which scales values in the range [-maxabs, maxabs]
(clamping values that lie outside this range) to the range [-1, 1]
.
See also: colorsigned
.
scalesigned(min, center, max) -> f
Return a function f
which scales values in the range [min, center]
to [-1,0]
and [center,max]
to [0,1]
. Values smaller than min
/max
get clamped to min
/max
, respectively.
See also: colorsigned
.
ImageCore.colorsigned
— Functioncolorsigned()
colorsigned(colorneg, colorpos) -> f
colorsigned(colorneg, colorcenter, colorpos) -> f
Define a function that maps negative values (in the range [-1,0]) to the linear colormap between colorneg
and colorcenter
, and positive values (in the range [0,1]) to the linear colormap between colorcenter
and colorpos
.
The default colors are:
colorcenter
: whitecolorneg
: green1colorpos
: magenta
See also: scalesigned
.
ImageCore.takemap
— Functiontakemap(f, A) -> fnew
takemap(f, T, A) -> fnew
Given a value-mapping function f
and an array A
, return a "concrete" mapping function fnew
. When applied to elements of A
, fnew
should return valid values for storage or display, for example in the range from 0 to 1 (for grayscale) or valid colorants. fnew
may be adapted to the actual values present in A
, and may not produce valid values for any inputs not in A
.
Optionally one can specify the output type T
that fnew
should produce.
Example:
julia> A = [0, 1, 1000];
julia> f = takemap(scaleminmax, A)
(::#7) (generic function with 1 method)
julia> f.(A)
3-element Array{Float64,1}:
0.0
0.001
1.0
List of storage-type transformations
ImageCore.float32
— Functionfloat32.(img)
converts the raw storage type of img
to Float32
, without changing the color space.
ImageCore.float64
— Functionfloat64.(img)
converts the raw storage type of img
to Float64
, without changing the color space.
ImageCore.n0f8
— Functionn0f8.(img)
converts the raw storage type of img
to N0f8
, without changing the color space.
ImageCore.n6f10
— Functionn6f10.(img)
converts the raw storage type of img
to N6f10
, without changing the color space.
ImageCore.n4f12
— Functionn4f12.(img)
converts the raw storage type of img
to N4f12
, without changing the color space.
ImageCore.n2f14
— Functionn2f14.(img)
converts the raw storage type of img
to N2f14
, without changing the color space.
ImageCore.n0f16
— Functionn0f16.(img)
converts the raw storage type of img
to N0f16
, without changing the color space.
List of traits
ImageCore.pixelspacing
— Functionpixelspacing(img) -> (sx, sy, ...)
Return a tuple representing the separation between adjacent pixels along each axis of the image. Defaults to (1,1,...). Use ImagesAxes for images with anisotropic spacing or to encode the spacing using physical units.
ImageCore.spacedirections
— Functionspacedirections(img) -> (axis1, axis2, ...)
Return a tuple-of-tuples, each axis[i]
representing the displacement vector between adjacent pixels along spatial axis i
of the image array, relative to some external coordinate system ("physical coordinates").
By default this is computed from pixelspacing
, but you can set this manually using ImagesMeta.
ImageCore.sdims
— Functionsdims(img)
Return the number of spatial dimensions in the image. Defaults to the same as ndims
, but with ImagesAxes you can specify that some axes correspond to other quantities (e.g., time) and thus not included by sdims
.
ImageCore.coords_spatial
— Functioncoords_spatial(img)
Return a tuple listing the spatial dimensions of img
.
Note that a better strategy may be to use ImagesAxes and take slices along the time axis.
ImageCore.size_spatial
— Functionsize_spatial(img)
Return a tuple listing the sizes of the spatial dimensions of the image. Defaults to the same as size
, but using ImagesAxes you can mark some axes as being non-spatial.
ImageCore.indices_spatial
— Functionindices_spatial(img)
Return a tuple with the indices of the spatial dimensions of the image. Defaults to the same as indices
, but using ImagesAxes you can mark some axes as being non-spatial.
ImageCore.nimages
— Functionnimages(img)
Return the number of time-points in the image array. Defaults to
- Use ImagesAxes if you want to use an explicit time dimension.
ImageCore.assert_timedim_last
— Functionassert_timedim_last(img)
Throw an error if the image has a time dimension that is not the last dimension.