In [8]:
import os
import numpy as np
import cv2 
import matplotlib as mpl
from matplotlib import pyplot as plt
import tensorflow as tf
import sklearn as skl

In [2]:
FPATH =  "D:\\kaggle\\notMinst\\notMNIST_small"

In [9]:
import sklearn.multiclass as mc

In [67]:
labels = []
imgs = np.array()
for root, dirs, files in os.walk(FPATH):
    for file in files:
        labels.append(os.path.basename(root))
        imgs.append(cv2.imread(root+os.sep+file))

In [68]:
x  = np.array(imgs)

In [70]:
x.shape


Out[70]:
(18726,)

In [71]:
len(labels)


Out[71]:
18726

In [72]:
x.dtype


Out[72]:
dtype('O')

In [81]:
type(imgs)


Out[81]:
list

In [82]:
x = np.array(imgs, dtype=np.ndarray)

In [84]:
type(x)


Out[84]:
numpy.ndarray

In [85]:
x.shape


Out[85]:
(18726,)

In [87]:
type(x[0])


Out[87]:
numpy.ndarray

In [ ]:


In [ ]:


In [ ]:


In [77]:
x = np.arange(1,5)

In [78]:
type(x)


Out[78]:
numpy.ndarray

In [79]:
np.ndarray.ndim(len(imgs), imgs[0].shape)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-79-d887e94e4493> in <module>()
----> 1 np.ndarray.ndim(len(imgs), imgs[0].shape)

TypeError: 'getset_descriptor' object is not callable

In [80]:
imgs[0].shape


Out[80]:
(28, 28, 3)

In [ ]:


In [ ]:


In [75]:
len(imgs)


Out[75]:
18726

In [76]:
x.shape


Out[76]:
(18726,)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [33]:
fp = FPATH + os.sep + "A" + os.sep + "MDRiXzA4LnR0Zg==.png"
img = cv2.imread(fp)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
print(img.shape)
plt.imshow(img, cmap="gray")
plt.show()


(28, 28, 3)

In [35]:
plt.subplot(221)
plt.imshow(img[:,:,0], cmap="gray")
plt.subplot(222)
plt.imshow(img[:,:,1], cmap="gray")
plt.subplot(223)
plt.imshow(img[:,:,2], cmap="gray")
plt.subplot(224)
plt.imshow(img, cmap="gray")
plt.show()



In [36]:
plt.subplot(121)
plt.imshow(img2, cmap="gray")
plt.subplot(122)
plt.imshow(img2)
plt.show()



In [42]:
res = (img[:,:,2] == img[:,:,0])

In [43]:
res.shape


Out[43]:
(28, 28)

In [46]:
res.all(axis=1)


Out[46]:
array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,  True], dtype=bool)

In [49]:
print(res.max())
print(res.mean())
print(res.min())
print(res.std())


True
1.0
True
0.0

In [51]:
np.arange(1,5).std()


Out[51]:
1.1180339887498949

In [52]:
np.arange(1,5)


Out[52]:
array([1, 2, 3, 4])

In [53]:
import math

In [54]:
math.sqrt(1.25)


Out[54]:
1.118033988749895

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [45]:
help(res.all)


Help on built-in function all:

all(...) method of numpy.ndarray instance
    a.all(axis=None, out=None, keepdims=False)
    
    Returns True if all elements evaluate to True.
    
    Refer to `numpy.all` for full documentation.
    
    See Also
    --------
    numpy.all : equivalent function


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [30]:
help(plt.imshow)


Help on function imshow in module matplotlib.pyplot:

imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, hold=None, data=None, **kwargs)
    Display an image on the axes.
    
    Parameters
    ----------
    X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4)
        Display the image in `X` to current axes.  `X` may be an
        array or a PIL image. If `X` is an array, it
        can have the following shapes and types:
    
        - MxN -- values to be mapped (float or int)
        - MxNx3 -- RGB (float or uint8)
        - MxNx4 -- RGBA (float or uint8)
    
        The value for each component of MxNx3 and MxNx4 float arrays
        should be in the range 0.0 to 1.0. MxN arrays are mapped
        to colors based on the `norm` (mapping scalar to scalar)
        and the `cmap` (mapping the normed scalar to a color).
    
    cmap : `~matplotlib.colors.Colormap`, optional, default: None
        If None, default to rc `image.cmap` value. `cmap` is ignored
        if `X` is 3-D, directly specifying RGB(A) values.
    
    aspect : ['auto' | 'equal' | scalar], optional, default: None
        If 'auto', changes the image aspect ratio to match that of the
        axes.
    
        If 'equal', and `extent` is None, changes the axes aspect ratio to
        match that of the image. If `extent` is not `None`, the axes
        aspect ratio is changed to match that of the extent.
    
        If None, default to rc ``image.aspect`` value.
    
    interpolation : string, optional, default: None
        Acceptable values are 'none', 'nearest', 'bilinear', 'bicubic',
        'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',
        'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc',
        'lanczos'
    
        If `interpolation` is None, default to rc `image.interpolation`.
        See also the `filternorm` and `filterrad` parameters.
        If `interpolation` is 'none', then no interpolation is performed
        on the Agg, ps and pdf backends. Other backends will fall back to
        'nearest'.
    
    norm : `~matplotlib.colors.Normalize`, optional, default: None
        A `~matplotlib.colors.Normalize` instance is used to scale
        a 2-D float `X` input to the (0, 1) range for input to the
        `cmap`. If `norm` is None, use the default func:`normalize`.
        If `norm` is an instance of `~matplotlib.colors.NoNorm`,
        `X` must be an array of integers that index directly into
        the lookup table of the `cmap`.
    
    vmin, vmax : scalar, optional, default: None
        `vmin` and `vmax` are used in conjunction with norm to normalize
        luminance data.  Note if you pass a `norm` instance, your
        settings for `vmin` and `vmax` will be ignored.
    
    alpha : scalar, optional, default: None
        The alpha blending value, between 0 (transparent) and 1 (opaque)
    
    origin : ['upper' | 'lower'], optional, default: None
        Place the [0,0] index of the array in the upper left or lower left
        corner of the axes. If None, default to rc `image.origin`.
    
    extent : scalars (left, right, bottom, top), optional, default: None
        The location, in data-coordinates, of the lower-left and
        upper-right corners. If `None`, the image is positioned such that
        the pixel centers fall on zero-based (row, column) indices.
    
    shape : scalars (columns, rows), optional, default: None
        For raw buffer images
    
    filternorm : scalar, optional, default: 1
        A parameter for the antigrain image resize filter.  From the
        antigrain documentation, if `filternorm` = 1, the filter
        normalizes integer values and corrects the rounding errors. It
        doesn't do anything with the source floating point values, it
        corrects only integers according to the rule of 1.0 which means
        that any sum of pixel weights must be equal to 1.0.  So, the
        filter function must produce a graph of the proper shape.
    
    filterrad : scalar, optional, default: 4.0
        The filter radius for filters that have a radius parameter, i.e.
        when interpolation is one of: 'sinc', 'lanczos' or 'blackman'
    
    Returns
    -------
    image : `~matplotlib.image.AxesImage`
    
    Other Parameters
    ----------------
    **kwargs : `~matplotlib.artist.Artist` properties.
    
    See also
    --------
    matshow : Plot a matrix or an array as an image.
    
    Notes
    -----
    Unless *extent* is used, pixel centers will be located at integer
    coordinates. In other words: the origin will coincide with the center
    of pixel (0, 0).
    
    .. note::
        In addition to the above described arguments, this function can take a
        **data** keyword argument. If such a **data** argument is given, the
        following arguments are replaced by **data[<arg>]**:
    
        * All positional and all keyword arguments.


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [24]:
img.shape


Out[24]:
(28, 28, 3)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [18]:
help(cv2.imreadmulti)


Help on built-in function imreadmulti:

imreadmulti(...)
    imreadmulti(filename, mats[, flags]) -> retval
    .   @brief Loads a multi-page image from a file.
    .   
    .   The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects.
    .   @param filename Name of file to be loaded.
    .   @param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR.
    .   @param mats A vector of Mat objects holding each page, if more than one.
    .   @sa cv::imread


In [ ]:


In [ ]:


In [ ]: