0% found this document useful (0 votes)
14 views38 pages

UNIT-II_Low Level Computer Vision

Uploaded by

VIDYA JAGTAP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views38 pages

UNIT-II_Low Level Computer Vision

Uploaded by

VIDYA JAGTAP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

COMPUTER VISION

UNIT -II
Low Level
Computer Vision

VIDYA JAGTAP
Low Level Image Processing: Image filtering, 2D
Convolution, smoothing, sharpening Spatial and
frequency domain filtering,
 Introduction to Low Level Image Processing:

 Low-level image processing refers to the initial stages of image processing,


where the focus is on extracting basic features and attributes from the
image data.

These processes are typically performed on the pixel level and are
used to:

1. _Enhance image quality_: Adjust brightness, contrast, and color balance.


 2. _Remove noise and artifacts_: Filter out unwanted distortions and errors.
 3. _Detect edges and contours_: Identify boundaries and shapes within the
image.
 4. _Extract texture and pattern information_: Analyze surface properties and
arrangements.
 5. _Perform image segmentation_: Divide the image into regions or objects.

VIDYA JAGTAP
 Low-level image processing techniques include:

 1. _Point operations_: Apply transformations to individual pixels


(e.g., brightness adjustment).
 2. _Local operations_: Perform calculations on small groups of pixels
(e.g., smoothing filters).
 3. _Global operations_: Analyze the entire image (e.g., histogram
equalization).
 4. _Frequency domain processing_: Manipulate image data in the
frequency domain (e.g., Fourier transform).
 5. _Morphological operations_: Use shape-based transformations
(e.g., dilation, erosion).

 Examples of low-level image processing algorithms:

 1. _Image filtering_ (e.g., Gaussian blur, median filter)


 2. _Thresholding_ (e.g., binary thresholding, adaptive thresholding)
 3. _Edge detection_ (e.g., Sobel, Canny, Laplacian of Gaussian)
 4. _Image sharpening_ (e.g., unsharp masking, deconvolution)
 5. _Noise reduction_ (e.g., wavelet denoising, total variation
VIDYA JAGTAP
Image filtering
 Image filtering is a fundamental process in computer vision that
involves modifying an image to enhance, restore, or extract
specific features.
 Purpose of Filtering to:
 1. *Reduce noise*: Remove random variations in pixel values.
 2. *Enhance details*: Highlight specific features, such as edges
or textures.
 3. *Correct distortions*: Compensate for camera or lens
distortions.
 4. *Improve quality*: Adjust brightness, contrast, and color
balance.

Types of image filtering techniques:

1. *Linear filters*:
 - Mean filter (average neighboring pixels)
VIDYA JAGTAP
 - Gaussian filter (weighted average)
 2. *Non-linear filters*:
 - Sobel filter (edge detection)
 - Laplacian of Gaussian (LoG) filter (edge detection)
 - Canny filter (edge detection)
 3. *Frequency domain filters*:
 - Fourier transform (filter in frequency domain)
 - Wavelet transform (filter in frequency domain)
 4. *Morphological filters*:
 - Erosion (remove small features)
 - Dilation (expand features)
 - Opening (erosion followed by dilation)
 - Closing (dilation followed by erosion)
 5. *Other filters*:
 - Bilateral filter (edge-preserving smoothing)
 - Anisotropic diffusion filter (edge-preserving smoothing)

VIDYA JAGTAP
 Filtering can be applied in various domains,
including:
 1. *Spatial domain*: Directly manipulate pixel values.
 2. *Frequency domain*: Modify image data in the frequency domain.
 3. *Wavelet domain*: Use wavelet transforms to filter images.

 Spatial Domain Filtering*

 - Operates directly on pixel values in the image spatial domain


 - Uses neighborhood operations (e.g., convolution) to modify pixel
values
 - Filters are applied in the spatial domain, using a kernel or mask
 - Examples: mean filter, median filter, Sobel filter, Gaussian filter

 *Frequency Domain Filtering*


 - Transforms the image into the frequency domain using Fourier
transform
 - Operates on the frequency components of the image
 - Filters are applied in the frequency domain, modifying frequency
VIDYA JAGTAP
coefficients
2D Convolution
 2D convolution is a fundamental operation in low-level image processing,
used to apply filters to images. It involves sliding a kernel (filter) over the
image, element-wise multiplying the kernel with the underlying image pixels,
and summing the results.

Process OF 2D Convolution :

 The process of 2D convolution involves the following steps:

1. *Kernel Selection*: Choose a kernel (filter) that defines the operation to be


performed on the image.

 2. *Kernel Padding*: Pad the kernel with zeros to match the size of the image,
if necessary.

 3. *Image Padding*: Pad the image with zeros to ensure that the kernel can
slide over the entire image, if necessary.

VIDYA JAGTAP
 4. *Kernel Sliding*: Slide the kernel over the image, starting
from the top-left corner.

 5. *Element-wise Multiplication*: Multiply the kernel elements


with the corresponding image pixel values.

6. *Summation*: Sum the products of the element-wise
multiplication.

7. *Output Calculation*: Calculate the output pixel value by
summing the results of the multiplication and summation steps.

8. *Repeat*: Repeat steps 4-7 for each pixel in the image.

 9. *Output Image*: The resulting output image is the convolved


image.

VIDYA JAGTAP
 Mathematical Representation of 2D Convolution:-

 Let `I` be the image, `K` be the kernel, and `O` be the output image.
 The 2D convolution is represented as:

 O(x, y) = ΣΣ I(x+i, y+j) * K(i, j)

 where `x` and `y` are the coordinates of the output pixel,
 `i` and `j` are the coordinates of the kernel,
 `ΣΣ` denotes the summation over the kernel.

VIDYA JAGTAP
 Types of 2D Convolution:_
 1. _Valid Convolution_: Only compute output pixels where the kernel fully overlaps with
the image.
 2. _Same Convolution_: Compute output pixels even when the kernel partially overlaps
with the image, padding with zeros if necessary.
 3. _Full Convolution_: Compute output pixels for all possible kernel positions, padding
with zeros if necessary.

 Applications of 2D Convolution:

 1. _Image Filtering_: Apply filters to enhance or restore images (e.g., blur, sharpen,
edge detection).
 2. _Image Feature Extraction_: Extract features like edges, lines, or textures.
 3. _Image Denoising_: Remove noise from images.

 Common 2D Convolution Kernels:

1. _Box Filter_: Averages neighboring pixels.


 2. _Gaussian Filter_: Smooths the image using a Gaussian distribution.
 3. _Sobel Filter_: Detects edges in the image.
 4.JAGTAP
VIDYA _Laplacian of Gaussian (LoG) Filter_: Detects edges and blobs.
Smoothing

 Sometimes, images can be noisy or have rough textures. That's where smoothing
comes in - a technique in low-level image processing to reduce noise and smooth out
textures.

Here are some common smoothing techniques:



1. *Mean Filter*: Replaces each pixel with the average value of neighboring pixels.

 2. *Median Filter*: Replaces each pixel with the median value of neighboring pixels.
 3. *Gaussian Filter*: Uses a Gaussian distribution to weight neighboring pixels.

 4. *Bilateral Filter*: Preserves edges while smoothing by considering both intensity


and spatial proximity.

 5. *Anisotropic Diffusion*: Adapts smoothing strength based on image features.

 6. *Total Variation (TV) Smoothing*: Minimizes image intensity variations.

VIDYA JAGTAP
 Advantages of Smoothing:

 1. *Reduce noise*

2. *Remove small details*

 3. *Improve image quality*

 4. *Prepare images for further processing*

VIDYA JAGTAP
Histogram processing (equalization, matching) Edge
detection (Sobel, Canny)
 Histogram processing :-
 Histogram processing is a technique used in image processing to
analyze and modify the distribution of pixel values in an image.
 A histogram is a graphical representation of the frequency of each
pixel value in an image.

 Types of histogram processing:


 1. _Histogram Equalization (HE)_: Adjusts pixel values to create
a uniform distribution, enhancing contrast.
 2. _Histogram Stretching_: Expands the range of pixel values to
improve contrast.
 3. _Histogram Shifting_: Shifts the entire histogram to change
the brightness.
 4. _Histogram Matching_: Matches the histogram of an image to
a reference histogram.
VIDYA JAGTAP
 5. _Adaptive Histogram Equalization (AHE)_: Applies HE to small regions,
reducing noise.

 6. _Contrast Limited Adaptive Histogram Equalization (CLAHE)_: Limits contrast


to avoid noise amplification.

 4. _Histogram Matching_: Matches the histogram of an image to a reference


histogram.

 5. _Adaptive Histogram Equalization (AHE)_: Applies HE to small regions,


reducing noise.

 6. _Contrast Limited Adaptive Histogram Equalization (CLAHE)_: Limits contrast


to avoid noise amplification.

VIDYA JAGTAP
 Histogram processing is used for:

1. _Image enhancement_
2. _Contrast adjustment_
3. _Brightness adjustment_
4. _Noise reduction_
5. _Image segmentation_

Histogram Equalization (HE)_:


 Histogram equalization is a technique used to enhance the contrast of
an image by adjusting the pixel values to create a more uniform
distribution.

 *Example:*
 Original Image:
 ```
 Pixel Values: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
 Histogram: [5, 5]
 ```
VIDYA JAGTAP
 After Histogram Equalization:
 Pixel Values: [0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
 Histogram: [5, 5]

 In this example, the original image has a skewed histogram with most
pixels having a value of 0 or 1. After histogram equalization, the pixel
values are adjusted to create a more uniform distribution, enhancing
the contrast of the image.

 *Steps:*
 1. Calculate the histogram of the original image.
 2. Calculate the cumulative distribution function (CDF) of the
histogram.
 3. Map each pixel value to its corresponding CDF value.
 4. Scale the CDF values to the range [0, 255] (or the maximum pixel
value).

VIDYA JAGTAP
 *Code Example (Python):*
 import cv2
 import numpy as np

 # Load the image


 img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)

# Calculate the histogram
 hist, bins = np.histogram(img.flatten(), 256, [0, 256])

 # Calculate the CDF


 cdf = hist.cumsum()

 # Map pixel values to CDF values


 equalized_img = cdf[img]

 # Scale to [0, 255]


 equalized_img = np.interp(equalized_img, (cdf.min(), cdf.max()), (0, 255))
 # Display the equalized image
 cv2.imshow('Equalized Image', equalized_img.astype(np.uint8))
 cv2.waitKey(0)
 cv2.destroyAllWindows()
VIDYA JAGTAP

 ```
 Histogram matching :
 Histogram matching is a technique used to transform the histogram of an image to match
a reference histogram. This is useful for:
 1. _Image normalization_: To reduce variations in lighting conditions.
 2. _Image registration_: To align multiple images.
 3. _Image fusion_: To combine multiple images.

 Example: Original image histogram is transformed to match the reference histogram.

 Reference Histogram:
 ```
 [0, 0, 0, 10, 20, 30, 20, 10, 0, 0]
 ```
 Original Image Histogram:

```
 [0, 5, 10, 15, 20, 15, 10, 5, 0, 0]
 ```

 After Histogram Matching:

 ```
 [0, 0, 0, 10, 20, 30, 20, 10, 0, 0]
 ```
VIDYA JAGTAP
 Example (Python):_

```
 import cv2
 import numpy as np

 # Load the images


 img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
 ref_img = cv2.imread('reference.jpg', cv2.IMREAD_GRAYSCALE)

 # Calculate the histograms


 hist, bins = np.histogram(img.flatten(), 256, [0, 256])
 ref_hist, ref_bins = np.histogram(ref_img.flatten(), 256, [0, 256])

 # Calculate the CDFs


 cdf = hist.cumsum()
 ref_cdf = ref_hist.cumsum()

 # Map pixel values to CDF values


 matched_img = np.interp(img, cdf, ref_cdf)

 # Display the matched image


 cv2.imshow('Matched Image', matched_img.astype(np.uint8))
 cv2.waitKey(0)
 cv2.destroyAllWindows()
VIDYA JAGTAP
 ```
Edge detection (Sobel, Canny)
 Edge detection using Sobel and Canny are two popular techniques:

 *Sobel Edge Detection:*



1. *Sobel Operator:* Applies two 3x3 kernels (horizontal and vertical) to compute
gradients.
 2. *Horizontal Gradient:* Highlights vertical edges.
 3. *Vertical Gradient:* Highlights horizontal edges.
 4. *Gradient Magnitude:* Combines horizontal and vertical gradients to detect
edges.
 5. *Thresholding:* Applies a threshold to determine edge pixels.

*Canny Edge Detection:*

1. *Noise Reduction:* Applies Gaussian blur to reduce noise.
 2. *Gradient Calculation:* Computes gradients using Sobel operators.
 3. *Non-Maximum Suppression:* Thins edges to single-pixel width.
 4. *Double Thresholding:* Applies two thresholds to detect strong and weak edges.
 5. *Edge Tracking:* Connects weak edges to strong edges to form continuous
edges.
VIDYA JAGTAP
 Key differences:*

1. *Sobel:* Simple and fast, but sensitive to noise and may detect
false edges.

 2. *Canny:* More robust to noise, detects edges more accurately, but


computationally expensive.

 *Choosing between Sobel and Canny:*



1. *Sobel:* Suitable for simple images, real-time applications, or
when speed is crucial.

 2. *Canny:* Suitable for complex images, high-accuracy


requirements, or when edge detection is critical.

VIDYA JAGTAP
 Sobel Edge Detection Example:

 Original Image:

 ```
 1 2 3 4 5
 6 7 8 9 10
 11 12 13 14 15
 16 17 18 19 20
 21 22 23 24 25

 ```
 Sobel Horizontal Gradient:

 ```
 -2 -1 0 1 2
 -2 -1 0 1 2
 -2 -1 0 1 2
 -2 -1 0 1 2
 -2 -1 0 1 2
 ```

VIDYA JAGTAP
 ```
 Sobel Vertical Gradient:

 -10 -8 -6 -4 -2
 -8 -6 -4 -2 0
 -6 -4 -2 0 2
 -4 -2 0 2 4
 -2 0 2 4 6
 ```

 Sobel Edge Detection Output:

 ```
 0 0 0 0 0
 0 1 1 1 0
 0 1 1 1 0
 0 1 1 1 0
 0 0 0 0 0
 ```

VIDYA JAGTAP
 Canny Edge Detection Example:_

Original Image:
 ```
 1 2 3 4 5
 6 7 8 9 10
 11 12 13 14 15
 16 17 18 19 20
 21 22 23 24 25
 ```
 Canny Edge Detection Output:

```
 0 0 0 0 0
 0 1 1 1 0
 0 1 1 1 0
 0 1 1 1 0
 0 0 0 0 0
 ```
 Canny output is similar to the Sobel output, but with more refined edges and
less noise.
VIDYA JAGTAP
 Local pre-processing :
 Local pre-processing operators in image processing are techniques
applied to small regions of an image to enhance or transform the
image. These operators are used to:

 1. *Reduce noise*: Remove random variations in pixel values.


 2. *Enhance edges*: Highlight boundaries between objects.
 3. *Correct intensity*: Adjust pixel values to improve contrast.
 4. *Detect features*: Identify specific patterns or structures.

 local pre-processing operators:

 1. *Mean filter*: Replaces each pixel with the average value of


neighboring pixels.
 2. *Median filter*: Replaces each pixel with the median value of
neighboring pixels.
 3. *Gaussian filter*: Applies a Gaussian distribution to neighboring
pixels.
 4. *Sobel operator*: Detects edges by computing gradients in
horizontal and vertical directions.
VIDYA JAGTAP
 5. *Laplacian operator*: Detects edges by computing the second
derivative of pixel values.
 6. *Prewitt operator*: Detects edges by computing gradients in
horizontal and vertical directions.
 7. *Kirsch operator*: Detects edges by computing gradients in multiple
directions.
 8. *Roberts cross operator*: Detects edges by computing gradients in
diagonal directions.
 9. *Unsharp masking*: Enhances edges by subtracting a blurred
version of the image.
 10. *Histogram equalization*: Adjusts pixel values to equalize the
histogram.

 These local operators are applied to small regions (typically 3x3 or 5x5
pixels) and are used as a pre-processing step for various image
processing tasks, such as:

 1. *Image segmentation*
 2. *Object recognition*
 3. *Feature extraction*
 4. *Image compression*
VIDYA JAGTAP
 Line and corner detection :
 Line and corner detection are essential techniques in image processing for identifying important
features in images.

 *Line Detection:*
 Line detection involves identifying straight lines or edges in an image. Common techniques
include:

 1. *Hough Transform:* A popular method for detecting lines, circles, and ellipses.
 2. *Canny Edge Detection:* Detects edges, which can be used to identify lines.
 3. *Sobel Operator:* Detects edges, which can be used to identify lines.

 *Example:*
 Original Image:

1 2 3 4 5
 6 7 8 9 10
 11 12 13 14 15
 16 17 18 19 20
 21 22 23 24 25

 Hough Transform Output:


 Line 1: (x1, y1) to (x2, y2)
 Line 2: (x3, y3) to (x4, y4)

VIDYA JAGTAP
 *Corner Detection:*

 Corner detection involves identifying points of interest in an image where two edges
meet. Common techniques include:

 1. *Harris Corner Detection:* A popular method for detecting corners.


 2. *Shi-Tomasi Corner Detection:* Similar to Harris corner detection.
 3. *FAST (Features from Accelerated Segment Test):* A fast corner detection algorithm.

 *Example:*

 Original Image:

 1 2 3 4 5
 6 7 8 9 10
 11 12 13 14 15
 16 17 18 19 20
 21 22 23 24 25

 Harris Corner Detection Output:

 Corner 1: (x1, y1)


 Corner 2: (x2, y2)
 Corner
VIDYA JAGTAP 3: (x3, y3)
 OpenCV (Open Source Computer Vision Library):

 OpenCV (Open Source Computer Vision Library) is a widely used, open-source library for
computer vision and machine learning. It provides a comprehensive set of functions and
tools for image and video processing, feature detection, object recognition, and more.

 Key Features:

 1. _Cross-platform_: OpenCV runs on Windows, macOS, Linux, and Android.


 2. _Open-source_: Free to use, modify, and distribute.
 3. _Extensive library_: Over 2,500 functions and algorithms.
 4. _Support for multiple programming languages_: C++, Python, Java, and MATLAB.

 Main Modules:

1. _Core_: Basic data structures and functions.
 2. _ImgProc_: Image processing and feature detection.
 3. _Video_: Video processing and analysis.
 4. _Features2D_: 2D feature detection and description.
 5. _ObjDetect_: Object detection and recognition.
 6. _Calib3D_: 3D calibration and reconstruction.
 7. _ML_: Machine learning and statistical functions.

VIDYA JAGTAP
 Popular OpenCV Applications:

1. _Image and video processing_
 2. _Object recognition and detection_
 3. _Facial recognition and tracking_
 4. _Motion analysis and tracking_
 5. _3D reconstruction and modeling_
 6. _Robotics and autonomous systems_
 7. _Healthcare and medical imaging_

 Getting Started with OpenCV:



1. _Install OpenCV_: Download and install the library from the official website.
 2. _Choose a programming language_: Select a language you're comfortable
with (e.g., Python, C++).
 3. _Read tutorials and documentation_: Familiarize yourself with OpenCV's
functions and modules.
 4. _Practice and experiment_: Start with simple projects and gradually move
to more complex tasks.

VIDYA JAGTAP
 Tools to open and display images using
Python:

 1. *OpenCV*: A comprehensive library for computer vision tasks,


including image processing and display.

- Import: `import cv2`
 - Open image: `img = cv2.imread('image.jpg')`
 - Display image: `cv2.imshow('Image', img)`
 - Wait for key press: `cv2.waitKey(0)`
 - Close window: `cv2.destroyAllWindows()`

 2. *Matplotlib*: A plotting library that can also display images.



- Import: `import matplotlib.pyplot as plt`
 - Open image: `img = plt.imread('image.jpg')`
 - Display image: `plt.imshow(img)`
 JAGTAP
VIDYA - Show plot: `plt.show()`
 3. *Pillow (PIL)*: A friendly fork of the Python Imaging Library
(PIL).

- Import: `from PIL import Image`
 - Open image: `img = Image.open('image.jpg')`
 - Display image: `img.show()`

 4. *Scikit-Image*: A library for image processing that also


provides functions for displaying images.

- Import: `from skimage import io, imshow`
 - Open image: `img = io.imread('image.jpg')`
 - Display image: `imshow(img)`

VIDYA JAGTAP
VIDYA JAGTAP
VIDYA JAGTAP
VIDYA JAGTAP
VIDYA JAGTAP
VIDYA JAGTAP
VIDYA JAGTAP

You might also like