In [23]:
import numpy as np
import matplotlib.pyplot as plt
import skimage.morphology as morph
import skimage.io as imgio
%matplotlib inline

In [39]:
#a=plt.imread('/Users/data/WaterBB/water_sample_BB/water_bb_0000.tif')
a=imgio.imread('/Users/data/P08062_wood/raw_CCD/wood_0001.fits')
a=(a-a.min())/(a.max()-a.min())
plt.imshow(a)


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py in pil_to_ndarray(im, dtype, img_num)
     52         # this will raise an IOError if the file is not readable
---> 53         im.getdata()[0]
     54     except IOError as e:

~/anaconda3/lib/python3.6/site-packages/PIL/Image.py in getdata(self, band)
   1217 
-> 1218         self.load()
   1219         if band is not None:

~/anaconda3/lib/python3.6/site-packages/PIL/ImageFile.py in load(self)
    306         if loader is None:
--> 307             raise IOError("cannot find loader for this %s file" % self.format)
    308         image = loader.load(self)

OSError: cannot find loader for this FITS file

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-39-a617cc5c1b38> in <module>()
      1 #a=plt.imread('/Users/data/WaterBB/water_sample_BB/water_bb_0000.tif')
----> 2 a=imgio.imread('/Users/data/P08062_wood/raw_CCD/wood_0001.fits')
      3 a=(a-a.min())/(a.max()-a.min())
      4 plt.imshow(a)

~/anaconda3/lib/python3.6/site-packages/skimage/io/_io.py in imread(fname, as_grey, plugin, flatten, **plugin_args)
     59 
     60     with file_or_url_context(fname) as fname:
---> 61         img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
     62 
     63     if not hasattr(img, 'ndim'):

~/anaconda3/lib/python3.6/site-packages/skimage/io/manage_plugins.py in call_plugin(kind, *args, **kwargs)
    209                                (plugin, kind))
    210 
--> 211     return func(*args, **kwargs)
    212 
    213 

~/anaconda3/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py in imread(fname, dtype, img_num, **kwargs)
     35         with open(fname, 'rb') as f:
     36             im = Image.open(f)
---> 37             return pil_to_ndarray(im, dtype=dtype, img_num=img_num)
     38     else:
     39         im = Image.open(fname)

~/anaconda3/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py in pil_to_ndarray(im, dtype, img_num)
     59                          'Please see documentation at: %s'
     60                          % (im.filename, pillow_error_message, site))
---> 61         raise ValueError(error_message)
     62     frames = []
     63     grayscale = None

ValueError: Could not load "" 
Reason: "cannot find loader for this FITS file"
Please see documentation at: http://pillow.readthedocs.org/en/latest/installation.html#external-libraries

In [26]:
mask=np.copy(a)
maxval=mask.max();
mask[1:-2,1:-2]=maxval
plt.subplot(1,4,1); 
plt.plot(mask[:,0])
fh=morph.greyreconstruct.reconstruction(seed=mask,mask=a,method='erosion')
plt.subplot(1,4,2); 
plt.imshow(a)
plt.subplot(1,4,3)
plt.imshow(fh)
plt.subplot(1,4,4)
plt.imshow(a-fh)


Out[26]:
<matplotlib.image.AxesImage at 0x1c1fe87828>

In [36]:
mask=np.copy(a)
minval=mask.min();
mask[1:-2,1:-2]=minval
plt.figure(figsize=[15,8])
plt.subplot(1,4,1); 
plt.plot(mask[:,0])
fh=morph.greyreconstruct.reconstruction(seed=mask,mask=a,method='dilation')

plt.subplot(1,4,2); 
plt.imshow(a)
plt.subplot(1,4,3)
plt.imshow(fh)
plt.subplot(1,4,4)
peakdiff=a-fh
plt.imshow(peakdiff)


Out[36]:
<matplotlib.image.AxesImage at 0x1c48a32f98>

In [35]:
h,ax=np.histogram(peakdiff.ravel(),bins=1024)
plt.plot(ax[0:-1],h)


Out[35]:
[<matplotlib.lines.Line2D at 0x1c1f825400>]

In [80]:
y,x = np.mgrid[:20:0.5,:20:0.5]
bumps=np.sin(x)+np.sin(y)

In [81]:
h=0.3
seed=bumps-h
background = morph.greyreconstruct.reconstruction(seed,bumps)

In [82]:
plt.subplot(1,3,1)
plt.imshow(bumps)
plt.subplot(1,3,2)
plt.imshow(seed)
plt.subplot(1,3,3)
plt.imshow(bumps-background)


Out[82]:
<matplotlib.image.AxesImage at 0x1c2997f630>

In [ ]: