In [1]:
%load_ext autoreload
%autoreload 2

In [2]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os

%matplotlib inline

In [3]:
in_folder = '/home/ubuntu/dataset/train/'

names = []
for r, ds, fs in os.walk(in_folder):
    for f in fs:
        names.append(os.path.join(r, f))
        break

In [ ]:


In [ ]:
print names

In [5]:
from joblib import Parallel, delayed
from data_augmentation import data_augmentation
from utils import bbox, create_fixed_image_shape

In [87]:
from skimage.io import imread, imsave
from skimage import img_as_float, img_as_uint
from skimage.filters.rank import subtract_mean
from skimage.morphology import disk

In [6]:
temp_shape = (300, 300, 3)
out_shape = (256, 256, 3)

In [3]:
def proc(name, k):
    im = cv2.imread(name)
    im.resize(temp_shape)
    imgs = data_augmentation(im, frame_size=out_shape)
    for i, img in enumerate(imgs):
        new_name = name.replace('/train/', '/train_aug/')
        new_name = new_name.replace('.jpeg', '_%d.jpeg' % i)
        cv2.imwrite(new_name, img)
    if k % 10 == 0:
        print "Completed %d." % k

In [75]:
im = cv2.imread('/home/ubuntu/dataset/validation_bkp/4/14849_right.jpeg').astype(np.int16)
print im.dtype


int16

In [76]:
mean_im = np.mean(im ,axis=0).mean(axis=0)
print "The mean is [%.2f, %.2f, %.2f]" % (mean_im[0], mean_im[1], mean_im[2])


The mean is [70.33, 73.51, 75.20]

In [78]:
gray_im = cv2.cvtColor(cv2.medianBlur(im.astype(np.uint8), 15), cv2.COLOR_BGR2GRAY)
mask = (gray_im > 2).astype(np.uint8)

In [79]:
mean_im = np.array(cv2.mean(im, mask)[:-1])
mean_im = mean_im[np.newaxis, np.newaxis, :]

In [80]:
plt.imshow((im - mean_im)[:,:,::-1], cmap="jet");



In [ ]:
norm_img = subtract_mean(im, )

In [84]:
aa = skimage.img_as_uint((im - mean_im)[:,:,::-1])


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-84-fab8f3b589af> in <module>()
----> 1 aa = skimage.img_as_uint((im - mean_im)[:,:,::-1])

/usr/local/lib/python2.7/dist-packages/skimage/util/dtype.pyc in img_as_uint(image, force_copy)
    313 
    314     """
--> 315     return convert(image, np.uint16, force_copy)
    316 
    317 

/usr/local/lib/python2.7/dist-packages/skimage/util/dtype.pyc in convert(image, dtype, force_copy, uniform)
    193     if kind_in == 'f':
    194         if np.min(image) < -1.0 or np.max(image) > 1.0:
--> 195             raise ValueError("Images of type float must be between -1 and 1.")
    196         if kind == 'f':
    197             # floating point -> floating point

ValueError: Images of type float must be between -1 and 1.

In [85]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-85-fd55c74f9d36> in <module>()
----> 1 skimage.filters.rank

AttributeError: 'module' object has no attribute 'filters'

In [35]:
a = mean_im[np.newaxis, np.newaxis, :]
print a.shape


(1, 1, 3)

In [42]:
plt.imshow(bbox(im)[:,:,::-1])


Out[42]:
<matplotlib.image.AxesImage at 0x7f7054cf48d0>

In [31]:
br = 40
a = im[:,:,::-1].copy().astype(np.uint16) + br
a[a>255] = 255
a[im[:,:,::-1]==0] = 0
plt.imshow(a.astype(np.uint8));



In [5]:
from utils import create_fixed_image_shape
from utils import bbox
from data_augmentation import data_augmentation

imre = create_fixed_image_shape(bbox(im), temp_shape, random_fill=False, mode='fit')
imgs = data_augmentation(imre, frame_size=out_shape)


30
28

In [6]:
for i in range(len(imgs)):
    img = imgs[i]
    imgs.append(img[:,::-1,:])

In [7]:
for i in range(len(imgs)):
    plt.figure()
    plt.imshow(imgs[i][:,:,::-1]);



In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: