From 3438860791aa6687def0094e8146de6e7c21de03 Mon Sep 17 00:00:00 2001 From: mronian Date: Mon, 11 Jul 2016 01:51:49 +0530 Subject: [PATCH] Fixed Bug for color images --- src/algorithms.jl | 12 ++++++++---- test/algorithms.jl | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/algorithms.jl b/src/algorithms.jl index cbb1a732..35a12fcd 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -435,6 +435,8 @@ difftype{CV<:AbstractRGB}(::Type{CV}, ::Type{Float64}) = RGB{Float64} accum{T<:Integer}(::Type{T}) = Int accum(::Type{Float32}) = Float32 accum{T<:Real}(::Type{T}) = Float64 +accum{C<:Colorant}(::Type{C}) = base_colorant_type(C){accum(eltype(C))} + # normalized by Array size "`s = ssdn(A, B)` computes the sum-of-squared differences over arrays/images A and B, normalized by array size" @@ -1966,9 +1968,11 @@ to each pixel the sum of all pixels above it and to its left, i.e. the rectangle (1, 1) to the pixel. """ function integral_image(img::AbstractArray) - integral_img = convert(Array{UInt}, raw(img)) - for i in 1:ndims(img) - integral_img = cumsum(integral_img, i) - end + integral_img = Array{accum(eltype(img))}(size(img)) + sd = coords_spatial(img) + cumsum!(integral_img, img, sd[1]) + for i = 2:length(sd) + cumsum!(integral_img, integral_img, sd[i]) + end integral_img end \ No newline at end of file diff --git a/test/algorithms.jl b/test/algorithms.jl index 33690919..82e9b45a 100755 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -154,7 +154,7 @@ facts("Algorithms") do a = ones(10,10) int_img = integral_image(a) chk = Array(1:10) - @fact all([int_img[i, :] == chk * i for i in 1:10]) --> true + @fact all([vec(int_img[i, :]) == chk * i for i in 1:10]) --> true a = reshape(1:100, 10, 10) int_img = integral_image(a)