Skip to content

WIP: replace Images with specific packages #105

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ version = "0.5.0"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageContrastAdjustment = "f332f351-ec65-5f6a-b3d1-319c6670881a"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageCorners = "89d5987c-236e-4e32-acd0-25bd6bd87b70"
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
IntegralArrays = "1d092043-8f09-5a30-832f-7509e371ab51"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Distributions = "0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
Images = "0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
ImageCore = "0.10"
julia = "1.6"

[extras]
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["ImageMagick", "LinearAlgebra", "Test", "TestImages"]
test = ["ImageIO", "LinearAlgebra", "Test", "TestImages"]
2 changes: 0 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ImageDraw = "4381153b-2b60-58ae-a1ba-fd683676385f"
ImageFeatures = "92ff4b2b-8094-53d3-b29d-97f740f06cef"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Documenter, ImageFeatures, Images
using Documenter, ImageFeatures, ImageCore

makedocs(sitename = "ImageFeatures",
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
Expand Down
1 change: 0 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ Installing the package is extremely easy with julia's package manager -
Pkg.add("ImageFeatures")
```

ImageFeatures.jl requires [Images.jl](https://github.com/JuliaImages/Images.jl).
4 changes: 2 additions & 2 deletions docs/src/tutorials/brief.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ BRIEF is a very simple feature descriptor and does not provide scale or rotation

## Example

Let us take a look at a simple example where the BRIEF descriptor is used to match two images where one has been translated by `(100, 200)` pixels. We will use the `lena_gray` image from the [TestImages](https://github.com/timholy/TestImages.jl) package for this example.
Let us take a look at a simple example where the BRIEF descriptor is used to match two images where one has been translated by `(100, 200)` pixels. We will use the `lena_gray` image from the [TestImages](https://github.com/JuliaImages/TestImages.jl) package for this example.


Now, let us create the two images we will match using BRIEF.

```@example 1
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations
using ImageFeatures, TestImages, ImageCore, ImageDraw, CoordinateTransformations

img = testimage("lighthouse")
img1 = Gray.(img)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/brisk.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ The descriptor is built using intensity comparisons. For each short pair if the

## Example

Let us take a look at a simple example where the BRISK descriptor is used to match two images where one has been translated by `(50, 40)` pixels and then rotated by an angle of 75 degrees. We will use the `lighthouse` image from the [TestImages](https://github.com/timholy/TestImages.jl) package for this example.
Let us take a look at a simple example where the BRISK descriptor is used to match two images where one has been translated by `(50, 40)` pixels and then rotated by an angle of 75 degrees. We will use the `lighthouse` image from the [TestImages](https://github.com/JuliaImages/TestImages.jl) package for this example.

First, let us create the two images we will match using BRISK.

```@example 4
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations, Rotations
using ImageFeatures, TestImages, ImageCore, ImageDraw, CoordinateTransformations, Rotations

img = testimage("lighthouse")
img1 = Gray.(img)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/freak.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ The descriptor is built using intensity comparisons of a predetermined set of 51

## Example

Let us take a look at a simple example where the FREAK descriptor is used to match two images where one has been translated by `(50, 40)` pixels and then rotated by an angle of 75 degrees. We will use the `lighthouse` image from the [TestImages](https://github.com/timholy/TestImages.jl) package for this example.
Let us take a look at a simple example where the FREAK descriptor is used to match two images where one has been translated by `(50, 40)` pixels and then rotated by an angle of 75 degrees. We will use the `lighthouse` image from the [TestImages](https://github.com/JuliaImages/TestImages.jl) package for this example.

First, let us create the two images we will match using FREAK.

```@example 3
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations, Rotations
using ImageFeatures, TestImages, ImageCore, ImageDraw, CoordinateTransformations, Rotations

img = testimage("lighthouse")
img1 = Gray.(img)
Expand Down
10 changes: 5 additions & 5 deletions docs/src/tutorials/object_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ representation which is invariant to local geometric and photometric changes (i.
Download the script to get the training data [here](https://drive.google.com/file/d/11G_9zh9N-0veQ2EL5WDGsnxRpihsqLX5/view?usp=sharing). Download tutorial.zip, decompress it and run get_data.bash. (Change the variable `path_to_tutorial` in preprocess.jl and path to julia executable in get_data.bash). This script will download the required datasets. We will start by loading the data and computing HOG features of all the images.

```julia
using Images, ImageFeatures
using ImageCore, ImageFeatures

path_to_tutorial = "" # specify this path
pos_examples = "$path_to_tutorial/tutorial/humans/"
neg_examples = "$path_to_tutorial/tutorial/not_humans/"

n_pos = length(readdir(pos_examples)) # number of positive training examples
n_neg = length(readdir(neg_examples)) # number of negative training examples
n = n_pos + n_neg # number of training examples
data = Array{Float64}(undef, 3780, n) # Array to store HOG descriptor of each image. Each image in our training data has size 128x64 and so has a 3780 length
n = n_pos + n_neg # number of training examples
data = Array{Float64}(undef, 3780, n) # Array to store HOG descriptor of each image. Each image in our training data has size 128x64 and so has a 3780 length
labels = Vector{Int}(undef, n) # Vector to store label (1=human, 0=not human) of each image.

for (i, file) in enumerate([readdir(pos_examples); readdir(neg_examples)])
Expand All @@ -31,7 +31,7 @@ for (i, file) in enumerate([readdir(pos_examples); readdir(neg_examples)])
end
```

Basically we now have an encoded version of images in our training data. This encoding captures useful information but discards extraneous information
Basically we now have an encoded version of images in our training data. This encoding captures useful information but discards extraneous information
(illumination changes, pose variations etc). We will train a linear SVM on this data.

```julia
Expand Down Expand Up @@ -94,7 +94,7 @@ end

![Original](../img/scores.png)

You can see that classifier gave low score to not-human class (i.e. high score to human class) at positions corresponding to humans in the original image.
You can see that classifier gave low score to not-human class (i.e. high score to human class) at positions corresponding to humans in the original image.
Below we threshold the image and supress non-minimal values to get the human locations. We then plot the bounding boxes using `ImageDraw`.

```julia
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/orb.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Let us take a look at a simple example where the ORB descriptor is used to match
First, let us create the two images we will match using ORB.

```@example 2
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations, Rotations
using ImageFeatures, TestImages, ImageCore, ImageDraw, CoordinateTransformations, Rotations

img = testimage("lighthouse")
img1 = Gray.(img)
Expand Down
12 changes: 10 additions & 2 deletions src/ImageFeatures.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
module ImageFeatures

# package code goes here
using Images, Distributions
using ImageCore
using ImageCore: NumberLike
using ImageBase
using ImageTransformations # imresize
using ImageCorners
using ImageFiltering
using ImageContrastAdjustment # build_histogram
using IntegralArrays
using Distributions
using SparseArrays
import Random.seed!
using Images.ImageTransformations.Interpolations
using ImageTransformations.Interpolations

include("core.jl")
include("const.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/hog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function HOG(; orientations::Int = 9, cell_size::Int = 8, block_size::Int = 2, b
HOG(orientations, cell_size, block_size, block_stride, norm_method)
end

function create_descriptor(img::AbstractArray{CT, 2}, params::HOG) where CT<:Images.NumberLike
function create_descriptor(img::AbstractArray{CT, 2}, params::HOG) where CT<:NumberLike
#compute gradient
gx = imfilter(img, centered([-1 0 1]))
gy = imfilter(img, centered([-1 0 1]'))
Expand All @@ -34,7 +34,7 @@ function create_descriptor(img::AbstractArray{CT, 2}, params::HOG) where CT<:Ima
create_hog_descriptor(mag, phase, params)
end

function create_descriptor(img::AbstractArray{CT, 2}, params::HOG) where CT<:Images.Color{T, N} where T where N
function create_descriptor(img::AbstractArray{CT, 2}, params::HOG) where CT<:Color{T, N} where T where N
#for color images, compute seperate gradient for each color channel and take one with largest norm as pixel's gradient vector
rows, cols = size(img)
gx = channelview(imfilter(img, centered([-1 0 1])))
Expand All @@ -56,7 +56,7 @@ function create_descriptor(img::AbstractArray{CT, 2}, params::HOG) where CT<:Ima
create_hog_descriptor(max_mag, max_phase, params)
end

function create_hog_descriptor(mag::AbstractArray{T, 2}, phase::AbstractArray{T, 2}, params::HOG) where T<:Images.NumberLike
function create_hog_descriptor(mag::AbstractArray{T, 2}, phase::AbstractArray{T, 2}, params::HOG) where T<:NumberLike
orientations = params.orientations
cell_size = params.cell_size
block_size = params.block_size
Expand Down
4 changes: 1 addition & 3 deletions src/houghtransform.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Images

"""
```
lines = hough_transform_standard(
Expand Down Expand Up @@ -133,7 +131,7 @@ Parameters:
# Example

```julia
julia> using Images, ImageFeatures, FileIO, ImageView
julia> using ImageCore, ImageFeatures, FileIO, ImageView

julia> img = load(download("http://docs.opencv.org/3.1.0/water_coins.jpg"));

Expand Down
2 changes: 1 addition & 1 deletion src/lbp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ function create_descriptor(img::AbstractArray{Gray{T}, 2}, yblocks::Integer = 4,
y_padded = ceil(Int, h / (yblocks)) * yblocks
x_padded = ceil(Int, w / (xblocks)) * xblocks

img_padded = Images.imresize(img, (y_padded, x_padded))
img_padded = imresize(img, (y_padded, x_padded))
_create_descriptor(img_padded, yblocks, xblocks, lbp_type, args...)
end
2 changes: 1 addition & 1 deletion test/brief.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images, TestImages, Distributions
using Test, ImageFeatures, ImageCore, TestImages, Distributions

@testset "Generating brief params" begin
brief_params = BRIEF(size = 8, window = 3, seed = 123)
Expand Down
2 changes: 1 addition & 1 deletion test/brisk.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images, TestImages, Distributions
using Test, ImageFeatures, ImageCore, TestImages, Distributions

@testset "Testing brisk params" begin
brisk_params = BRISK(pattern_scale = 2.0)
Expand Down
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images
using Test, ImageFeatures, ImageCore

@testset "Types" begin
img = zeros(10, 10)
Expand Down
2 changes: 1 addition & 1 deletion test/corner.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images
using Test, ImageFeatures, ImageCore

@testset "Orientations" begin
img = zeros(20, 20)
Expand Down
2 changes: 1 addition & 1 deletion test/freak.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images, TestImages, Distributions
using Test, ImageFeatures, ImageCore, TestImages, Distributions

@testset "Test freak params" begin
freak_params = FREAK(pattern_scale = 20.0)
Expand Down
2 changes: 1 addition & 1 deletion test/glcm.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images
using Test, ImageFeatures, ImageCore, ImageBase

@testset "GLCM" begin
img = [ 0 0 1 1
Expand Down
2 changes: 1 addition & 1 deletion test/hog.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images
using Test, ImageFeatures, ImageCore
import ImageFeatures.trilinear_interpolate!

@testset "HOG Feature" begin
Expand Down
4 changes: 2 additions & 2 deletions test/lbp.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images
using Test, ImageFeatures, ImageCore

@testset "circular_offsets" begin
img = [ 0x4c 0x19 0xac 0x2e 0x8c 0xcc 0x96 0x4c 0xdb 0x4f
Expand All @@ -13,7 +13,7 @@ using Test, ImageFeatures, Images
0x1a 0xe0 0x52 0x5a 0x6a 0x03 0xe8 0xcb 0x95 0xfc
]

global img_gray = map(i -> Images.Gray(reinterpret(N0f8, i)), img)
global img_gray = map(i -> Gray(reinterpret(N0f8, i)), img)
end

@test ImageFeatures.circular_offsets(8, 1) == [ (-0.0,1.0), (-0.70711,0.70711), (-1.0,0.0), (-0.70711,-0.70711), (-0.0,-1.0), (0.70711,-0.70711), (1.0,-0.0), (0.70711,0.70711)]
Expand Down
2 changes: 1 addition & 1 deletion test/orb.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, ImageFeatures, Images, TestImages, Distributions
using Test, ImageFeatures, ImageCore, TestImages, Distributions

@testset "Testing ORB params" begin
orb_params = ORB(num_keypoints = 1000, threshold = 0.2)
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module ImageFeatureTests

using ImageFeatures, Images, TestImages, Distributions
using ImageFeatures, ImageCore, ImageTransformations, ImageCorners, ImageFiltering, TestImages, Distributions
using Test
using LinearAlgebra
import Random.seed!
using Images.ImageTransformations: imrotate

function check_samples(sample_one, sample_two, size::Int, window::Int)
check_bool = true
Expand Down