|
| 1 | +#!/usr/bin/env julia |
| 2 | + |
| 3 | +using ConvolutionalNeuralOperators: create_filter |
| 4 | +using CairoMakie |
| 5 | + |
| 6 | +# Test what happens with cutoff > 1 |
| 7 | +println("Testing sinc filter with cutoff > 1...") |
| 8 | + |
| 9 | +# Setup test parameters |
| 10 | +T = Float32 |
| 11 | +N = 64 |
| 12 | +grid = collect(0.0:(1.0/(N-1)):1.0) |
| 13 | + |
| 14 | +# Create a simple test image (checkerboard pattern) |
| 15 | +test_image = zeros(T, N, N, 1, 1) |
| 16 | +for i in 1:N, j in 1:N |
| 17 | + if ((i ÷ 8) + (j ÷ 8)) % 2 == 0 |
| 18 | + test_image[i, j, 1, 1] = 1.0 |
| 19 | + end |
| 20 | +end |
| 21 | + |
| 22 | +# Test different cutoff values including > 1 |
| 23 | +cutoff_values = [0.1, 0.5, 1.0, 2.0, 10.0, 100.0] |
| 24 | + |
| 25 | +fig = Figure(resolution = (1200, 400)) |
| 26 | + |
| 27 | +# Original image |
| 28 | +ax_orig = Axis(fig[1, 1], title = "Original") |
| 29 | +heatmap!(ax_orig, test_image[:, :, 1, 1]) |
| 30 | + |
| 31 | +for (i, cutoff) in enumerate(cutoff_values) |
| 32 | + println("Testing cutoff = $cutoff") |
| 33 | + |
| 34 | + # Create sinc filter with current cutoff |
| 35 | + filter = create_filter(T, grid, cutoff, filter_type = "sinc", force_cpu = true) |
| 36 | + |
| 37 | + # Apply filter |
| 38 | + filtered_image = filter(test_image) |
| 39 | + |
| 40 | + # Plot result |
| 41 | + ax = Axis(fig[1, i+1], title = "Cutoff = $cutoff") |
| 42 | + heatmap!(ax, filtered_image[:, :, 1, 1]) |
| 43 | +end |
| 44 | + |
| 45 | +# Save the comparison |
| 46 | +save("large_cutoff_test.png", fig) |
| 47 | +println("Saved comparison to large_cutoff_test.png") |
| 48 | + |
| 49 | +# Also check the frequency response by looking at the sinc function values |
| 50 | +println("\nSinc function behavior:") |
| 51 | +for cutoff in cutoff_values |
| 52 | + omega = cutoff * π |
| 53 | + # Check sinc values at a few sample points |
| 54 | + x_values = [0, 1, 2, 3] |
| 55 | + sinc_values = [sinc(x * omega) for x in x_values] |
| 56 | + println("Cutoff $cutoff (ω = $(omega/π)π): sinc values at x=[0,1,2,3] = $sinc_values") |
| 57 | +end |
0 commit comments