In [1]:
%matplotlib inline 

import numpy as np
from scipy.misc import imread

from plt_utils import * # see https://github.com/bbabenko/plt_utils
from image_utils import *

Load and display images


In [2]:
# img = np.array(data.lena()).astype('uint8')
duck_img = imread('ducks.jpg')
synth_img = np.reshape(np.arange(20), (4,5)).astype('float32')

In [3]:
imshow(synth_img)



In [4]:
imshow(duck_img)


Gaussian blur

The method gblur is a convenience wrapper around cv2.GaussianBlur.


In [5]:
imshow(gblur(duck_img, 5))



In [6]:
imshow(gblur(duck_img.mean(-1), 5))


RGB Convert

The method rgb_convert is a convenience wrapper around cv2.cvtColor.


In [7]:
plt.figure(figsize=(10,10))
imshow(rgb_convert(duck_img, colorspace=COLORSPACE.hsv), split=True)



In [8]:
plt.figure(figsize=(10,10))
imshow(rgb_convert(duck_img, colorspace=COLORSPACE.luv), split=True)



In [9]:
plt.figure(figsize=(10,10))
imshow(rgb_convert(duck_img, colorspace=COLORSPACE.gray)


  File "<ipython-input-9-abdbe4fb3a51>", line 2
    imshow(rgb_convert(duck_img, colorspace=COLORSPACE.gray)
                                                            ^
SyntaxError: invalid syntax

Pad and crop

Convenience wrapper around cv2.copyMakeBorder and a method to crop a patch from an image.


In [ ]:
imshow(pad(duck_img, (100,150), (200,350)))

In [10]:
imshow(pad(synth_img, (1,2), (2,1)))



In [11]:
cropped_duck = crop(duck_img, (-20, -30, 300, 300))
imshow(cropped_duck)



In [12]:
cropped_synth = crop(synth_img, (-2, -3, 5, 5))
imshow(cropped_synth)


Gradients


In [13]:
# create a circle image
from skimage.draw import circle
img = np.zeros((51, 51), dtype=np.uint8)
rr, cc = circle(25, 25, 20)
img[rr, cc] = 1

mag, orient = gradient(img)
imshow(img)
imshow(mag)
imshow(orient)


Resize

Convenience wrapper around cv2.resize.


In [14]:
imshow(resize(duck_img, 2000, 1000))
imshow(resize(duck_img, 50, 100))
imshow(resize(duck_img.transpose(1,0,2), 100, 50))
imshow(resize(duck_img.transpose(1,0,2), 50, 100))
imshow(resize(duck_img, 100, 50, keep_aspect_ratio=False))
imshow(resize(duck_img, 50, 100, keep_aspect_ratio=False))