0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Databricks Notebook上で画像のプレビューをする方法

Posted at

Databricks上で画像に関する機械学習やデータサインエンスを実施していると、分析対象の画像ファイル、もしくは、画像データをNotebook上でプレビューしたい場合があります。

今回は、その方法について見ていきます。

参考: この記事のNotebook

方法1: DataFrame(format="image") + display()

  • SparkのDataframe(format="image")で読み込む
  • display()で表示する

ドキュメント: Image

image_df = (
  spark
  .read
  .format("image")
  .load('/databricks-datasets/cctvVideos/train_images/label=0/Browse2frame000*.jpg')
)

### DataFrameなので、いろいろ補助情報のカラムを追加できる
display(
  image_df
  .withColumn('filename', image_df.image.origin)
) 

df_image.png

方法2: DataFrame(format="binary") + display()

  • SparkのDataframe(format="binaryFile")で読み込む
  • .option("mimeType", "image/*")でコンテンツ種別を指定
  • display()で表示する

ドキュメント: Binary File

image_df = (
  spark
  .read
  .format("binaryFile")
  .option("mimeType", "image/*")
  .load('/databricks-datasets/cctvVideos/train_images/label=0/Browse2frame000*.jpg')
)

display( image_df ) 

df_binary.png

方法3: PIL + numpy + matplotlib

  • 通常のJupyter Notebook上で実施するのと同じ方法
from matplotlib.pyplot import imshow
import numpy as np
from PIL import Image

pil_im = Image.open('/dbfs/databricks-datasets/cctvVideos/train_images/label=0/Browse2frame0002.jpg', 'r')
imshow(np.asarray(pil_im))

PIL.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?