Skip to content

Commit

Permalink
Merge pull request #508 from mronian/addsintegralimage
Browse files Browse the repository at this point in the history
Adds Integral Image. Required for CENSURE in ImageFeatures
  • Loading branch information
timholy authored Jul 11, 2016
2 parents 581e765 + 3438860 commit 919f480
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export # types
thin_edges_nonmaxsup,
thin_edges_nonmaxsup_subpix,
canny,
integral_image,

# distances
hausdorff_distance,
Expand Down Expand Up @@ -284,7 +285,7 @@ Contrast/coloration:
Algorithms:
- Reductions: `maxfinite`, `maxabsfinite`, `minfinite`, `meanfinite`, `sad`, `ssd`
- Reductions: `maxfinite`, `maxabsfinite`, `minfinite`, `meanfinite`, `sad`, `ssd`, `integral_image`
- Resizing: `restrict`, `imresize` (not yet exported)
- Filtering: `imfilter`, `imfilter_fft`, `imfilter_gaussian`, `imfilter_LoG`, `imROF`, `ncc`, `padarray`
- Filtering kernels: `ando[345]`, `guassian2d`, `imaverage`, `imdog`, `imlaplacian`, `prewitt`, `sobel`
Expand Down
21 changes: 21 additions & 0 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 @@ -1956,3 +1958,22 @@ function shepp_logan(M,N; highContrast=true)
end

shepp_logan(N;highContrast=true) = shepp_logan(N,N;highContrast=highContrast)

"""
```
integral_img = integral_image(img)
```
Returns the integral image of an image. The integral image is calculated by assigning
to each pixel the sum of all pixels above it and to its left, i.e. the rectangle from
(1, 1) to the pixel.
"""
function integral_image(img::AbstractArray)
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
13 changes: 13 additions & 0 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ facts("Algorithms") do

@fact Images.test_approx_eq_sigma_eps(a[:,1:end-1], a[1:end-1,:], [3,3], 0.1) --> less_than(0.1)
@fact_throws Images.test_approx_eq_sigma_eps(a[:,1:end-1], a[1:end-1,:], [3,3], 0.01)

a = zeros(10, 10)
int_img = integral_image(a)
@fact all(int_img == a) --> true

a = ones(10,10)
int_img = integral_image(a)
chk = Array(1:10)
@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)
@fact int_img[diagind(int_img)] == Array([1, 26, 108, 280, 575, 1026, 1666, 2528, 3645, 5050]) --> true
end

context("fft and ifft") do
Expand Down

0 comments on commit 919f480

Please sign in to comment.