Usage of imfilter() with specified type

Hey there,
I am trying to apply a simple gaussian blur to an image of type Matrix{Gray{N0f8}}, but recognized that the returned type is Matrix{Gray{Float64}}.
. After looking up the documentation at Function reference · ImageFiltering I can see that there is a optional Type argument [T], but I cannot find an example with how to apply the type.

simple example:

using Images
dummy_img = rand(Gray{N0f8}, 2, 2)
println(typeof(dummy_img))
dummy_blur = imfilter(dummy_img, Kernel.gaussian(2))
println(typeof(dummy_blur)) #should also by Matrix{Gray{N0f8}}

Simply running it resulting in an error in my instance:

dummy_blur = imfilter(Matrix{Gray{N0f8}}, dummy_img, Kernel.gaussian(2))

Error Stacktrace:

Type Array does not have a definite size.

    sizeof(::Type)@essentials.jl:559
    padded_tilesize(::Type{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Tuple{Int64, Int64}, ::Int64)@TiledIteration.jl:185
    padded_tilesize(::Type{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Tuple{Int64, Int64})@TiledIteration.jl:182
    filter_algorithm(::Matrix{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}, ::Tuple{OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}, OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}})@imfilter.jl:1553
    imfilter!(::Matrix{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}, ::Tuple{OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}, OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}}, ::ImageFiltering.Pad{0})@imfilter.jl:606
    imfilter@imfilter.jl:27[inlined]
    imfilter(::Type{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}, ::Tuple{OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}, OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}}, ::String)@imfilter.jl:22
    imfilter(::Type{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}, ::Tuple{OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}, OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}}})@imfilter.jl:18
    imfilter(::Type{Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}}, ::Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}}, ::OffsetArrays.OffsetMatrix{Float64, Matrix{Float64}})@imfilter.jl:10
    top-level scope@Local: 1[inlined]

Optionally, you can control the element type of the output image by passing in a type T as the first argument.

Untested, but I would try to pass T as the element type rather than the matrix type.

2 Likes

Element type, perhaps:

imfilter(Gray{N0f8}, dummy_img, Kernel.gaussian(2))
2 Likes