In [1]:
import cv2
import os

In [2]:
%pwd


Out[2]:
u'C:\\Users\\Wasit\\Documents\\GitHub_2017\\cs634\\2017\\cs634_project\\dataset'

In [3]:
for file in os.listdir("dog"):
    if file.endswith(".jpg"):
        pass
        #print(os.path.join("dog", file))

In [4]:
#dog\013d0b02-cd6e-4c91-9b12-6fdaf4f0d00e.jpg
img=cv2.imread(os.path.join("dog","013d0b02-cd6e-4c91-9b12-6fdaf4f0d00e.jpg"),0)

In [5]:
%matplotlib inline
from matplotlib import pyplot as plt

In [6]:
plt.imshow(img, cmap='gray')


Out[6]:
<matplotlib.image.AxesImage at 0x7cd0550>

In [7]:
h,w = img.shape

In [8]:
if w<h:
    margin=(h-w)//2
    croped=img[ margin:-margin, :]
else:
    margin=(w-h)//2
    croped=img[ :, margin:-margin]

In [9]:
plt.imshow(croped, cmap='gray')


Out[9]:
<matplotlib.image.AxesImage at 0x815e080>

In [10]:
croped.shape


Out[10]:
(376L, 375L)

In [11]:
resized=cv2.resize(croped, (28,28)) 
plt.imshow(resized, cmap='gray')


Out[11]:
<matplotlib.image.AxesImage at 0x82dd4a8>

In [15]:
import numpy as np
x=np.reshape(resized, newshape=(784))

In [16]:
x.shape


Out[16]:
(784L,)

In [17]:
x


