text_plain_output_35.png text_plain_output_43.png text_plain_output_37.png text_plain_output_5.png text_plain_output_48.png text_plain_output_30.png text_plain_output_15.png text_plain_output_9.png text_plain_output_44.png text_plain_output_40.png text_plain_output_31.png text_plain_output_20.png text_plain_output_4.png text_plain_output_13.png text_plain_output_52.png text_plain_output_45.png text_plain_output_14.png text_plain_output_32.png text_plain_output_29.png text_plain_output_49.png text_plain_output_27.png text_plain_output_10.png text_plain_output_6.png text_plain_output_24.png text_plain_output_21.png text_plain_output_47.png text_plain_output_25.png text_plain_output_18.png text_plain_output_50.png text_plain_output_36.png application_vnd.jupyter.stderr_output_3.png text_plain_output_22.png text_plain_output_38.png text_plain_output_7.png text_plain_output_16.png text_plain_output_8.png text_plain_output_26.png text_plain_output_41.png text_plain_output_34.png text_plain_output_42.png text_plain_output_23.png text_plain_output_51.png text_plain_output_28.png text_plain_output_2.png text_plain_output_33.png application_vnd.jupyter.stderr_output_1.png text_plain_output_39.png text_plain_output_19.png text_plain_output_17.png text_plain_output_11.png text_plain_output_12.png text_plain_output_46.png
from keras.preprocessing import image

from pathlib import Path

import numpy as np # linear algebra

img_root_path = Path('../input/chest-xray-masks-and-labels/Lung Segmentation/CXR_png/')
mask_root_path = Path('../input/chest-xray-masks-and-labels/Lung Segmentation/masks')
test_root_path = Path('../input/chest-xray-masks-and-labels/Lung Segmentation/test')
img_paths = sorted(img_root_path.iterdir())
mask_paths = sorted(mask_root_path.iterdir())
test_paths = sorted(test_root_path.iterdir())

images = []
masks = []
test_images = []
image_size = (256, 256)
for img, mask, test_img in zip(img_paths, mask_paths, test_paths):
    images.append(image.load_img(img, target_size=image_size))
    masks.append(image.load_img(mask, target_size=image_size))
    test_images.append(image.load_img(test_img, target_size=image_size))

X = []
for img in images:
    x = image.img_to_array(img)
    X.append(x)
X = np.array(X)

y = []
for mask in masks:
    y.append(image.img_to_array(mask))
y = np.array(y)

print(np.sum(y[0, ..., 0] == y[0, ..., 1]))
print(np.sum(y[0, ..., 1] == y[0, ..., 2]))