In [1]:
%matplotlib inline

import cv2
import numpy as np
import os.path
import sklearn.linear_model
import sklearn.model_selection
import tabulate

from IPython.display import HTML, display
from matplotlib import pyplot as plt

# Set default figure size
plt.rcParams['figure.figsize'] = [30, 10]
plt.rcParams['font.size'] = 30
plt.rcParams['figure.facecolor'] = 'white'
plt.rcParams['lines.markersize'] = 20
plt.rcParams['lines.markeredgewidth'] = 4
In [2]:
def imread_color(filename):
    """Reads `filename` into a numpy array (channels: R, G, B)"""
    return cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2RGB)

def imread_gray(filename):
    return cv2.imread(filename, cv2.IMREAD_GRAYSCALE)

def imshow_color(ax, img):
    ax.imshow(img)
    
def imshow_gray(ax, img):
    ax.imshow(img, cmap='gray')
    
def get_patch(img, roi):
    return img[roi[0][1]:roi[1][1],roi[0][0]:roi[1][0]]

def draw_roi(img, roi, color=(255), thickness=3):
    cv2.rectangle(img, roi[0], roi[1], color, thickness)
In [3]:
blurry_roi = ((600, 600), (650, 650))
sharp_roi = ((620, 620), (670, 670))

blurry_img_color = imread_color('img/blurry/2020-02-09T17:54:08.347Z.jpg')
sharp_img_color  = imread_color('img/sharp/2020-02-09T17:53:50.500Z.jpg')

fig, axs = plt.subplots(1, 2, figsize=(30,30))

draw_roi(blurry_img_color, blurry_roi)
draw_roi(sharp_img_color, sharp_roi)

blurry_patch = get_patch(blurry_img_color, blurry_roi)
sharp_patch = get_patch(sharp_img_color, sharp_roi)

axs[0].set_title('Blurry')
imshow_gray(axs[0], blurry_img_color)
axs[1].set_title('Sharp')
imshow_gray(axs[1], sharp_img_color)