Skip to content

Commit

Permalink
Fixed Bug for color images
Browse files Browse the repository at this point in the history
  • Loading branch information
mronian committed Jul 10, 2016
1 parent ea7b12e commit 3438860
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3438860

Please sign in to comment.