Save Ipython notebook as script with the same filename

# creating a variable theNotebook with the name of notebook
# source: http://stackoverflow.com/a/23619544
# In[1]:

%%javascript
var kernel = IPython.notebook.kernel;
var thename = window.document.getElementById("notebook_name").innerHTML;
var command = "theNotebook = " + "'"+thename+"'";
kernel.execute(command);

# saving to a directory 'backup'. create the directory if it doesn't exist
# source http://stackoverflow.com/a/19067979
# In[2]:

try :
    if(__IPYTHON__) :
        print "saving", theNotebook
        import os
        dir_backup = 'backup'
        if not os.path.exists(dir_backup):
            os.makedirs(dir_backup)
        get_ipython().system(u'ipython nbconvert --to python {0} --output {1}'.format(theNotebook, os.path.join(dir_backup, theNotebook)) )
except NameError :
    print "Unable to save"

Python equivalent of interp2

I wrote python version of  interp2(z, xi, yi,'linear') from matlab

https://github.com/serge-m/pyinterp2

Simple occlusion filling for depth maps

As an example I use images from middleburry.
Solution is very dirty and slow.


https://github.com/serge-m/depth_map_occlusion

# In[1]:

import numpy
import scipy
import matplotlib.pyplot as plt


# In[2]:

from scipy import ndimage
import numpy as np

# kernels for shift
k = np.array([
[[0,0,0],
 [0,0,1],
 [0,0,0],],
[[0,1,0],
 [0,0,0],
 [0,0,0],],
[[0,0,0],
 [1,0,0],
 [0,0,0],],
[[0,0,0],
 [0,0,0],
 [0,1,0],],
[[1,0,0],
 [0,0,0],
 [0,0,0],],
[[0,0,1],
 [0,0,0],
 [0,0,0],],
[[0,0,0],
 [0,0,0],
 [0,0,1],],
[[0,0,0],
 [0,0,0],
 [1,0,0],],
])