Python
 Computer >> コンピューター >  >> プログラミング >> Python

Pillowライブラリを使用して画像にMinFilterを適用する


このプログラムでは、ピローライブラリを使用して画像に最小フィルターを適用します。最小フィルタリングでは、画像の選択されたウィンドウの各ピクセルの値が、そのウィンドウの最小ピクセルに置き換えられます。フィルタ機能は、ピローライブラリを使用してさまざまなフィルタを適用するために使用されます。

元の画像

Pillowライブラリを使用して画像にMinFilterを適用する

アルゴリズム

Step 1: Import Image from Pillow.
Step 2: Open the image.
Step 3: Call the filter function and specify minfilter.
Step 4: Display the output.

サンプルコード

from PIL import Image, ImageFilter

im = Image.open('testimage.jpg')
im1 = im.filter(ImageFilter.MinFilter(size = 7))
im1.show()

出力

Pillowライブラリを使用して画像にMinFilterを適用する


  1. Pillowライブラリを使用して、画像内の各バンドのすべてのピクセルの平均を計算する

    このプログラムでは、Pillowライブラリを使用して各チャネルのすべてのピクセルの平均を計算します。画像には合計3つのチャネルがあるため、3つの値のリストが表示されます。 元の画像 アルゴリズム Step 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the mean of the pixels. サンプルコード from PIL im

  2. Pillowライブラリを使用して、画像内の各バンドのすべてのピクセルの中央値を計算します

    このプログラムでは、Pillowライブラリを使用して、各チャネルのすべてのピクセルのMEDIANを計算します。画像には合計3つのチャネルがあるため、3つの値のリストが表示されます。 元の画像 アルゴリズム Step 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the median of the pixels. サンプルコード from