From cbe8f782f7f4d45a5d3356ba7d3f1e620e2848a1 Mon Sep 17 00:00:00 2001 From: Yash Kant Date: Sat, 18 Jan 2020 18:03:01 -0500 Subject: [PATCH 1/2] Update image_preproc.py --- viscap/captioning/utils/image_preproc.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/viscap/captioning/utils/image_preproc.py b/viscap/captioning/utils/image_preproc.py index 083c210..a10dc08 100644 --- a/viscap/captioning/utils/image_preproc.py +++ b/viscap/captioning/utils/image_preproc.py @@ -22,6 +22,13 @@ def read_image(image_path): def image_transform(img): im = np.array(img).astype(np.float32) + + # Handle images with Luminosity and Alpha channel + # Converting 2 channeled images to grayscale: + # https://stackoverflow.com/questions/56531491 + if im.shape[2] == 2: + im = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) + assert len(im.shape) == 2 # Handle B&W images if len(im.shape) == 2: @@ -31,8 +38,9 @@ def image_transform(img): if im.shape[2] == 4: im = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) + assert im.shape[2] == 3 + im = im[:, :, ::-1] - # Transform used for BUTD model in pythia trained on coco im -= np.array([102.9801, 115.9465, 122.7717]) im_shape = im.shape From 7702f42b888725de9e75f135faf176a569d9fe34 Mon Sep 17 00:00:00 2001 From: Yash Kant Date: Wed, 22 Jan 2020 14:06:48 -0500 Subject: [PATCH 2/2] Update image_preproc.py --- viscap/captioning/utils/image_preproc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viscap/captioning/utils/image_preproc.py b/viscap/captioning/utils/image_preproc.py index a10dc08..627c11c 100644 --- a/viscap/captioning/utils/image_preproc.py +++ b/viscap/captioning/utils/image_preproc.py @@ -27,7 +27,7 @@ def image_transform(img): # Converting 2 channeled images to grayscale: # https://stackoverflow.com/questions/56531491 if im.shape[2] == 2: - im = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) + im = Image.open(im).convert('L') assert len(im.shape) == 2 # Handle B&W images