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

OpenCVを使用して画像に逆ゼロしきい値を実行する


このプログラムでは、openCVを使用して画像に対して逆ゼロしきい値処理を実行します。しきい値処理は、各ピクセルの値がしきい値に関連して変更されるプロセスです。ピクセルには、しきい値よりも小さい場合は特定の値が与えられ、しきい値よりも大きい場合は他の値が与えられます。逆ゼロしきい値処理では、強度値がしきい値よりも大きいピクセルが0に設定されます。

元の画像

OpenCVを使用して画像に逆ゼロしきい値を実行する

アルゴリズム

Step 1: Import cv2.
Step 2: Define the threshold and max_val.
Step 3: Pass these parameters in the cv2.threshold value and specify the type of thresholding you want to do.
Step 4: Display the output.

サンプルコード

import cv2

image = cv2.imread('testimage.jpg')
threshold_value = 120
max_val = 255
ret, image = cv2.threshold(image, threshold_value, max_val, cv2.THRESH_TOZERO_INV)
cv2.imshow('InverseZeroThresholding', image)

出力

OpenCVを使用して画像に逆ゼロしきい値を実行する


  1. OpenCVを使用して画像に線を引く

    このプログラムでは、OpenCV関数line()を使用して画像に単純な線を描画します。 元の画像 アルゴリズム Step 1: Import cv2. Step 2: Read the image using imread(). Step 3: Get the dimensions of the image using the image.shape method. Step 4: Define starting point of the line. Step 5: Define the end point of the line. Step 6: Define the thicknes

  2. OpenCVを使用した画像の読み取りと表示

    この記事では、OpenCVライブラリを使用して画像を読み取って表示する方法を学習します。 OpenCVは、主にリアルタイムのコンピュータービジョンを目的としたプログラミング機能のライブラリです。画像を読み取る前に、画像がプログラムと同じディレクトリにあることを確認してください。 アルゴリズム Step 1: Import OpenCV. Step 2: Read an image using imread(). Step 3: Display the image using imshow(). サンプルコード import cv2 as cv image = cv.imread ('