Skip to content

Commit

Permalink
Update to newer version of Images (#40)
Browse files Browse the repository at this point in the history
Closes #39

Now requires julia 1.6+
  • Loading branch information
timholy authored Nov 3, 2023
1 parent f171b26 commit f9c0468
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}-
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/haar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))[:]
Expand Down
40 changes: 21 additions & 19 deletions src/lucas_kanade.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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])
Expand Down Expand Up @@ -158,27 +159,28 @@ 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

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(
Expand Down
2 changes: 1 addition & 1 deletion test/haar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

2 comments on commit f9c0468

@timholy
Copy link
Member Author

@timholy timholy commented on f9c0468 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94707

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" f9c0468ce2a48f347a6892e9c62cc6cf7fa68ac3
git push origin v0.3.0

Please sign in to comment.