Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name = "VisualRegressionTests"
uuid = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
author = "Thomas Breloff"
version = "1.0.0"
version = "1.1.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageDistances = "51556ac3-7006-55f5-8cb3-34580c88182d"
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
QuartzImageIO = "dca85d43-d64c-5e67-8c65-017450d5d020"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
ColorTypes = "0.7, 0.8, 0.9, 0.10"
ColorVectorSpace = "0.6, 0.7, 0.8"
FileIO = "1"
ImageFiltering = "0.4, 0.5, 0.6"
ImageBase = "^0"
ImageDistances = "^0"
ImageFiltering = "^0"
ImageMagick = "0.7, 1"
QuartzImageIO = "0.7"
Requires = "1"
julia = "1.3"
julia = "1.5"

[extras]
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
Expand Down
4 changes: 2 additions & 2 deletions src/VisualRegressionTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module VisualRegressionTests

using Requires
using FileIO
using ColorTypes
using ColorVectorSpace
using ImageBase
using ImageDistances
using ImageFiltering

# ---------------------------------------------
Expand Down
48 changes: 4 additions & 44 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# a few utility functions copied/adapted from Images.jl

# github.com/JuliaGraphics/ColorVectorSpace.jl#abs-and-abs2
_abs(c::CT) where CT<:Color = mapreducec(v->abs(float(v)), +, zero(eltype(CT)), c)

"blur images `A` and `B` with `sigma` and then compute a difference"
function blurdiff(A::AbstractArray, B::AbstractArray, sigma)
# make sure arrays have the same size
Expand All @@ -17,51 +20,8 @@ function blurdiff(A::AbstractArray, B::AbstractArray, sigma)
Af = imfilter(A, kern, NA())
Bf = imfilter(B, kern, NA())
d = sad(Af, Bf)
diffscale = max(maxabsfinite(A), maxabsfinite(B))
diffscale = max(_abs(maxabsfinite(A)), _abs(maxabsfinite(B)))
diffpct = d / (length(Af) * diffscale)

diffpct
end

sad(A::AbstractArray, B::AbstractArray) = sumdiff(abs, A, B)

function sumdiff(f, A::AbstractArray, B::AbstractArray)
axes(A) == axes(B) || throw(DimensionMismatch("A and B must have the same indices"))
T = promote_type(difftype(eltype(A)), difftype(eltype(B)))
s = zero(accum(eltype(T)))
for (a, b) in zip(A, B)
x = convert(T, a) - convert(T, b)
s += f(x)
end
s
end

difftype(::Type{T}) where {T<:Integer} = Int
difftype(::Type{T}) where {T<:Real} = Float32
difftype(::Type{Float64}) = Float64
difftype(::Type{CV}) where {CV<:Colorant} = difftype(CV, eltype(CV))
difftype(::Type{CV}, ::Type{T}) where {CV<:RGBA,T<:Real} = RGBA{Float32}
difftype(::Type{CV}, ::Type{Float64}) where {CV<:RGBA} = RGBA{Float64}
difftype(::Type{CV}, ::Type{T}) where {CV<:BGRA,T<:Real} = BGRA{Float32}
difftype(::Type{CV}, ::Type{Float64}) where {CV<:BGRA} = BGRA{Float64}
difftype(::Type{CV}, ::Type{T}) where {CV<:AbstractGray,T<:Real} = Gray{Float32}
difftype(::Type{CV}, ::Type{Float64}) where {CV<:AbstractGray} = Gray{Float64}
difftype(::Type{CV}, ::Type{T}) where {CV<:AbstractRGB,T<:Real} = RGB{Float32}
difftype(::Type{CV}, ::Type{Float64}) where {CV<:AbstractRGB} = RGB{Float64}

accum(::Type{T}) where {T<:Integer} = Int
accum(::Type{Float32}) = Float32
accum(::Type{T}) where {T<:Real} = Float64
accum(::Type{C}) where {C<:Colorant} = base_colorant_type(C){accum(eltype(C))}

"maximum absolute value in `A` ignoring `Inf` or `NaN`"
function maxabsfinite(A)
m = -Inf
for a in A
v = abs(a)
if isfinite(v) && v > m
m = v
end
end
m
end