Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Return rgb when rgba is loaded #734

Merged
merged 15 commits into from
Feb 6, 2019
5 changes: 5 additions & 0 deletions chainercv/utils/image/read_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def _read_image_cv2(path, dtype, color):
# reshape (H, W) -> (1, H, W)
return img[np.newaxis].astype(dtype)
else:
# alpha channel is inclued
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

included?

if img.shape[-1] == 4:
bgr = img[:, :, :3]
alpha = img[:, :, 3:] / 255
img = bgr * alpha + 255 * np.ones_like(bgr) * (1 - alpha)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are three options.

  1. just ignore alpha channel
  2. blend with black image
  3. blend with white image

Why do you choose 3.? Personally, I prefer 1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the alpha channel contains meaningful information (for some part, the value is in (0, 1)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. is not acceptable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 2 better?
I thought 3 was more natural

img = img[:, :, ::-1] # BGR -> RGB
img = img.transpose((2, 0, 1)) # HWC -> CHW
return img.astype(dtype)
Expand Down