From 251fb2d648cd60f8ac70f7b6a39af4a65d04931f Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 21 Apr 2022 03:34:18 +0800 Subject: [PATCH] fix UInt8 indexed image for im_from_matlab --- src/matlab.jl | 2 +- test/matlab.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/matlab.jl b/src/matlab.jl index 15361c7..d09d582 100644 --- a/src/matlab.jl +++ b/src/matlab.jl @@ -132,7 +132,7 @@ _im_from_matlab(::Type{CT}, X::AbstractArray{T}) where {CT<:Gray,T<:Real} = colo _im_from_matlab(::Type{CT}, X::AbstractArray{T,3}) where {CT<:Gray,T<:Real} = colorview(CT, X) # index image support -im_from_matlab(index::AbstractArray, values::AbstractMatrix{T}) where T<:Real = im_from_matlab(RGB{T}, index, values) +im_from_matlab(index::AbstractArray, values::AbstractMatrix{T}) where T<:Real = im_from_matlab(RGB, index, values) @static if VERSION >= v"1.3" function im_from_matlab(::Type{CT}, index::AbstractArray, values::AbstractMatrix{T}) where {CT<:Colorant, T<:Real} return IndirectArray(index, im_from_matlab(CT, values)) diff --git a/test/matlab.jl b/test/matlab.jl index 07890f8..39f8394 100644 --- a/test/matlab.jl +++ b/test/matlab.jl @@ -149,6 +149,12 @@ lab_values = permutedims(channelview(Lab.(img.values)), (2, 1)) lab_img = im_from_matlab(Lab, index, lab_values) @test sum(abs2, channelview(RGB.(lab_img) - img)) < 1e-10 + + values = UInt8.(values .* 255) + img = im_from_matlab(index, values) + @test size(img) == (2, 5) + @test eltype(img) == RGB{N0f8} + @test img[2, 3] == RGB(0.0, 0.0, 1.0) end end