In [1]:
import os
from os import listdir
from os.path import isfile, join
import numpy as np
from matplotlib import pyplot as plt
import  cv2
%matplotlib inline
import scipy.misc

In [2]:
mask = plt.imread('/home/arvind/mask.jpg')
mypath = '/home/arvind/Desktop/Manatee_dataset/cleaned_data/train/'
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]

In [25]:
img = plt.imread(mypath+'../../sketches_train/U3821.jpg')
_img = np.invert(img)

In [27]:
plt.imshow(img)
print files[0]


op_U3821.jpg.tif

In [5]:
sizes = {(224, 224),(259, 594)}
masks = {}
for filen in files:
    img = plt.imread(mypath + filen)
    img = np.invert(img)
    img[img<100] = 0
    img[img>100] = 1
    
    #idx = np.where(img)[0:2] # Drop the color when finding edges
    #box = map(min,idx)[::-1] + map(max,idx)[::-1]
    #region = img[box[0]:0,box[1]:box[2]]
    if img.shape in sizes:
        if img.shape not in masks: 
            masks[img.shape] = img.astype('float32')
        masks[img.shape] = masks[img.shape] +  img

In [6]:
masks.keys()


Out[6]:
[(224, 224)]

In [8]:
img = plt.imread(mypath+files[0])

_img = np.invert(img)
print np.max(masks[(224,224)])
_img[masks[(224,224)]>1500] = 0
#_img[masks[(224,224)]>200] = 0.9
plt.imshow(_img)


85724.0
Out[8]:
<matplotlib.image.AxesImage at 0x7f41837a9ad0>

In [9]:
plt.imshow(img)


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

In [11]:
idx = np.where(img-255)[0:2] # Drop the color when finding edges
box = map(min,idx)[::-1] + map(max,idx)[::-1]
region = img[box[0]:box[3],box[1]:box[2]]
#region_pix = np.asarray(region)
plt.imshow(img)


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

In [ ]: