image_output_1.png
import cv2

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_df = pd.read_csv('../input/train.csv')
test_df = pd.read_csv('../input/test.csv')

def display_train_images(df, col=3, row=3):
    
    tol = 30  # initializing our tolerence level for cropping 

    matrix = col*row
    fig = plt.figure(figsize=(10, 10)) #definingthe size of our inline plot from matplotlib 
    
    for i in range(matrix):
        
        image_path = df.loc[i,'id_code']     # assigning the id_code of each eye image to a certain path
        image_id = df.loc[i,'diagnosis']
        
        image = cv2.imread(f'../input/train_images/{image_path}.png')
        
        img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # converting images from a RGB format to a grayscale format 
        
        mask = img>tol
        img = img[np.ix_(mask.any(1),mask.any(0))]       # converting the images into an adjusted or cropped image
        
        img = cv2.resize(img, (img_size, img_size))   # resizing our images all to a single size 
        
        img=cv2.addWeighted(img, 4, cv2.GaussianBlur(img, (0,0), img_size/10),-4, 128) # creating a guassian blur from the grayscale image 
        
        fig.add_subplot(row, col, i+1)
        
        plt.title(image_id)
        plt.axis('off')
        plt.imshow(img,cmap='gray')
        
    plt.tight_layout()

    return df

def display_test_images(df, col=3, row=3):
    
    tol = 30  # initializing our tolerence level for cropping 

    matrix = col*row
    fig = plt.figure(figsize=(10, 10)) #definingthe size of our inline plot from matplotlib 
    
    for i in range(matrix):
        
        image_path = df.loc[i,'id_code']     # assigning the id_code of each eye image to a certain path
        image = cv2.imread(f'../input/test_images/{image_path}.png')
        
        img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # converting images from a RGB format to a grayscale format 
        
        mask = img>tol
        img = img[np.ix_(mask.any(1),mask.any(0))]       # converting the images into an adjusted or cropped image
        
        img = cv2.resize(img, (img_size, img_size))   # resizing our images all to a single size 
        
        
        fig.add_subplot(row, col, i+1)
        
        plt.axis('off')
        plt.imshow(img,cmap='gray')
        
    plt.tight_layout()

display_test_images(test_df)