目次
概要
OpenCV または Pillow で読み込んだ画像を base64 文字列に変換する方法について解説します。
Pillow の画像形式から base64 文字列にエンコードする
Pillow の PIL.Image から base64 文字列にエンコードするコードを紹介します。
In [1]:
import base64
from io import BytesIO
from PIL import Image
def pil_to_base64(img, format="jpeg"):
buffer = BytesIO()
img.save(buffer, format)
img_str = base64.b64encode(buffer.getvalue()).decode("ascii")
return img_str
img = Image.open("sample.jpg")
# base64 文字列 (jpeg) に変換する。
img_base64 = pil_to_base64(img, format="jpeg")
変換が行えたことを、img
タグで表示して確認します。
In [2]:
from IPython.display import HTML, display
# インライン画像として表示して確認する。
img_tag = f'<img src="data:image/png;base64,{img_base64}">'
display(HTML(img_tag))
base64 文字列から Pillow の画像形式にデコードする
base64 文字列から Pillow の PIL.Image にデコードするコードを紹介します。
In [3]:
import base64
from io import BytesIO
from PIL import Image
def base64_to_pil(img_str):
if "base64," in img_str:
# DARA URI の場合、data:[<mediatype>][;base64], を除く
img_str = img_str.split(",")[1]
img_raw = base64.b64decode(img_str)
img = Image.open(BytesIO(img_raw))
return img
# base64 文字列
img_base64 = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4QEsRXhpZgAATU0AKgAAAAgABQEPAAIAAAAYAAAASgEQAAIAAAARAAAAYgESAAMAAAABAAEAAIKaAAUAAAABAAAAdIdpAAQAAAABAAAAfAAAAABPTFlNUFVTIElNQUdJTkcgQ09SUC4gIABFLU0xICAgICAgICAgICAgAAAAAAABAAAD6AAHgpoABQAAAAEAAADWgp0ABQAAAAEAAADeiCcAAwAAAAIBkAAAkAMAAgAAABQAAADmkgkAAwAAAAIACAAAkgoABQAAAAEAAAD6pDQAAgAAACAAAAECAAAAAAAAAAEAAAPoAAAAQwAAAAoyMDE5OjA2OjAyIDA5OjMyOjUyAAAAAR4AAAABT0xZTVBVUyBNLjc1LTMwMG1tIEY0LjgtNi43IElJAAAAAP/bAEMAAgEBAgEBAgICAgICAgIDBQMDAwMDBgQEAwUHBgcHBwYHBwgJCwkICAo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knn+Qqy7favFt0snzKt15QB7KMACv6IrUkmfNVIno/wAHPjHefBrxFb6oohkjuLnNxbog/ewnAKDuDj5h7gV9nXXjmHXrS0utPlFxbXkazxSJ91kYZB/Wvz9tnLvdSk/vEJKt6HOOPwr6r/Y/vpr74XeTM/mR2ly8UII/1abVbA9skn8aMPifZ3gtnr8z2+H68nUeGez1XlY6z9pi5a/+AOvQrxI8aN07B1Jr4k1C0V4ObdZPlwxQ4P5f/Wr7a+Nyh/hxq6nlfsz8fhXxxfIJomZh8wB56d68LPJfvYy8v1Ns8p8taPp+pxdzpMcd0gjZo/mGQV/qP8K970Sw0z9of4Ya5oln4d0vR9a8Lwza3Jrf2l2luWP2iR7eONnVVjdET5V3tvIYDCuK8K1G4eCR9rY56da9E/Yy1a4tPjF4i2MuP+EW16TDIrLuTSrl1OCMcMqn8K2ymVqvs5aqWn4meV1l7ZYWor06rUZL1ej9Yt3R5zPqbNI0F0rxSqmA2c/Tf/e9Mjke/Sug8BX0mizS6pIysumwG5tskHbKrKI8H+Jd7KdvsfeofinpdvZT6SYY1jNxYtPIV/idXwG+uOCe+BnOBWl8OLCG5bQ7V41a3vdetEnToJBkZB/76P8AkCunESUKLl/Xf8jlzjJ5ZdjqmBnJScHa669n93T8z6i+BGr2PwR+GoijjgGvtD9ovL1mBmeVgC0Sn+FVGV45OCcleB518fPjBH4zs7WGORAzFjNxlgc8Kf58Z6jqKreN9QmfTb3dIzeXHKyknkFRkH8D/h0rzHxNM0lqGLc7ByOOoB/r+FfkVHC/WsX9brycpX0v08l5Lt0OmM2oKmtrWH6heO9233ZGXCkm3kfkDHVOO1FZ2owxtdtujjc5PLKGPU9zRXvxoqyFKKuf/9k="
# PIL.Image 形式に変換する。
img = base64_to_pil(img_base64)
# インライン画像として表示して確認する。
img
OpenCV の画像形式から base64 文字列にエンコードする
OpenCV の ndarray から base64 文字列にエンコードするコードを紹介します。
In [4]:
import base64
import cv2
def cv_to_base64(img):
_, encoded = cv2.imencode(".jpg", img)
img_str = base64.b64encode(encoded).decode("ascii")
return img_str
# 画像を読み込む。
img = cv2.imread("sample.jpg")
img_str = cv_to_base64(img)
変換が行えたことを、img
タグで表示して確認します。
In [5]:
# インライン画像として表示して確認する。
from IPython.display import HTML, display
img_tag = f'<img src="data:image/jpeg;base64,{img_str}">'
display(HTML(img_tag))
base64 文字列から OpenCV の画像形式にデコードする
base64 文字列から OpenCV の画像形式 ndarray にデコードするコードを紹介します。
In [6]:
import base64
import cv2
import numpy as np
def base64_to_cv(img_str):
if "base64," in img_str:
# DARA URI の場合、data:[<mediatype>][;base64], を除く
img_str = img_str.split(",")[1]
img_raw = np.frombuffer(base64.b64decode(img_str), np.uint8)
img = cv2.imdecode(img_raw, cv2.IMREAD_UNCHANGED)
return img
# base64 文字列
img_base64 = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4QEsRXhpZgAATU0AKgAAAAgABQEPAAIAAAAYAAAASgEQAAIAAAARAAAAYgESAAMAAAABAAEAAIKaAAUAAAABAAAAdIdpAAQAAAABAAAAfAAAAABPTFlNUFVTIElNQUdJTkcgQ09SUC4gIABFLU0xICAgICAgICAgICAgAAAAAAABAAAD6AAHgpoABQAAAAEAAADWgp0ABQAAAAEAAADeiCcAAwAAAAIBkAAAkAMAAgAAABQAAADmkgkAAwAAAAIACAAAkgoABQAAAAEAAAD6pDQAAgAAACAAAAECAAAAAAAAAAEAAAPoAAAAQwAAAAoyMDE5OjA2OjAyIDA5OjMyOjUyAAAAAR4AAAABT0xZTVBVUyBNLjc1LTMwMG1tIEY0LjgtNi43IElJAAAAAP/bAEMAAgEBAgEBAgICAgICAgIDBQMDAwMDBgQEAwUHBgcHBwYHBwgJCwkICAoIBwcKDQoKCwwMDAwHCQ4PDQwOCwwMDP/bAEMBAgICAwMDBgMDBgwIBwgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDP/AABEIAEsAZAMBIgACEQEDEQH/xAAfAAABBQEBA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9skn8aMPifZ3gtnr8z2+H68nUeGez1XlY6z9pi5a/+AOvQrxI8aN07B1Jr4k1C0V4ObdZPlwxQ4P5f/Wr7a+Nyh/hxq6nlfsz8fhXxxfIJomZh8wB56d68LPJfvYy8v1Ns8p8taPp+pxdzpMcd0gjZo/mGQV/qP8K970Sw0z9of4Ya5oln4d0vR9a8Lwza3Jrf2l2luWP2iR7eONnVVjdET5V3tvIYDCuK8K1G4eCR9rY56da9E/Yy1a4tPjF4i2MuP+EW16TDIrLuTSrl1OCMcMqn8K2ymVqvs5aqWn4meV1l7ZYWor06rUZL1ej9Yt3R5zPqbNI0F0rxSqmA2c/Tf/e9Mjke/Sug8BX0mizS6pIysumwG5tskHbKrKI8H+Jd7KdvsfeofinpdvZT6SYY1jNxYtPIV/idXwG+uOCe+BnOBWl8OLCG5bQ7V41a3vdetEnToJBkZB/76P8AkCunESUKLl/Xf8jlzjJ5ZdjqmBnJScHa669n93T8z6i+BGr2PwR+GoijjgGvtD9ovL1mBmeVgC0Sn+FVGV45OCcleB518fPjBH4zs7WGORAzFjNxlgc8Kf58Z6jqKreN9QmfTb3dIzeXHKyknkFRkH8D/h0rzHxNM0lqGLc7ByOOoB/r+FfkVHC/WsX9brycpX0v08l5Lt0OmM2oKmtrWH6heO9233ZGXCkm3kfkDHVOO1FZ2owxtdtujjc5PLKGPU9zRXvxoqyFKKuf/9k="
# ndarray 形式に変換する。
img = base64_to_cv(img_base64)
In [7]:
from IPython.display import Image, display
def imshow(img):
"""ndarray 配列をインラインで Notebook 上に表示する。"""
ret, encoded = cv2.imencode(".jpg", img)
display(Image(encoded))
# インライン画像として表示して確認する。
imshow(img)
コメント