<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Image Processing notes
A short collection of useful Python image processing notes.
Step1:  Median filtering
Below I demonstrate the differences between the median filter implementations of skimage and ndimage.
Step2:  It looks like skimage's median filter is only good for uint8 data types. If its a float it will be downgraded to uint8 and if its uint16 its really, really, slow.
<ASSISTANT_TASK:>
Python Code:
%pylab inline
from scipy import ndimage
from skimage import filters, data
import skimage as ski
Explanation: Image Processing notes
A short collection of useful Python image processing notes.
End of explanation
myData = uint16(ski.exposure.rescale_intensity(ski.color.rgb2gray(data.lena()),out_range='uint16'))
matshow(myData, cmap = 'gray')
#float64 images
myData = ski.color.rgb2gray(data.lena())
ski_mf_data = filters.median(myData,uint8(ones((10,10))))
nd_mf_data = ndimage.median_filter(myData,10)
fig, ax = subplots(1,2,squeeze=True)
ax[0].matshow(ski_mf_data,cmap='gray')
ax[1].matshow(nd_mf_data,cmap='gray')
fig.tight_layout()
print(ski_mf_data.dtype)
print(nd_mf_data.dtype)
#16 bit images
myData = uint16(ski.exposure.rescale_intensity(ski.color.rgb2gray(data.lena()),out_range='uint16'))
ski_mf_data = filters.median(myData,uint8(ones((10,10))))
nd_mf_data = ndimage.median_filter(myData,10)
fig, ax = subplots(1,2,squeeze=True)
ax[0].matshow(ski_mf_data,cmap='gray')
ax[1].matshow(nd_mf_data,cmap='gray')
fig.tight_layout()
print(ski_mf_data.dtype)
print(nd_mf_data.dtype)
#8 bit images
myData = uint8(ski.exposure.rescale_intensity(ski.color.rgb2gray(data.lena()),out_range='uint8'))
ski_mf_data = filters.median(myData,uint8(ones((10,10))))
nd_mf_data = ndimage.median_filter(myData,10)
fig, ax = subplots(1,2,squeeze=True)
ax[0].matshow(ski_mf_data,cmap='gray')
ax[1].matshow(nd_mf_data,cmap='gray')
fig.tight_layout()
print(ski_mf_data.dtype)
print(nd_mf_data.dtype)
#float64
myData = ski.color.rgb2gray(data.lena())
%timeit filters.median(myData,ones((10,10)))
%timeit filters.rank.median(myData,ones((10,10)))
%timeit nd_mf_data = ndimage.median_filter(myData,10)
myData.dtype
#uint16
myData = uint16(ski.exposure.rescale_intensity(ski.color.rgb2gray(data.lena()),out_range='uint16'))
%timeit filters.median(myData,ones((10,10)))
%timeit filters.median(myData,uint8(ones((10,10))))
%timeit nd_mf_data = ndimage.median_filter(myData,10)
myData.dtype
#uint8
myData = uint8(ski.exposure.rescale_intensity(ski.color.rgb2gray(data.lena()),out_range='uint8'))
%timeit filters.median(myData,ones((10,10)))
%timeit filters.median(myData,uint8(ones((10,10))))
%timeit nd_mf_data = ndimage.median_filter(myData,10)
myData.dtype
Explanation: Median filtering
Below I demonstrate the differences between the median filter implementations of skimage and ndimage.
End of explanation
#take a look at the difference
matshow(ski_mf_data*1.0-1.0*nd_mf_data)
colorbar()
#The edges are different between the two methods. I don't really know why...
matshow((ski_mf_data*1.0-1.0*nd_mf_data)[0:15,0:15])
colorbar()
matshow((ski_mf_data*1.0-1.0*nd_mf_data)[-16:-1,0:15])
colorbar()
matshow((ski_mf_data*1.0-1.0*nd_mf_data)[0:15,-16:-1])
colorbar()
matshow((ski_mf_data*1.0-1.0*nd_mf_data)[-16:-1,-16:-1])
colorbar()
Explanation: It looks like skimage's median filter is only good for uint8 data types. If its a float it will be downgraded to uint8 and if its uint16 its really, really, slow.
End of explanation
<END_TASK>