You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What spatial frequencies is the steerable pyramid sensitive to?
#323
I've had two people recently (@kbonnen and @JiyeongHa) ask me how to determine which spatial frequencies the steerable pyramid are sensitive to, in reasonable units. Right now, there's not a super straightforward way to determine that info, but the following script is an empirical way of doing so, inspired by an example in the pyrtools docs:
importtorchimportplenopticaspoimportmatplotlib.pyplotaspltimporteinopsorder=3height=4imsize=512pyr=po.simul.SteerablePyramidFreq(height=height, image_shape=[imsize, imsize], order=order)
empty_image=torch.zeros((1, 1, imsize, imsize))
pyr_coeffs=pyr.forward(empty_image)
# insert a 1 in the center of each coefficient...fork, vinpyr.pyr_size.items():
mid= (v[0] //2, v[1] //2)
pyr_coeffs[k][0, 0, mid[0], mid[1]] =1# ... and then reconstruct this dummy image to visualize the filter.reconList= []
forkinpyr_coeffs:
# we ignore the residual_highpass and residual_lowpass, since we're focusing on the# filters hereifisinstance(k, tuple):
filt=pyr.recon_pyr(pyr_coeffs, [k[0]], [k[1]])
filt_fourier=torch.fft.fftshift(torch.fft.fft2(filt).abs())
reconList.append(filt_fourier)
# visualize fourier representation of filterspo.imshow(reconList, col_wrap=order+1, vrange="indep1", zoom=2)
plt.savefig("filters.png")
plt.close()
# arrange them into a nicer shapefourier_filts=einops.pack(reconList, "* c h w")[0]
fourier_filts=einops.rearrange(fourier_filts, "(scales ori) c h w -> scales (ori c) h w",
scales=pyr.num_scales)
# sum across orientationsfourier_filts=fourier_filts.sum(1, keepdim=True)
po.imshow(fourier_filts)
plt.savefig("all_orientations.png")
plt.close()
# compute radial averagepolar_rad=po.tools.polar_radius(fourier_filts.shape[-2:]).to(torch.int)
nr=torch.bincount(polar_rad.ravel())
# convert to integers so we can use bincount. amplitudes are irrelevnatfourier_filts= (255*fourier_filts/fourier_filts.max()).to(torch.int)
radial_avg= []
forscinrange(height):
tbin=torch.bincount(polar_rad.ravel(), fourier_filts[sc, 0].ravel())
radial_avg.append(tbin/nr)

radial_avg=torch.stack(radial_avg)
plt.plot(radial_avg.T)
plt.savefig('steerpyr_freqs.png')
That will create three images, filters.png:
This shows the energy, in frequency space, of the steerable pyramid filters. Each row shows a different scale and each column a different orientation. You can see that the orientations are just rotated copies of each other, and that the frequencies each scale is selective for decreases from coarse to fine as you go up.
all_orientations.png:
Summing across the orientations in the filters.png gives you the above plot, showing that each scale is an annulus, and they're just scaled copies of each other.
and steerpyr_freqs.png:
Taking a radial average of the info in all_orientations.png gives you the above plot, with frequencies (in cycles per image) on the x-axis, and arbitrary units on the y.
Deriving selectivity analytically
The steerable pyramid implementation in plenoptic is constructed in the frequency domain, so it should be possible to read this info directly out of the object itself. I am planning on refactoring the steerable pyramid at some point, and will make this info explicitly available at that point. If someone wants to get started before then, here are some pointers:
During initialization, a bunch of frequency-domain masks are created and cached, which are used during filtering.
During the forward pass, we take the Fourier transform of the input image, and progressively low-pass filter/downsample for each scale.
The actual filtering during the forward pass happens on this line, where lodft is the Fourier transformation of the image that is being progressively low-passed filtered and down-sampled on each scale, anglemask is the mask component that handles the different orientations (and so can be ignored for our case here), himask ignores all the highpass residuals, and complex_const can be ignored here as well.
For our purposes, the frequency (non-angle/orientation) selectivity comes from himask and lomask, which are created during initialization and cached in the _lomasks_scale_{i} and _himasks_scale_{i} attributes (one per scale). They are off by one, so that pyr._himasks_scale_0 should be multiplied by pyr.lo0mask, pyr_himasks_scale_1 should be multiplied by pyr._lomasks_scale_0 and so on. Unlike the fourier_filts variable created in the script above, these masks shrink in size with each scale, and so to get the actual frequencies, they need to be made back into images of the original size, by padding with zeros. When done correctly, the output should look a lot like the fourier_filts variable that has been summed across orientations.
Those two masks are created by using some raised cosines, which all have names like Ycosn, Xcosn, etc. To understand these will require digging back into the papers describing the steerable pyramid filter design. I believe the relevant paper is this one, but I'd start with Eero Simoncelli's notes and David Heeger's notes. My intuition is, from looking into the arguments passed to create the raised cosine variables, we should be able to derive the exact frequencies. The advantage of this is that the above method (and similar ones) will be sensitive to sampling, whereas the math will not.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I've had two people recently (@kbonnen and @JiyeongHa) ask me how to determine which spatial frequencies the steerable pyramid are sensitive to, in reasonable units. Right now, there's not a super straightforward way to determine that info, but the following script is an empirical way of doing so, inspired by an example in the pyrtools docs:
That will create three images,
filters.png:This shows the energy, in frequency space, of the steerable pyramid filters. Each row shows a different scale and each column a different orientation. You can see that the orientations are just rotated copies of each other, and that the frequencies each scale is selective for decreases from coarse to fine as you go up.
all_orientations.png:Summing across the orientations in the
filters.pnggives you the above plot, showing that each scale is an annulus, and they're just scaled copies of each other.and
steerpyr_freqs.png:Taking a radial average of the info in
all_orientations.pnggives you the above plot, with frequencies (in cycles per image) on the x-axis, and arbitrary units on the y.Deriving selectivity analytically
The steerable pyramid implementation in plenoptic is constructed in the frequency domain, so it should be possible to read this info directly out of the object itself. I am planning on refactoring the steerable pyramid at some point, and will make this info explicitly available at that point. If someone wants to get started before then, here are some pointers:
lodftis the Fourier transformation of the image that is being progressively low-passed filtered and down-sampled on each scale,anglemaskis the mask component that handles the different orientations (and so can be ignored for our case here),himaskignores all the highpass residuals, andcomplex_constcan be ignored here as well.himaskandlomask, which are created during initialization and cached in the_lomasks_scale_{i}and_himasks_scale_{i}attributes (one per scale). They are off by one, so thatpyr._himasks_scale_0should be multiplied bypyr.lo0mask,pyr_himasks_scale_1should be multiplied bypyr._lomasks_scale_0and so on. Unlike thefourier_filtsvariable created in the script above, these masks shrink in size with each scale, and so to get the actual frequencies, they need to be made back into images of the original size, by padding with zeros. When done correctly, the output should look a lot like thefourier_filtsvariable that has been summed across orientations.Ycosn,Xcosn, etc. To understand these will require digging back into the papers describing the steerable pyramid filter design. I believe the relevant paper is this one, but I'd start with Eero Simoncelli's notes and David Heeger's notes. My intuition is, from looking into the arguments passed to create the raised cosine variables, we should be able to derive the exact frequencies. The advantage of this is that the above method (and similar ones) will be sensitive to sampling, whereas the math will not.All reactions