From 3356c469f5663533ad77bb0f88604184c4dc8f98 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 22 Jul 2023 01:50:47 -0500 Subject: [PATCH] WIP: replace Images with specific packages Currently the bottleneck is `gaussian_pyramid` which is still in Images.jl --- Project.toml | 14 ++++++++++---- docs/Project.toml | 2 -- docs/make.jl | 2 +- docs/src/index.md | 1 - docs/src/tutorials/brief.md | 4 ++-- docs/src/tutorials/brisk.md | 4 ++-- docs/src/tutorials/freak.md | 4 ++-- docs/src/tutorials/object_detection.md | 10 +++++----- docs/src/tutorials/orb.md | 2 +- src/ImageFeatures.jl | 12 ++++++++++-- src/hog.jl | 6 +++--- src/houghtransform.jl | 4 +--- src/lbp.jl | 2 +- test/brief.jl | 2 +- test/brisk.jl | 2 +- test/core.jl | 2 +- test/corner.jl | 2 +- test/freak.jl | 2 +- test/glcm.jl | 2 +- test/hog.jl | 2 +- test/lbp.jl | 4 ++-- test/orb.jl | 2 +- test/runtests.jl | 3 +-- 23 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Project.toml b/Project.toml index 257f33a..8acfd8a 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/docs/Project.toml b/docs/Project.toml index f165446..a24ec1a 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -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" diff --git a/docs/make.jl b/docs/make.jl index 392f347..83c20dc 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,4 +1,4 @@ -using Documenter, ImageFeatures, Images +using Documenter, ImageFeatures, ImageCore makedocs(sitename = "ImageFeatures", format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"), diff --git a/docs/src/index.md b/docs/src/index.md index 87af206..4b5ef2d 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -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). diff --git a/docs/src/tutorials/brief.md b/docs/src/tutorials/brief.md index c7e39f0..258195c 100644 --- a/docs/src/tutorials/brief.md +++ b/docs/src/tutorials/brief.md @@ -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) diff --git a/docs/src/tutorials/brisk.md b/docs/src/tutorials/brisk.md index 8c90755..ce446f0 100644 --- a/docs/src/tutorials/brisk.md +++ b/docs/src/tutorials/brisk.md @@ -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) diff --git a/docs/src/tutorials/freak.md b/docs/src/tutorials/freak.md index 5d10583..6c55d86 100644 --- a/docs/src/tutorials/freak.md +++ b/docs/src/tutorials/freak.md @@ -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) diff --git a/docs/src/tutorials/object_detection.md b/docs/src/tutorials/object_detection.md index 9488cd6..f7c542d 100644 --- a/docs/src/tutorials/object_detection.md +++ b/docs/src/tutorials/object_detection.md @@ -11,7 +11,7 @@ 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/" @@ -19,8 +19,8 @@ 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)]) @@ -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 @@ -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 diff --git a/docs/src/tutorials/orb.md b/docs/src/tutorials/orb.md index 2f3ce88..19839c6 100644 --- a/docs/src/tutorials/orb.md +++ b/docs/src/tutorials/orb.md @@ -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) diff --git a/src/ImageFeatures.jl b/src/ImageFeatures.jl index 932ab5b..522a0cc 100644 --- a/src/ImageFeatures.jl +++ b/src/ImageFeatures.jl @@ -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") diff --git a/src/hog.jl b/src/hog.jl index 2db6302..6cb7cdf 100755 --- a/src/hog.jl +++ b/src/hog.jl @@ -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]')) @@ -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]))) @@ -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 diff --git a/src/houghtransform.jl b/src/houghtransform.jl index 8adda0f..ad56cf8 100644 --- a/src/houghtransform.jl +++ b/src/houghtransform.jl @@ -1,5 +1,3 @@ -using Images - """ ``` lines = hough_transform_standard( @@ -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")); diff --git a/src/lbp.jl b/src/lbp.jl index 3fea4be..163ca6d 100644 --- a/src/lbp.jl +++ b/src/lbp.jl @@ -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 diff --git a/test/brief.jl b/test/brief.jl index ce09a20..e2fd006 100644 --- a/test/brief.jl +++ b/test/brief.jl @@ -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) diff --git a/test/brisk.jl b/test/brisk.jl index 913be83..323b2a6 100644 --- a/test/brisk.jl +++ b/test/brisk.jl @@ -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) diff --git a/test/core.jl b/test/core.jl index ee7aa20..1bab9de 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1,4 +1,4 @@ -using Test, ImageFeatures, Images +using Test, ImageFeatures, ImageCore @testset "Types" begin img = zeros(10, 10) diff --git a/test/corner.jl b/test/corner.jl index 3635c9c..508b438 100644 --- a/test/corner.jl +++ b/test/corner.jl @@ -1,4 +1,4 @@ -using Test, ImageFeatures, Images +using Test, ImageFeatures, ImageCore @testset "Orientations" begin img = zeros(20, 20) diff --git a/test/freak.jl b/test/freak.jl index ed5f12c..d08b81b 100644 --- a/test/freak.jl +++ b/test/freak.jl @@ -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) diff --git a/test/glcm.jl b/test/glcm.jl index e76ccb6..ac14247 100644 --- a/test/glcm.jl +++ b/test/glcm.jl @@ -1,4 +1,4 @@ -using Test, ImageFeatures, Images +using Test, ImageFeatures, ImageCore, ImageBase @testset "GLCM" begin img = [ 0 0 1 1 diff --git a/test/hog.jl b/test/hog.jl index 7c830f8..68d6a9c 100644 --- a/test/hog.jl +++ b/test/hog.jl @@ -1,4 +1,4 @@ -using Test, ImageFeatures, Images +using Test, ImageFeatures, ImageCore import ImageFeatures.trilinear_interpolate! @testset "HOG Feature" begin diff --git a/test/lbp.jl b/test/lbp.jl index ac2290a..6b86548 100644 --- a/test/lbp.jl +++ b/test/lbp.jl @@ -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 @@ -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)] diff --git a/test/orb.jl b/test/orb.jl index d9d6fdf..3c1ad53 100644 --- a/test/orb.jl +++ b/test/orb.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 8513374..3582c16 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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