diff --git a/.github/workflows/UnitTest.yml b/.github/workflows/UnitTest.yml index 5235f9b..55a90fe 100644 --- a/.github/workflows/UnitTest.yml +++ b/.github/workflows/UnitTest.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - julia-version: ['1.0', '1', 'nightly'] + julia-version: ['1.6', '1', 'nightly'] os: [ubuntu-latest] arch: [x64] include: @@ -38,7 +38,7 @@ jobs: env: cache-name: cache-artifacts with: - path: ~/.julia/artifacts + path: ~/.julia/artifacts key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} restore-keys: | ${{ runner.os }}-test-${{ env.cache-name }}- diff --git a/Project.toml b/Project.toml index 914cbc2..d310f95 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ImageTracking" uuid = "7632190a-71f5-11e9-04ef-99e081817785" -version = "0.2.0" +version = "0.3.0" [deps] AxisAlgorithms = "13072b0f-2c55-5437-9ae7-d433b7a33950" @@ -14,10 +14,10 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] AxisAlgorithms = "0.3, 1" CoordinateTransformations = "0.5, 0.6" -Images = "0.18, 0.19, 0.20, 0.21, 0.22, 0.23" -Interpolations = "0.10, 0.11, 0.12, 0.13" +Images = "0.25, 0.26" +Interpolations = "0.10, 0.11, 0.12, 0.13, 0.14" StaticArrays = "0.10, 0.11, 0.12, 1" -julia = "1" +julia = "1.6" [extras] ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" diff --git a/src/haar.jl b/src/haar.jl index 8375859..3346375 100644 --- a/src/haar.jl +++ b/src/haar.jl @@ -170,7 +170,7 @@ M. Oren, C. Papageorgiou, P. Sinha, E. Osuna and T. Poggio, "Pedestrian detectio P. Viola and M. Jones, "Rapid object detection using a boosted cascade of simple features," Proceedings of the 2001 IEEE Computer Society Conference on Computer Vision and Pattern Recognition. CVPR 2001, 2001, pp. I-511-I-518 vol.1. """ -function haar_features(img::AbstractArray{T, 2}, top_left::Array{I, 1}, bottom_right::Array{I, 1}, feat::Symbol, coordinates = nothing) where {T <: Union{Real, Color}, I <: Int} +function haar_features(img::IntegralArray{T, 2}, top_left::Array{I, 1}, bottom_right::Array{I, 1}, feat::Symbol, coordinates = nothing) where {T <: Union{Real, Color}, I <: Int} check_coordinates(top_left, bottom_right) rectangular_feature_coordinates = check_feature_type(feat) @@ -198,7 +198,7 @@ function haar_features(img::AbstractArray{T, 2}, top_left::Array{I, 1}, bottom_r ybot = top_left[1] + a[j, 3] - 1 xtop = top_left[2] + a[j, 2] - 1 xbot = top_left[2] + a[j, 4] - 1 - rectangular_features[i,j] = boxdiff(img, ytop, xtop, ybot, xbot) + rectangular_features[i,j] = img[ytop .. ybot, xtop .. xbot] end end rectangular_feature_values = (sum(rectangular_features[:, 2:2:end], dims = 2) - sum(rectangular_features[:, 1:2:end], dims = 2))[:] diff --git a/src/lucas_kanade.jl b/src/lucas_kanade.jl index 6e9354c..25007cd 100644 --- a/src/lucas_kanade.jl +++ b/src/lucas_kanade.jl @@ -1,12 +1,12 @@ -struct LKPyramid - layers::Vector{Matrix{Gray{Float64}}} +struct LKPyramid{T, A<:AbstractMatrix{T}} + layers::Vector{A} - Iy::Union{Nothing, Vector{Matrix{Gray{Float64}}}} - Ix::Union{Nothing, Vector{Matrix{Gray{Float64}}}} + Iy::Union{Nothing, Vector{A}} + Ix::Union{Nothing, Vector{A}} - Iyy::Union{Nothing, Vector{Matrix{Gray{Float64}}}} - Ixx::Union{Nothing, Vector{Matrix{Gray{Float64}}}} - Iyx::Union{Nothing, Vector{Matrix{Gray{Float64}}}} + Iyy::Union{Nothing, Vector{IntegralArray{T, 2, A}}} + Ixx::Union{Nothing, Vector{IntegralArray{T, 2, A}}} + Iyx::Union{Nothing, Vector{IntegralArray{T, 2, A}}} end function LKPyramid(image, levels; downsample = 2, σ = 1.0, compute_gradients::Bool = true) @@ -15,14 +15,15 @@ function LKPyramid(image, levels; downsample = 2, σ = 1.0, compute_gradients::B return LKPyramid(pyramid, nothing, nothing, nothing, nothing, nothing) total_levels = levels + 1 - Iy = Vector{Matrix{Gray{Float64}}}(undef, total_levels) - Ix = Vector{Matrix{Gray{Float64}}}(undef, total_levels) + M = typeof(first(pyramid)) + Iy = Vector{M}(undef, total_levels) + Ix = Vector{M}(undef, total_levels) - Iyy = Vector{Matrix{Gray{Float64}}}(undef, total_levels) - Ixx = Vector{Matrix{Gray{Float64}}}(undef, total_levels) - Iyx = Vector{Matrix{Gray{Float64}}}(undef, total_levels) + Iyy = Vector{IntegralArray{eltype(M), 2, M}}(undef, total_levels) + Ixx = Vector{IntegralArray{eltype(M), 2, M}}(undef, total_levels) + Iyx = Vector{IntegralArray{eltype(M), 2, M}}(undef, total_levels) - filling = Fill(zero(eltype(pyramid[1]))) + filling = Fill(zero(eltype(M))) for (i, layer) in enumerate(pyramid) Iy[i], Ix[i] = imgradients(layer, KernelFactors.scharr, filling) Iyy[i], Ixx[i], Iyx[i] = compute_partial_derivatives(Iy[i], Ix[i]) @@ -158,15 +159,15 @@ function compute_partial_derivatives(Iy, Ix; σ = 4) squared .= Iy .* Iy imfilter!(filtered, squared, kernel_factors) - Iyy_integral_table = integral_image(filtered) + Iyy_integral_table = IntegralArray(filtered) squared .= Ix .* Ix imfilter!(filtered, squared, kernel_factors) - Ixx_integral_table = integral_image(filtered) + Ixx_integral_table = IntegralArray(filtered) squared .= Iy .* Ix imfilter!(filtered, squared, kernel_factors) - Iyx_integral_table = integral_image(filtered) + Iyx_integral_table = IntegralArray(filtered) Iyy_integral_table, Ixx_integral_table, Iyx_integral_table end @@ -174,11 +175,12 @@ end function _compute_spatial_gradient( grid, Iyy_integral, Iyx_integral, Ixx_integral, ) - sum_Iyy = boxdiff(Iyy_integral, grid[1], grid[2]) - sum_Ixx = boxdiff(Ixx_integral, grid[1], grid[2]) - sum_Iyx = boxdiff(Iyx_integral, grid[1], grid[2]) + sum_Iyy = Iyy_integral[makeiv(grid[1]), makeiv(grid[2])] + sum_Ixx = Ixx_integral[makeiv(grid[1]), makeiv(grid[2])] + sum_Iyx = Iyx_integral[makeiv(grid[1]), makeiv(grid[2])] SMatrix{2, 2, Float64}(sum_Iyy, sum_Iyx, sum_Iyx, sum_Ixx) end +makeiv(range::AbstractUnitRange) = first(range) .. last(range) function compute_spatial_gradient(pyramid::LKPyramid, grid, level) G = _compute_spatial_gradient( diff --git a/test/haar.jl b/test/haar.jl index dd1367a..a2aab9a 100644 --- a/test/haar.jl +++ b/test/haar.jl @@ -52,7 +52,7 @@ using Images, StaticArrays, LinearAlgebra # Simple Image haar_features img = Matrix(Diagonal([1,1,1,1,1])) - int_img = integral_image(img) + int_img = IntegralArray(img) test_features = haar_features(int_img, [2,2], [4,4], :x2) correct_features = [-1,0,0,-1,1,1,-1,0,0,1]