The Wayback Machine - https://web.archive.org/web/20240624065706/https://www.geeksforgeeks.org/point-processing-in-image-processing-using-python-opencv/
Open In App

Point Processing in Image Processing using Python-OpenCV

Last Updated : 17 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human.

Point processing in spatial domain

All the processing done on the pixel values. Point processing operations take the form –

s = T ( r )

Here, T is referred to as a grey level transformation function or a point processing operation, s refers to the processed image pixel value and r refers to the original image pixel value. 

Image Negative:

s = (L-1) – r, where L= number of grey levels

Thresholding:

s = L-1 for r > threshold
s = 0 for r < threshold

Grey level slicing with background:

s = L-1 for a < r < b,
here a and b define some specific range of grey level
s = r otherwise.

Below is the implementation. 

Original Input Image :

  

Python3




import cv2
import numpy as np
 
  
# Image negative
img = cv2.imread('food.jpeg',0)
 
# To ascertain total numbers of
# rows and columns of the image,
# size of the image
m,n = img.shape
  
# To find the maximum grey level
# value in the image
L = img.max()
  
# Maximum grey level value  minus
# the original image gives the
# negative image
img_neg = L-img
  
# convert the np array img_neg to
# a png image
cv2.imwrite('Cameraman_Negative.png', img_neg)
  
# Thresholding without background
# Let threshold =T
# Let pixel value in the original be denoted by r
# Let pixel value in the new image be denoted by s
# If r<T, s= 0
# If r>T, s=255
  
T = 150
 
# create an array of zeros
img_thresh = np.zeros((m,n), dtype = int)
  
for i in range(m):
     
    for j in range(n):
         
        if img[i,j] <  T:
            img_thresh[i,j]= 0
        else:
            img_thresh[i,j] = 255
  
  
# Convert array to png image
cv2.imwrite('Cameraman_Thresh.png', img_thresh)
  
# the lower threshold value
T1 = 100
 
# the upper threshold value
T2 = 180
 
# create an array of zeros
img_thresh_back = np.zeros((m,n), dtype = int)
  
for i in range(m):
     
    for j in range(n):
         
        if T1 < img[i,j] < T2:
            img_thresh_back[i,j]= 255
        else:
            img_thresh_back[i,j] = img[i,j]
 
# Convert array to  png image
cv2.imwrite('Cameraman_Thresh_Back.png', img_thresh_back)


Output : 

Image Negative

  

Output : 

Image with Thresholding :

  

Output : 

Image with Grey Level Slicing with Background

 



Similar Reads

Connect new point to the previous point on a image with a straight line in Opencv-Python
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. Let's see how to Connect a new point to the previous point on an image with a straight line. Step 1: Draw points on image: On a image we can mark points using cv2.circle( ) method. This method is used to draw a circle on any image. Syntax: cv2.circle(image, ce
3 min read
Image Processing without OpenCV | Python
We know OpenCV is widely used to operate on images and has a wide spectrum of functions to do so. But what if we want to process the image files without using any external library like OpenCV. Let's see how can we do this. Image Scaling (Using Nearest Neighbour Interpolation): Nearest Neighbour interpolation is the simplest way of interpolation. Th
4 min read
Convert OpenCV image to PIL image in Python
OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as Numpy which is a
3 min read
OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
Content has been removed on Author's request.
1 min read
Automatic Document Scanner using OpenCV (OpenCV Document Scanner)
An automatic document scanner using OpenCV is a computer vision application that automatically detects and extracts documents from images. This type of scanner can be useful in various scenarios, such as digitizing paper documents, processing scanned documents, or automating document recognition tasks. In this article, we will see how we can build
6 min read
SIFT Interest Point Detector Using Python - OpenCV
SIFT (Scale Invariant Feature Transform) Detector is used in the detection of interest points on an input image. It allows the identification of localized features in images which is essential in applications such as: Object Recognition in ImagesPath detection and obstacle avoidance algorithmsGesture recognition, Mosaic generation, etc.Unlike the H
4 min read
Image processing with Scikit-image in Python
scikit-image is an image processing Python package that works with NumPy arrays which is a collection of algorithms for image processing. Let's discuss how to deal with images in set of information and its application in the real world. Important features of scikit-image : Simple and efficient tools for image processing and computer vision techniqu
2 min read
Transition from OpenCV 2 to OpenCV 3.x
OpenCV is one of the most popular and most used Computer vision libraries. It contains tools to carry out image and video processing. When OpenCV 3..4.1 is an improved version of OpenCV 2.4 as it introduced new algorithms and features. Although some of the existing modules were rewritten and moved to sub-modules. In this articles, I will focus on t
2 min read
Top Books for Learning OpenCV: Computer Vision with OpenCV Library
OpenCV or Open Source Computer Vision Library, is an open-source computer vision and machine learning software library. It's extensively used for real-time computer vision tasks such as object detection, face recognition, image processing, etc. Whether you're a beginner or an experienced developer looking to deepen your understanding of OpenCV, her
5 min read
Image resizing using Seam carving using OpenCV in Python
Seam carving is an effective image processing technique with the help of which an image can be resized without removing important elements from the image. The basic approach is to find all the continuous pixels with low energy from left to right or from top to bottom. After the region is selected, it is removed from the original image, leaving only
2 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg