In [1]:
from wndcharm import diagnostics
print diagnostics
In [2]:
%matplotlib inline
In [3]:
import numpy as np
In [4]:
from skimage.io import imshow, imsave
In [5]:
from skimage.data import chelsea
In [6]:
imshow( chelsea())
Out[6]:
In [7]:
img = chelsea()
In [8]:
type( img)
Out[8]:
In [9]:
img.shape
Out[9]:
In [10]:
img.dtype
Out[10]:
In [11]:
for d, label in enumerate( ('r', 'g', 'b')):
plane = img[:,:,d]
print "{}: min={}, max={}".format( label, plane.min(), plane.max())
In [12]:
from skimage.color import rgb2gray
In [13]:
gray_img = rgb2gray( img)
In [14]:
gray_img.shape
Out[14]:
In [15]:
gray_img.dtype
Out[15]:
In [16]:
gray_img.min(), gray_img.max()
Out[16]:
In [17]:
gray_img = (gray_img * 255 ).astype( np.uint8 )
In [18]:
gray_img.dtype
Out[18]:
In [19]:
gray_img.min(), gray_img.max()
Out[19]:
In [20]:
imshow( gray_img)
Out[20]:
In [21]:
from wndcharm.PyImageMatrix import PyImageMatrix
In [22]:
matrix = PyImageMatrix()
matrix.allocate(gray_img.shape[1], gray_img.shape[0])
numpy_matrix = matrix.as_ndarray()
numpy_matrix[:] = gray_img
In [23]:
from wndcharm.FeatureVector import FeatureVector
In [24]:
fv = FeatureVector( name='FromNumpyMatrix', long=True, original_px_plane=matrix )
In [25]:
len( fv.values)
In [26]:
import time
In [27]:
t1 = time.time()
fv.GenerateFeatures(quiet=False, write_to_disk=True)
t2 = time.time()
print "Feat calc took {:0.2f} seconds.".format( t2-t1 )
In [28]:
fv.values
Out[28]:
In [29]:
len(fv.values)
Out[29]:
In [30]:
imsave( "chelsea_tiff.tiff", gray_img )
In [31]:
ls
In [32]:
!tiffinfo chelsea_tiff.tiff
In [33]:
tiff_fv = FeatureVector( name='FromTiff', long=True, source_filepath='chelsea_tiff.tiff' )
In [34]:
t1 = time.time()
tiff_fv.GenerateFeatures(quiet=False, write_to_disk=True)
t2 = time.time()
print "Feat calc took {:0.2f} seconds.".format( t2-t1 )
In [35]:
tiff_fv.values
Out[35]:
In [36]:
from wndcharm.utils import compare
In [37]:
compare( tiff_fv.values, fv.values )
Out[37]:
In [38]:
tiff_fv.values == fv.values
Out[38]:
In [39]:
all( tiff_fv.values == fv.values )
Out[39]: