Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to normalize an image in OpenCV Python?
Image normalization in OpenCV rescales pixel values to a specific range, improving image processing and machine learning model performance. The cv2.normalize() function provides various normalization techniques to transform pixel intensities. Syntax The cv2.normalize() function accepts the following parameters ? cv2.normalize(src, dst, alpha, beta, norm_type, dtype, mask) Parameters src − Input image array dst − Output array of the same size as src alpha − Lower norm value for range normalization beta − Upper norm value for range normalization norm_type − Normalization type (NORM_MINMAX, NORM_L2, etc.) dtype − Data type of output array ...
Read MoreHow to mask an image in OpenCV Python?
We can apply a mask to an image by computing the cv2.bitwise_and() between the mask and the image. To track a color, we define a mask in HSV color space using cv2.inRange() passing lower and upper limits of color values in HSV. To track a part of the image we can define a mask using np.zeros() and slicing the entries with white (255) for the region in the input image to examine. Follow the given steps to mask an image − Import required libraries − OpenCV and NumPy Read the input image using cv2.imread() method. Convert the ...
Read MoreHow to flip an image in OpenCV Python?
In OpenCV, an image can be flipped using the function cv2.flip(). Using this function we can flip the image across X-axis, Y-axis and across both axes. It accepts a flag flipCode as an argument to flip the image across the axis. If the flipCode is set to 0, the image is flipped across the x-axis and if the flipCode is set to a positive integer (say 1), the image is flipped across the Y-axis. If the flipCode is set to a negative integer (say -1), the image is flipped across both axes. Syntax cv2.flip(image, flipCode) ...
Read MoreHow to access and modify pixel value in an image using OpenCV Python?
In OpenCV, you can access and modify pixel values in images using NumPy-style indexing. Since OpenCV images are stored as NumPy arrays, you can use array indexing to read pixel values and assignment operations to modify them. Understanding Image Structure OpenCV loads color images in BGR (Blue, Green, Red) format. Each pixel contains three values representing the intensity of each color channel (0-255). Accessing a Single Pixel Value To access a pixel at coordinates (row, column), use array indexing ? import cv2 import numpy as np # Create a sample image for demonstration ...
Read MoreHow to split an image into different color channels in OpenCV Python?
A color image consists of three color channels − Red, Green, and Blue. These color channels can be split using cv2.split() function in OpenCV Python. This technique is useful for analyzing individual color components or applying channel-specific processing. Syntax blue, green, red = cv2.split(image) The cv2.split() function takes a BGR image as input and returns three separate arrays representing the Blue, Green, and Red channels respectively. Steps to Split Color Channels Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed ...
Read MoreOpenCV Python – How to find and draw extreme points of an object on an image?
Finding and drawing extreme points of objects in an image is useful for shape analysis and object detection. Extreme points are the leftmost, rightmost, topmost, and bottommost coordinates of a contour. Algorithm Steps To find and draw extreme points of objects, follow these steps: Load and preprocess − Read the input image using cv2.imread() and convert it to grayscale. Apply thresholding − Create a binary image using cv2.threshold() for better contour detection. Find contours − Detect object boundaries using cv2.findContours(). Calculate extreme points − For each contour, find the leftmost, rightmost, topmost, and bottommost points. Draw ...
Read MoreOpenCV Python – How to draw circles using Mouse Events?
OpenCV provides various mouse events to interact with images, such as cv2.EVENT_LBUTTONDOWN for left button click, cv2.EVENT_RBUTTONDOWN for right button click, and cv2.EVENT_LBUTTONDBLCLK for double-click. These events return mouse coordinates (x, y) which we can use to draw shapes like circles through callback functions. Steps to Draw Circles with Mouse Events To draw circles using mouse events, follow these steps ? Import the required library OpenCV and NumPy. Create a black image or read an existing image using cv2.imread(). Define a mouse callback function that draws circles when mouse events occur. Create a window and bind ...
Read MoreRegression Analysis and the Best Fitting Line using Python
In this tutorial, we will implement regression analysis and find the best-fitting line using Python. We'll explore linear regression concepts and demonstrate practical implementation with scikit-learn. What is Regression Analysis? Regression analysis is a statistical method for modeling relationships between variables. Linear regression specifically models the relationship between a dependent variable (target) and one or more independent variables using a linear equation. In machine learning, linear regression is a supervised algorithm that predicts continuous target values like salary, temperature, or stock prices based on input features. Linear Regression Equation The linear regression equation follows the ...
Read MoreHow to split a Dataset into Train sets and Test sets in Python?
In this tutorial, we will learn how to split a dataset into train sets and test sets using Python. This is a fundamental preprocessing step in machine learning that helps build robust models. Why Split Datasets? When creating machine learning models, we need to evaluate their performance on unseen data. Common problems include overfitting (model performs well on training data but fails on new data) and underfitting (model performs poorly on both training and new data). Splitting the dataset helps us: Train set − Used to train the model (typically 70-80% of data) Test set ...
Read MoreHow to Create simulated data for classification in Python
In this tutorial we will learn how to create simulated data for classification in Python using popular libraries like scikit-learn and Faker. Introduction Simulated data can be defined as any data not representing the real phenomenon but which is generated synthetically using parameters and constraints. This synthetic data mimics real-world patterns and relationships while being completely controllable. When and Why Do We Need Simulated Data? Sometimes while prototyping a particular algorithm in Machine Learning or Deep Learning we generally face a scarcity of good real-world data which can be useful to us. Sometimes there is no ...
Read More