|
| 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 |
0 commit comments