teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

d

2019/09/05 06:26

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -9,10 +9,10 @@
9
9
  ```python
10
10
  import cv2
11
11
 
12
- img = cv2.imread("colorbar3.png", cv2.IMREAD_UNCHANGED)
12
+ img = cv2.imread("test.png", cv2.IMREAD_UNCHANGED)
13
13
  print(img.shape) # (288, 432, 3)
14
14
 
15
- if img.ndim == 3:
15
+ if img.ndim == 3: # RGBならアルファチャンネル追加
16
16
  img = cv2.cvtColor(img, cv2.COLOR_RGB2RGBA)
17
17
  print(img.shape) # (288, 432, 4)
18
18
  ```

1

d

2019/09/05 06:25

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -7,12 +7,12 @@
7
7
  cvtColor で RGB 画像にアルファチャンネルを付加できます。
8
8
 
9
9
  ```python
10
-
11
10
  import cv2
12
11
 
13
- img = cv2.imread("colorbar3.png")
12
+ img = cv2.imread("colorbar3.png", cv2.IMREAD_UNCHANGED)
14
13
  print(img.shape) # (288, 432, 3)
15
14
 
15
+ if img.ndim == 3:
16
- rgba = cv2.cvtColor(img, cv2.COLOR_RGB2RGBA)
16
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2RGBA)
17
- print(rgba.shape) # (288, 432, 4)
17
+ print(img.shape) # (288, 432, 4)
18
18
  ```