Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the demo examples working with Images 0.26. #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
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"
StaticArrays = "0.10, 0.11, 0.12, 1"
julia = "1"

[extras]
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Expand Down
3 changes: 1 addition & 2 deletions demo/demo_farneback.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ImageMagick
using Images, TestImages, StaticArrays, ImageTracking, ImageView, LinearAlgebra, CoordinateTransformations, Gtk.ShortNames
using Images, ImageTracking, ImageView, LinearAlgebra, CoordinateTransformations
#=Image Credit: C. Liu. Beyond Pixels: Exploring New Representations and
#Applications for Motion Analysis. Doctoral Thesis. Massachusetts Institute of
#Technology. May 2009. =#
Expand Down
6 changes: 3 additions & 3 deletions demo/demo_lucas_kanade.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Images, TestImages, StaticArrays, ImageTracking, ImageView, LinearAlgebra, CoordinateTransformations, Gtk.ShortNames
using Images, StaticArrays, ImageTracking, ImageView, LinearAlgebra, CoordinateTransformations
#=Image Credit: C. Liu. Beyond Pixels: Exploring New Representations and
#Applications for Motion Analysis. Doctoral Thesis. Massachusetts Institute of
#Technology. May 2009. =#
img1 = load("demo/table1.jpg")
img2 = load("demo/table2.jpg")
img1 = load("table1.jpg")
img2 = load("table2.jpg")

corners = imcorner(img1, method=shi_tomasi)
I = findall(!iszero, corners)
Expand Down
Binary file modified demo/optical_flow_farneback.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/lucas_kanade.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,74 @@
displacement, status
end

# TODO: Images.integral_image has been deprecated in favor of IntegralArrays.jl
# Included here to get this package working with newer versions of Images.jl
# Should this package use IntegralArrays.jl like the depreciation notes suggest?

accum(::Type{T}) where {T<:Integer} = Int
accum(::Type{Float32}) = Float32
accum(::Type{T}) where {T<:Real} = Float64
accum(::Type{Gray{T}}) where {T} = accum(T)

Check warning on line 159 in src/lucas_kanade.jl

View check run for this annotation

Codecov / codecov/patch

src/lucas_kanade.jl#L156-L159

Added lines #L156 - L159 were not covered by tests

"""
```
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. An integral image is a data structure which helps in efficient
calculation of sum of pixels in a rectangular subset of an image. See `boxdiff` for more
information.
"""
function integral_image(img::AbstractArray)
integral_img = Array{accum(eltype(img))}(undef, size(img))
sd = coords_spatial(img)
cumsum!(integral_img, img, dims=sd[1])
for i = 2:length(sd)
cumsum!(integral_img, integral_img, dims=sd[i])
end
integral_img
end

"""
```
sum = boxdiff(integral_image, ytop:ybot, xtop:xbot)
sum = boxdiff(integral_image, CartesianIndex(tl_y, tl_x), CartesianIndex(br_y, br_x))
sum = boxdiff(integral_image, tl_y, tl_x, br_y, br_x)
```

An integral image is a data structure which helps in efficient calculation of sum of pixels in
a rectangular subset of an image. It stores at each pixel the sum of all pixels above it and to
its left. The sum of a window in an image can be directly calculated using four array
references of the integral image, irrespective of the size of the window, given the `yrange` and
`xrange` of the window. Given an integral image -

A - - - - - - B -
- * * * * * * * -
- * * * * * * * -
- * * * * * * * -
- * * * * * * * -
- * * * * * * * -
C * * * * * * D -
- - - - - - - - -

The sum of pixels in the area denoted by * is given by S = D + A - B - C.
"""
boxdiff(int_img::AbstractArray{T, 2}, y::UnitRange, x::UnitRange) where {T} =
boxdiff(int_img, y.start, x.start, y.stop, x.stop)

boxdiff(int_img::AbstractArray{T, 2}, tl::CartesianIndex, br::CartesianIndex) where {T} =

Check warning on line 209 in src/lucas_kanade.jl

View check run for this annotation

Codecov / codecov/patch

src/lucas_kanade.jl#L209

Added line #L209 was not covered by tests
boxdiff(int_img, tl[1], tl[2], br[1], br[2])

function boxdiff(int_img::AbstractArray{T, 2}, tl_y::Integer, tl_x::Integer, br_y::Integer, br_x::Integer) where T
sum = int_img[br_y, br_x]
sum -= tl_x > 1 ? int_img[br_y, tl_x - 1] : zero(T)
sum -= tl_y > 1 ? int_img[tl_y - 1, br_x] : zero(T)
sum += tl_y > 1 && tl_x > 1 ? int_img[tl_y - 1, tl_x - 1] : zero(T)
sum
end

function compute_partial_derivatives(Iy, Ix; σ = 4)
kernel = KernelFactors.gaussian(σ)
kernel_factors = kernelfactors((kernel, kernel))
Expand Down
Loading