Moved code back from skimage