question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: 3d examples for filters (e.g. `gaussian_filter`)

See original GitHub issue

Is 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:

https://user-images.githubusercontent.com/44469195/141647703-cf3c597c-e404-4fef-b746-495d59146685.mp4

Or as images image image

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kolibril13commented, Nov 13, 2021

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:

from scipy.ndimage import gaussian_filter
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)")
0reactions
tupuicommented, Nov 14, 2021

Sounds good!

I can refactor the code a bit and then make a pull request.

@tupui : Would you be willing to make some fine-tuning of the formatting and commit them directly to my soon coming pull request branch, so that my example is embedded nicely in the style of the docs?

Sure of course! Thanks for making a PR 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found