1. 製品
  2.   画像
  3.   Python
  4.   Sikit Image
 
  

画像用のオープン ソース Python API

Python API による画像の科学的画像分析、フィルタリング、および復元。

Sikit-Image は、画像処理用のオープン ソース Python API です。 API は、Python で幅広い画像処理ルーチンを提供します。この API を使用すると、特定の科学的および汎用的な画像からデータを抽出し、NumPy 操作を使用して画像を操作し、構造化要素を生成し、画像のビューをブロックし、露出とカラー チャネルを操作し、エッジとラインを管理し、幾何学的な変換を実行できます。

さらに、API を使用すると、画像のフィルタリングと復元が可能です。グレースケール イメージ内の小規模なオブジェクトを削除したり、平均フィルターを使用したり、シャープ マスキングを使用したりできます。これだけでなく、API を使用すると、さらに多くの機能で画像を操作できます。

Previous Next

Sikit-Image を使い始める

Sikit-Image をインストールするための推奨される方法は、Pip を使用することです。次のコマンドを使用して Sikit-Image をインストールしてください。

Pip 経由で Sikit-Image をインストールする

pip install scikit-image

Python を介して露出とカラー チャネルを操作する

Sikit-Image API を使用すると、プログラムで画像の色と露出を操作できます。RGB 画像をグレースケール画像または HSV 画像に変換できます。ヒストグラム マッチング、免疫組織化学染色の色分離、グレースケール画像の色付け、ヒストグラム均等化、ガンマと対数コントラストの調整、局所的な最大値のフィルタリング、グレースケール フィルターの RGB 画像への適応を行うことができます。

無料の Python API を使用した幾何学的変換

Sikit-Image API を使用すると、画像の色と露出をプログラムで操作できます。 RGB イメージをグレースケール イメージまたは HSV イメージに変換できます。ヒストグラム マッチング、免疫組織化学染色の色分離、グレースケール画像の色付け、ヒストグラム均等化、ガンマと対数コントラストの調整、局所最大値のフィルタリング、グレースケール フィルターの RGB 画像への適応を行うことができます。

Pythonで幾何学的変換を実行

# First we create a transformation using explicit parameters:
tform = transform.SimilarityTransform(scale=1, rotation=math.pi/2,
                                      translation=(0, 1))
print(tform.params)
# Alternatively you can define a transformation by the transformation matrix itself:
matrix = tform.params.copy()
matrix[1, 2] = 2
tform2 = transform.SimilarityTransform(matrix)
# apply forward & inverse coordinate transformations b/t the source & destination coordinate systems:
coord = [1, 0]
print(tform2(coord))
print(tform2.inverse(tform(coord)))
# Geometric transformations  to warp images:
text = data.text()
tform = transform.SimilarityTransform(scale=1, rotation=math.pi/4,
                                      translation=(text.shape[0]/2, -100))
rotated = transform.warp(text, tform)
back_rotated = transform.warp(rotated, tform.inverse)
fig, ax = plt.subplots(nrows=3)
ax[0].imshow(text, cmap=plt.cm.gray)
ax[1].imshow(rotated, cmap=plt.cm.gray)
ax[2].imshow(back_rotated, cmap=plt.cm.gray)
for a in ax:
    a.axis('off')
plt.tight_layout()

Python による画像のフィルタリングと復元

Scikit-Image ライブラリを使用すると、開発者はプログラムでイメージをフィルタリングおよび復元できます。トップ ハット フィルターを使用してグレースケール イメージから小さなオブジェクトを削除したり、イメージで Windows 関数を使用したり、平均フィルターを使用したり、アンシャープ マスキングを使用したり、イメージ デコンボリューションを使用したりできます。

Pythonで画像フィルタリングを実行

# Let us load an image available through scikit-image’s data registry.
image = data.astronaut()
image = color.rgb2gray(image)
# Let us blur this image with a series of uniform filters of increasing size.
blurred_images = [ndi.uniform_filter(image, size=k) for k in range(2, 32, 2)]
img_stack = np.stack(blurred_images)
fig = px.imshow(
    img_stack,
    animation_frame=0,
    binary_string=True,
    labels={'animation_frame': 'blur strength ~'}
)
plotly.io.show(fig)
# Plot blur metric
B = pd.DataFrame(
    data=np.zeros((len(blurred_images), 3)),
    columns=['h_size = 3', 'h_size = 11', 'h_size = 30']
)
for ind, im in enumerate(blurred_images):
    B.loc[ind, 'h_size = 3'] = measure.blur_effect(im, h_size=3)
    B.loc[ind, 'h_size = 11'] = measure.blur_effect(im, h_size=11)
    B.loc[ind, 'h_size = 30'] = measure.blur_effect(im, h_size=30)
B.plot().set(xlabel='blur strength (half the size of uniform filter)',
             ylabel='blur metric');
plt.show()
 日本