Out[17]:
array([178, 181, 189, 170, 179, 174, 171, 177, 173, 174, 174, 178, 170,
       160, 170, 162, 173, 201, 212, 140,  52, 136, 148, 148, 181, 144,
       180, 215, 181, 174, 176, 180, 162, 159, 193, 155, 183, 153, 165,
       156, 153, 153, 167, 224, 228, 227, 214,  93, 111, 141, 157, 165,
       150, 143, 188, 191, 179, 171, 191, 185, 155, 130, 156, 193, 186,
       203, 158, 133, 251, 243, 248, 254, 225, 214, 181, 172, 114, 134,
       193, 156, 148, 208, 189, 193, 164, 189, 175, 179, 168, 154, 130,
       120, 108, 129, 221, 240, 249, 255, 255, 230, 232, 231, 186, 187,
       149, 161, 142, 156, 159, 197, 186, 190, 178, 168, 180, 173, 184,
       147, 113, 103, 145, 116, 217, 232, 243, 233, 255, 233, 214, 192,
       153, 164, 205, 156, 136, 216, 195, 195, 202, 184, 167, 166, 150,
       174, 180, 171, 172,  92, 131, 124, 222, 226, 242, 210, 238, 231,
       217, 114, 113,   4, 120, 189, 221, 200, 185, 194, 190, 196,  83,
       113, 159, 178, 175, 177, 182,  98, 102, 172, 219, 249, 235, 218,
       205, 245, 204, 123,   3,  14,  55, 123, 193, 203, 204, 190, 185,
       188, 198, 200, 174, 167, 181, 178, 222, 180, 109, 164, 215, 206,
         3, 162, 209, 252, 202, 199,  90,  33,  38,  71, 183, 187, 187,
       204, 188, 198, 181, 168, 177, 182, 187, 208, 232, 255, 253, 193,
       234, 132,  22,  57, 220, 254, 241, 233, 157, 110,  60,  73, 191,
       193, 189, 194, 203, 214, 163, 163, 179, 172, 164, 223, 255, 255,
       255, 254, 217, 211, 160, 177, 231, 255, 253, 234, 237, 143, 115,
        89, 180, 188, 173, 170, 194, 187, 183, 172, 176, 171, 178, 233,
       255, 255, 254, 251, 226, 210, 178, 211, 251, 255, 249, 210, 248,
       236, 142, 127, 197, 185, 190, 184, 187, 196, 169, 174, 183, 182,
       177, 255, 255, 255, 255, 255, 229, 219, 205, 234, 255, 255, 247,
       174, 209, 215, 197, 146, 183, 202, 181, 173, 186, 150, 195, 185,
       193, 180, 178, 255, 244, 249, 255, 255, 245, 243, 196, 210, 255,
       255, 170, 139,  68,  77, 145, 162, 157, 205, 171, 143, 168, 164,
       184, 201, 172, 167, 182, 255, 253, 255, 254, 255, 255, 248, 242,
       204, 231, 253,  92,   9,   1,   2, 101, 150, 172, 178, 173, 165,
       163, 154, 174, 169, 212, 194, 186, 254, 254, 255, 255, 255, 253,
       245, 237, 222, 221, 246, 189,   5,  17,  48,  83, 134, 163, 168,
       164, 167, 157, 160, 196, 171, 178, 190, 208, 253, 255, 255, 255,
       255, 255, 252, 241, 203, 167, 206, 206, 132,  69,  31, 128, 138,
       139, 158, 152, 156, 162, 157, 196, 217, 191, 187, 165, 253, 254,
       255, 255, 255, 255, 242, 235, 224, 149, 157, 129,  66, 152, 123,
       131, 127, 131, 156, 138, 147, 149, 164, 176, 176, 182, 143, 151,
       198, 255, 255, 253, 255, 254, 245, 237, 240, 191, 161, 158, 135,
       146, 135, 135, 137, 133, 121, 136, 140, 149, 148, 194, 155, 134,
       225, 219, 203, 229, 255, 251, 252, 254, 243, 216, 236, 200, 175,
       167, 158, 157, 148, 126, 106, 141, 115, 132, 143, 127, 159, 209,
       195, 223, 204, 199, 179, 184, 247, 248, 245, 243, 240, 222, 221,
       208, 189, 162, 156, 164, 125, 134, 126, 119, 132, 109, 116, 126,
       134, 139, 198, 199, 218, 197, 185, 182, 232, 254, 237, 237, 222,
       217, 208, 195, 193, 168, 150, 143, 139, 141, 112, 124, 123, 120,
       124, 129, 131, 185, 190, 200, 163, 196, 188, 201, 185, 255, 237,
       213, 221, 212, 173, 196, 168, 183, 167, 148, 140, 162, 105, 112,
       115, 120, 118, 131, 115, 198, 205, 198, 192, 201, 204, 161, 253,
       254, 180, 105, 181, 207, 174, 163, 151, 138, 159,  72, 175, 136,
       105, 111, 112, 106,  46, 132, 129, 194, 203, 199, 204, 216, 199,
       176, 255, 254, 184,  61,  84, 114,  99,  90,  84, 112,  93,  69,
        25,  76,  78,  92,  65, 103, 156, 107, 122, 193, 196, 205, 200,
       156, 207, 176, 207, 238, 129,  25,  82, 104,  64, 102,  75,  92,
        80,  72,  58,  50,  94, 100,  44,  90,  94, 112, 104, 185, 190,
       138, 149, 219, 189, 192, 176, 227,  27, 109, 125,  89, 171, 101,
        80,  98,  72,  72,  74,  69, 101,  84,  80, 100,  99, 110,  99,
       190, 154, 223, 185, 185, 186, 199, 162, 174, 150, 157, 130, 100,
       119,  99,  69,  94,  92,  63,  84,  91,  99, 107, 107, 105,  76,
       101, 106, 181, 221, 183, 176, 174, 185, 176, 193, 173, 166, 148,
       129, 127,  99,  66,  89, 101, 113, 109,  90, 105,  84, 104, 107,
        89,  88, 118, 102], dtype=uint8)

In [ ]: