ENH: 3d examples for filters (e.g. `gaussian_filter`)
See original GitHub issueIs your feature request related to a problem? Please describe.
Right now, there are only 2D examples for Multidimensional filters, e.g. the Gaussian filter: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html
Describe the solution you’d like.
Provide also 3D examples. Toy examples in 3D will help to make the filter parameters easier to understand. I had the idea to use 3D voxel for that.
Describe alternatives you’ve considered.
No response
Additional context (e.g. screenshots, GIFs)
Either as animation:
Or as images
This is only a quick code draft for reproduction (not very pretty):
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
from scipy.ndimage import gaussian_filter
%config InlineBackend.figure_format = 'svg'
size= 10
x, y, z = np.indices((size*2, size*2, size*2))
o1,o2,o3 =(0,0,0)
cube1 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(size,0,0)
cube2 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(0,size,0)
cube3 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(size,size,0)
cube4 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(0,0,size)
cube5 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(size,0,size)
cube6 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(0,size,size)
cube7 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
o1,o2,o3 =(size,size,size)
cube8 = (o1 <= x) & (x < o1+size) & (o2 <= y) & (y < o2+size) & (o3 <= z) & (z < o3+size)
voxelarray = np.zeros(cube1.shape)
voxelarray[cube1]=1 * 255/8
voxelarray[cube2]=2 * 255/8
voxelarray[cube3]=3 * 255/8
voxelarray[cube4]=4 * 255/8
voxelarray[cube5]=5 * 255/8
voxelarray[cube6]=6 * 255/8
voxelarray[cube7]=7 * 255/8
voxelarray[cube8]=8 * 255/8
voxelarray = np.uint8(voxelarray)
cmap = plt.get_cmap('magma')
cols256=[]
for i in range(cmap.N):
rgb = cmap(i)[:3]
cols256.append(mpl.colors.rgb2hex(rgb))
def get_color(x):
return cols256[x]
get_color = np.vectorize(get_color)
colors = get_color(voxelarray)
def plot_voxels(varray,title):
colors = get_color(varray)
global ax
ax = plt.figure().add_subplot(projection='3d')
plt.axis('off')
ax.voxels(varray, facecolors=colors, edgecolor="#000000",linewidth=0.1)
ax.set_title(title)
plot_voxels(voxelarray,"Original")
voxelarray2=gaussian_filter(voxelarray, sigma=1)
plot_voxels(voxelarray2,"gaussian_filter(voxelarray, sigma=1)")
voxelarray2=gaussian_filter(voxelarray, sigma=3)
plot_voxels(voxelarray2,"gaussian_filter(voxelarray, sigma=3)")
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
3-D Gaussian filtering of 3-D images - MATLAB imgaussfilt3
This MATLAB function filters 3-D image A with a 3-D Gaussian smoothing kernel with standard deviation of 0.5, and returns the filtered image...
Read more >A fast Gaussian filtering algorithm for three - IOPscience
The 1-D Gaussian filter can be implemented approximately by the cascaded Butterworth filters. The approximation accuracy will be improved with the.
Read more >Bilateral Filter Lab - Brown CS
Gaussian Filter Background. The bilateral filter is a Gaussian that acts strongly on regions of uniform color, and lightly on regions with high...
Read more >Spatial Filters - Laplacian/Laplacian of Gaussian
= 3 pixels. By itself, the effect of the filter is to highlight edges in an image. For example,. wdg4. is a ...
Read more >Example Gaussian Filter - YouTube
This video is part of the Udacity course "Computational Photography". Watch the full course at https://www.udacity.com/course/ud955.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That would be possible. But should all the code be displayed? It is about 70 lines in total, but only these 6 lines are actually important to understand the gaussian_filter:
Sure of course! Thanks for making a PR 😃