image_output_1.png
from PIL import Image

from PIL import Image

from keras.preprocessing import image

from os import listdir

import cv2

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

INIT_LR = 0.001
BS = 32
default_image_size = tuple((72, 72))
image_size = 72
directory_root = '../input/brain-tumor-classification-mri/Training'
width = 256
height = 256
depth = 3

def convert_image_to_array(image_dir):
    try:
        image = cv2.imread(image_dir)
        if image is not None:
            image = cv2.resize(image, default_image_size)
            image = cv2.convertScaleAbs(image, alpha=1.2, beta=0)
            return image.astype(np.uint8)
        else:
            return np.array([])
    except Exception as e:
        return None

image_list, label_list = ([], [])
try:
    root_dir = listdir(directory_root)
    brain_folder_list = listdir(f'{directory_root}/')
    for brain_folder in brain_folder_list:
        brain_image_list = listdir(f'{directory_root}/{brain_folder}/')
        for image in brain_image_list[:500]:
            image_directory = f'{directory_root}/{brain_folder}/{image}'
            if image_directory.endswith('.jpg') == True or image_directory.endswith('.JPG') == True:
                image_list.append(convert_image_to_array(image_directory))
                label_list.append(brain_folder)
                exit
except Exception as e:

np_image_list = np.array(image_list, dtype=np.uint8)

from PIL import Image
import matplotlib.pyplot as plt

from PIL import Image
import matplotlib.pyplot as plt
plt.imshow(Image.fromarray(x_train[100].astype(np.uint8)))
plt.show()