Found 184 Articles for OpenCV

How to perform distance transformation on a given image in OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:58:26

995 Views

We can perform the distance transform using the method cv2.distanceTransform(). Following is the syntax of this method. Syntax cv2.distanceTransform(src, distanceType, maskSize) This method accepts the following parameters − src − 8-bit, single-channel (binary) source image. distanceType − Type of the distance. maskSize − Size of the distance transform mask. Steps To perform distance transform on the image, we could follow the below steps- Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed it. Read an input image using cv2.imread(). The RGB image read using ... Read More

How to implement probabilistic Hough Transform in OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:51:28

2K+ Views

Probabilistic Hough Transform is an optimization of the Hough Transform. The hough transform takes a lot of computation even for a line with two arguments. Probabilistic Hough Transform doesn't take all the points into consideration, it takes only a random subset of points and that is sufficient for line detection. We could follow the below given steps to implement probabilistic Hough Transform on an image- Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed it. Read an input image using cv2.imread(). The RGB image read using ... Read More

How to find the Fourier Transforms of Gaussian and Laplacian filters in OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:49:06

875 Views

We apply Fourier Transform to analyze the frequency characteristics of various filters. We can apply Fourier transform on the Gaussian and Laplacian filters using np.fft.fft2(). We use np.fft.fftshift() to shift the zero-frequency component to the center of the spectrum. Steps To find Fourier transforms of the Gaussian or Laplacian filters, one could follow the steps given below − Import the required libraries. In all below Python examples the required Python libraries are OpenCV, Numpy and Matplotlib. Make sure you have already installed them. Define a Gaussian or a Laplacian Filter. Apply Fourier transform on the above defined ... Read More

How to find the Fourier Transform of an image using OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:47:25

3K+ Views

The Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) are applied on images to find the frequency domain. To find the Fourier transforms of an image we use the functions cv2.dft() and cv2.idft(). We can apply Fourier Transform to analyze the frequency characteristics of various filters. Steps To find Fourier transforms of an input image, one could follow the steps given below − Import the required libraries. In all below Python examples the required Python libraries are OpenCV, Numpy and Matplotlib. Make sure you have already installed them. Load the input image as a grayscale image ... Read More

OpenCV Python – How to compute and plot the histogram of a region of an image?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:44:25

3K+ Views

In OpenCV, We use the cv2.calcHist() function to compute the histogram of an image. We can use this function to compute the histogram of a region of the image. To compute a histogram of a region in the image first we define a mask. The white color in the maskis for regions to examine in the original input image and the black color in the mask image is for regions to ignore. Now we calculate the histogram passing this mask as a parameter to the function. Steps To compute and plot the histograms of a region of the image, one ... Read More

How to compute and plot 2D histograms of an image in OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:41:58

564 Views

We can apply the cv2.calcHist() function to compute a 2D histogram of an image. The color image has three channels- Red, Green and Blue. We can compute the 2D histograms for two color channels at a time. So we have three combinations of the color channels taking two at a time- Red & Green (or Green & Red), Green & Blue (or Blue & Green) and Blue & Red (or Red & Blue). Steps To compute and plot 2D histograms of an input image, one could follow the steps given below − Import required libraries OpenCV and matplotlib. ... Read More

OpenCV Python – How to convert a colored image to a binary image?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:39:58

21K+ Views

We use cv2.threshold() to convert a grayscale image to binary image. To convert a color image to binary image, we first convert the color image to grayscale image using cv2.cvtColor() then apply cv2.threshold() on the grayscale image. Steps One could follow the below given steps to convert a color image to a binary image- Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed it. Read an the input image using cv2.imread(). The RGB image read using this method is in BGR format. Optionally assign the read ... Read More

OpenCV Python – How to find the shortest distance between a point in the image and a contour?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:37:06

3K+ Views

We could compute the shortest distance between a point and a contour on the image using cv2.pointPolygonTest() passing the contour points coordinates and the point coordinate as arguments. Before applying cv2.pointPolygonTest() we need to compute the contours in the image. We could follow the below given steps to find shortest distance between a given point and a contour of an object in an image- Import the required library. In all the following Python examples, the required Python library is OpenCV. Make sure you have already installed it. Read an input image using cv2.imread(). The RGB image read using ... Read More

OpenCV Python – How to perform bitwise NOT operation on an image?

Shahid Akhtar Khan
Updated on 02-Dec-2022 10:34:43

1K+ Views

We can perform bitwise NOT operation on an image using cv2.bitwise_not(). Here is the syntax to perform bitwise NOT operation on an image - cv2.bitwise_not(img) Steps To compute bitwise NOT on an image, you can follow the steps given below − Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed it. Read the input image as a grayscale image using cv2.imread() method. Specify the full path of the image with the image type (i.e. png or jpg). Compute the bitwise NOT on the input image using ... Read More

How to normalize an image in OpenCV Python?

Shahid Akhtar Khan
Updated on 26-Aug-2023 03:42:32

37K+ Views

We use the function cv2.normalize() to normalize an image in OpenCV. This function accepts the parameters- src, dst, alpha, beta, norm_type, dtype and mask. src and dst are input image and output of the same size as input, alpha is lower norm value for range normalization, beta is upper norm value for range normalization, norm_type is normalization type, dtype is data type of output and mask is optional operation mask. Steps To normalize an image, we could follow the steps given below − Import the required library. In all the following examples, the required Python library is OpenCV. ... Read More

Previous 1 ... 3 4 5 6 7 ... 19 Next
Advertisements