Skip to content

Commit 59d5bc8

Browse files
committed
add CUDA testset for Gabor and LogGabor
Currently we don't have very native CUDA support for these two kernels, so the test set mainly serves as "okay, we can convert the lazy kernel array to CuArray by following the steps in tests and then use GPU to do multiplication and fft"
1 parent 7f29c9e commit 59d5bc8

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

test/cuda/gaborkernels.jl

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@testset "GaborKernels" begin
2+
3+
@testset "Gabor" begin
4+
# Gray
5+
img = float32.(TestImages.shepp_logan(127))
6+
kern = Kernel.Gabor(size(img), 3.0f0, 0f0)
7+
img_freq = fft(channelview(img))
8+
kern_freq = ifftshift(fft(kern))
9+
out = abs.(ifft(img_freq .* kern_freq))
10+
11+
# TODO(johnnychen94): currently Gabor can't be converted to CuArray directly and thus
12+
# FFTW is applied in the CPU side.
13+
img_cu = CuArray(img)
14+
img_freq = fft(channelview(img_cu))
15+
kern_freq = CuArray(ifftshift(fft(kern)))
16+
out_cu = abs.(ifft(img_freq .* kern_freq))
17+
18+
@test out Array(out_cu)
19+
20+
# RGB
21+
img = float32.(testimage("monarch"))
22+
kern = Kernel.Gabor(size(img), 3.0f0, 0f0)
23+
kern_freq = reshape(ifftshift(fft(kern)), 1, size(kern)...)
24+
img_freq = fft(channelview(img), 2:3)
25+
out = colorview(RGB, abs.(ifft(img_freq .* kern_freq)))
26+
27+
img_cu = CuArray(img)
28+
kern_freq = CuArray(reshape(ifftshift(fft(kern)), 1, size(kern)...))
29+
img_freq = fft(channelview(img_cu), 2:3)
30+
out_cu = colorview(RGB, abs.(ifft(img_freq .* kern_freq)))
31+
32+
@test out Array(out_cu)
33+
end
34+
35+
@testset "LogGabor" begin
36+
# Gray
37+
img = float32.(TestImages.shepp_logan(127))
38+
kern = Kernel.LogGabor(size(img), 1.0f0/6, 0f0)
39+
kern_freq = OffsetArrays.no_offset_view(ifftshift(kern))
40+
img_freq = fft(channelview(img))
41+
out = abs.(ifft(kern_freq .* img_freq))
42+
43+
# TODO(johnnychen94): remove this no_offset_view wrapper
44+
img_cu = CuArray(img)
45+
kern_freq = CuArray(OffsetArrays.no_offset_view(ifftshift(kern)))
46+
img_freq = fft(channelview(img_cu))
47+
out_cu = abs.(ifft(kern_freq .* img_freq))
48+
49+
@test out Array(out_cu)
50+
51+
# RGB
52+
img = float32.(testimage("monarch"))
53+
kern = Kernel.LogGabor(size(img), 1.0f0/6, 0f0)
54+
kern_freq = reshape(ifftshift(kern), 1, size(kern)...)
55+
img_freq = fft(channelview(img), 2:3)
56+
out = colorview(RGB, abs.(ifft(img_freq .* kern_freq)))
57+
58+
img_cu = CuArray(img)
59+
kern_freq = CuArray(reshape(ifftshift(kern), 1, size(kern)...))
60+
img_freq = fft(channelview(img_cu), 2:3)
61+
out_cu = colorview(RGB, abs.(ifft(img_freq .* kern_freq)))
62+
63+
@test out Array(out_cu)
64+
end
65+
66+
end

test/cuda/runtests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ using ImageBase
77
using ImageQualityIndexes
88
using Test
99
using Random
10+
using FFTW
11+
using OffsetArrays
12+
using CUDA.Adapt
1013

1114
CUDA.allowscalar(false)
1215

1316
@testset "ImageFiltering" begin
1417
if CUDA.functional()
1518
include("models.jl")
19+
include("gaborkernels.jl")
1620
end
1721
end

0 commit comments

Comments
 (0)