Help us understand the problem. What is going on with this article?


More than 1 year has passed since last update.


import cv2
import numpy as np

        img = cv2.imread(image_file_path, cv2.IMREAD_UNCHANGED)
        # 画像から透明ピクセル(アルファチャンネルが0)を抜き出し、白ピクセルで置き換える
        # np.where使いたかったけど使い方がわからんかったのです
        for y in range(img.shape[0]):
            for x in range(img.shape[1]):
                if img[y, x, 3] == 0:
                    img[y, x] = [255, 255, 255, 255]

        # jpg保存をもってアルファチャンネル削除に替える
        cv2.imwrite(dst_file_path, img)


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away