image_output_1.png
import albumentations as A

import cv2

import matplotlib.pyplot as plt

import os

import random

import os
import random
from multiprocessing import Pool
import numpy as np
import cv2
import albumentations as A
import matplotlib.pyplot as plt
from tqdm import tqdm
INPUT_PATH = '../input/happy-whale-and-dolphin'
IMG_SIZE = 600

train_files = os.listdir(os.path.join(INPUT_PATH, 'train_images'))
test_files = os.listdir(os.path.join(INPUT_PATH, 'test_images'))
all_files = [os.path.join(INPUT_PATH, 'train_images', f) for f in train_files] + [os.path.join(INPUT_PATH, 'test_images', f) for f in test_files]
show_images = random.sample(all_files, 5)

def show_orig_norm_images(img_files, mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)):
    nrows, ncols = (len(img_files), 2)
    fig, ax = plt.subplots(nrows, ncols, figsize=(20, 31))
    for i in range(len(img_files)):
        img = cv2.imread(img_files[i])
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        norm_img = A.Normalize(mean=mean, std=std)(image=img)['image']
        ax[i, 0].grid(False)
        ax[i, 0].axis('off')
        ax[i, 0].title.set_text(f'{os.path.basename(img_files[i])}: original')
        ax[i, 0].imshow(img)
        ax[i, 1].grid(False)
        ax[i, 1].axis('off')
        ax[i, 1].title.set_text(f'{os.path.basename(img_files[i])}: normalized')
        ax[i, 1].imshow(norm_img)
    plt.tight_layout()
    plt.show()
show_orig_norm_images(show_images)