|
290 | 290 | imgf = imfilter(img, Kernel.gaussian((3,3))) |
291 | 291 | @test axes(imgf) == axes(img) |
292 | 292 | end |
| 293 | + |
| 294 | + @testset "Planned FFT edge cases" begin |
| 295 | + # Test case 1: axes(result) != axes(A) but size(result) == size(A) |
| 296 | + A_offset = OffsetArray(rand(Float64, 6, 8), (-1, 1)) |
| 297 | + kernel = rand(Float64, 3, 3) |
| 298 | + planned_alg = planned_fft(A_offset, kernel, Fill(0.0)) |
| 299 | + result_planned = imfilter(A_offset, kernel, Fill(0.0), planned_alg) |
| 300 | + result_standard = imfilter(A_offset, kernel, Fill(0.0), Algorithm.FFT()) |
| 301 | + @test axes(result_planned) == axes(A_offset) |
| 302 | + @test result_planned ≈ result_standard |
| 303 | + |
| 304 | + # Test case 2: size(result) != size(A) - create artificial size mismatch |
| 305 | + A = rand(Float64, 7, 9) |
| 306 | + bord = Fill(0.0)(rand(3,5), A, Algorithm.FFT()) |
| 307 | + _A = ImageFiltering.padarray(Float64, A, bord) |
| 308 | + kern = ImageFiltering.samedims(_A, ImageFiltering.kernelconv(rand(3,5))) |
| 309 | + krn = FFTView(zeros(eltype(kern), map(length, axes(_A)))) |
| 310 | + |
| 311 | + # Create custom planned function that returns larger buffer |
| 312 | + original_irfft = ImageFiltering.buffered_planned_irfft(_A) |
| 313 | + custom_irfft = function(arr) |
| 314 | + result = original_irfft(arr) |
| 315 | + if size(result, 1) > 2 && size(result, 2) > 2 |
| 316 | + # Return buffer that's 1 larger in each dimension |
| 317 | + larger = zeros(eltype(result), size(result, 1) + 1, size(result, 2) + 1) |
| 318 | + larger[1:size(result,1), 1:size(result,2)] = result |
| 319 | + return larger |
| 320 | + end |
| 321 | + return result |
| 322 | + end |
| 323 | + |
| 324 | + result_custom = ImageFiltering.filtfft(_A, krn, |
| 325 | + ImageFiltering.buffered_planned_rfft(_A), |
| 326 | + ImageFiltering.buffered_planned_rfft(krn), |
| 327 | + custom_irfft) |
| 328 | + result_standard = ImageFiltering.filtfft(_A, krn) |
| 329 | + @test size(result_custom) == size(_A) |
| 330 | + @test result_custom ≈ result_standard |
| 331 | + end |
293 | 332 | end |
294 | 333 |
|
295 | 334 | @testset "Borders (issue #85)" begin |
|
0 commit comments