I want to change the background of an image to white. The following code gives me a black background. the input image has a white background. when i print output, it shows black background. Input image is given above
import os
import sys
import random
import warnings
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage.io import imread, imshow, imread_collection,concatenate_images
from skimage.transform import resize
from skimage.morphology import label
import tensorflow as tf
X_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS), dtype=np.uint8)
Y_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.uint8)
print('Getting and resizing train images and masks ... ')
sys.stdout.flush()
for n, id_ in tqdm(enumerate(train_ids), total=len(train_ids)):
path = TRAIN_PATH +'\\'+ id_
path_image = path + '\\images\\'
path_mask = path + '\\masks\\'
for image_file, mask_file in zip(os.listdir(path_image), os.listdir(path_mask)):
img=imread(path_image+image_file)[:,:,:IMG_CHANNELS]
img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
X_train[n] = img
print(path_mask)
print(mask_file)
img2=imread(path_mask+mask_file)[:,:,:IMG_CHANNELS]
img1 = resize(img2, (IMG_HEIGHT, IMG_WIDTH,1), preserve_range=True)
Y_train[n] = img1
#print(img2[0][0])
plt.imshow(img2)
plt.show()