OpenCVのequalizeHist()関数とは何ですか?
ヒストグラム 画像のは、ピクセルの強度値の頻度を示しています。画像ヒストグラムでは、X軸はグレーレベルの強度を示し、Y軸はこれらの強度の頻度を示します。
ヒストグラム均等化 強度範囲を拡大するために、画像のコントラストを改善します。 equalizeHist()関数を使用して、特定の画像のヒストグラムを均等化できます。 。
この関数の基本的な構文は-
です。構文
equalizeHist(Source Matrix, Destination Matrix).
このプログラムでは、グレースケール画像をイコライズします。これは、チャネルが1つしかないことを意味します。この関数は、その単一チャネルのピクセル値を等しくしました。ただし、この関数をカラー画像に適用する場合は、ソースと宛先のマトリックスではなく、異なるチャネルを定義する必要があります。次のプログラムでは、カラー画像でのequalizehist()の適用を確認します。
次のプログラムは、 equalizeHist()を示しています。 OpenCVで機能します。
例
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, const char** argv) {
Mat original;//Declaring a matrix//
original = imread("sky.jpg");//loading image//
vectorchannels;//vector to store each channel in different array//
Mat hist;//Declaring a matrix//
cvtColor(original, hist, COLOR_BGR2YCrCb);//Converting from BGR to YCrCB//
split(hist, channels);//splitting channels//
equalizeHist(channels[2], channels[2]);//applying histogram equalizer in 2nd channel//
Mat histeql;//Declaring a matrix//
merge(channels, hist);//merging equalized channel with actual matrix//
cvtColor(hist, histeql, COLOR_YCrCb2BGR);//Reconverting to BGR//
namedWindow("original");//window to show original image//
namedWindow("hist");//window to show edited image//
imshow("original", original);//showing original image//
imshow("hist", histeql);//showing edited image//
waitKey(0);//wait for keystroke//
return 0;
} 出力
-
OpenCV関数blur()を使用して画像をぼかす
このプログラムでは、opencv関数blur()を使用して画像をぼかします。 アルゴリズム Step 1: Import OpenCV. Step 2: Import the image. Step 3: Set the kernel size. Step 4: Call the blur() function and pass the image and kernel size as parameters. Step 5: Display the results. 元の画像 サンプルコード import cv2 image = cv2.imread("testimage.jp
-
OpenCV関数circle()を使用して円を描きます
この記事では、OpenCV関数circle()を使用して画像に円を描きます。 元の画像 アルゴリズム Step 1: Import OpenCV. Step 2: Define the radius of circle. Step 3: Define the center coordinates of the circle. Step 4: Define the color of the circle. Step 5: Define the thickness. Step 6: Pass the above arguments into cv2.circle() along with t