I created a function to convert Images.jl’s packed format into a planar format:
using Images;
function ConverImagePlanarForm( mI :: Matrix{RGB{Normed{U, f}}} ) :: Array{U, 3} where{U <: Unsigned, f <: Integer}
# Converts from Julia Images Packed from to Planar form:
# R1G1B1R2G2B2R3G3B3 -> R1R2R3G1G2G3B1B2B3
dataType = FixedPointNumbers.rawtype(eltype(eltype(mI)));
return permutedims(reinterpret(reshape, dataType, mI), (2, 3, 1));
end
Since Images.jl uses FixedPointNumbers.jl’s types I parameterized both input and output on it.
In FixedPointNumbers.jl’s documentation it is stated that:
the
N0f8type (aliased toNormed{UInt8,8}) is represented internally by aUInt8…
So the above should work.
I tested it with:
mS = Matrix{RGB{Normed{UInt8, 4}}}([0.1 1.0; 0.9 0.75]);
typeof(mS)
Yields:
Matrix{RGB{N4f4}} (alias for Array{RGB{Normed{UInt8, 4}}, 2})
Which is great, since it means that U will be parameterized as UInt8 and f is indeed an integer.
Yet:
julia> ConverImagePlanarForm(mS)
ERROR: MethodError: no method matching ConverImagePlanarForm(::Matrix{RGB{N4f4}})
Closest candidates are:
ConverImagePlanarForm(::Array{RGB{Normed{U, f}}, 2}) where {U<:Unsigned, f<:Integer}
I don’t understand why it doesn’t catch the method defined as they should match.
I have a feeling that UInt8’s type is something different.
Is there a correct way to achieve what I want?