4
1

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.

scikit-imageを簡単にcudaで計算させる

Last updated at Posted at 2022-02-04

画像処理ライブラリのscikit-imageを簡単にCUDAで走らせるcucimというものを見つけたので、試してみる。

https://developer.nvidia.com/blog/cucim-rapid-n-dimensional-image-processing-and-i-o-on-gpus/
https://docs.rapids.ai/api/cucim/nightly/api.html

なお、scikit-imageのすべてのサブモジュールが使えるわけではないようだ。
22/02/24現在、future.graph.merge_hierarchicalは使えない。

インストール

pipが使えるなら、

先に、cupyなどの環境を整えておく必要があると思うが、

pip install cucim

で入るようだ。

condaなどの方法は、以下を参照。

numpyの配列 ⇔ cupyの配列の変換

numpy配列に入れた画像をcupy配列に入れてから用いるようである。

# numpy-array --> cupy-array
image_gpu = cp.asarray(image)

# cupy-array --> numy-array
image_cpu = cp.asnumpy(image_gpu)

例、ガウシアンフィルターと画像表示

import numpy as np
import cupy as cp
import cucim
from cucim.skimage.filters import gaussian

from skimage import data, img_as_float
from skimage.io import imread, imshow
import matplotlib.pyplot as plt

def gpu_imshow(image_gpu):
    image = cp.asnumpy(image_gpu)
    imshow(image)
    plt.show()

image = img_as_float(data.camera())
image_gpu = cp.asarray(image)
blurred_gpu = gaussian(image_gpu, sigma=5)
gpu_imshow(blurred_gpu)

参考

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?