-
Notifications
You must be signed in to change notification settings - Fork 304
Conversation
chainercv/utils/image/read_image.py
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
included
?
chainercv/utils/image/read_image.py
Outdated
if img.shape[-1] == 4: | ||
bgr = img[:, :, :3] | ||
alpha = img[:, :, 3:] / 255 | ||
img = bgr * alpha + 255 * np.ones_like(bgr) * (1 - alpha) |
There was a problem hiding this comment.
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.
- just ignore alpha channel
- blend with black image
- blend with white image
Why do you choose 3.? Personally, I prefer 1.
There was a problem hiding this comment.
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)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- is not acceptable?
There was a problem hiding this comment.
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
ca4c25a
to
b7b5cbc
Compare
cbd7ca7
to
0f38d43
Compare
@Hakuyume |
Sometimes,
cv2.imread
returns(H, W, 4)
array (e.g., the image below).It seems that this behavior is dependent on the build of cv2.
The bug occurred with the
cv2
installed using anaconda, but the same problem did not occur forcv2
installed with apt.EDIT:
Alpha channel extracted by
img = cv2.imread(path)[:, :, 3]
RGB extracted by
img = cv2.imread(path)[:, :, :3][:. :. ::-1]
PIL
f = Image.open(path); img = f.convert('RGB');