CV Unit 1
CV Unit 1
UNIT-1
Unit I: Introduction to computer vision, Introduction to images, Image Processing VS Computer Vision,
Problems in Computer Vision, Basic image operations, Mathematical operations on images: Datatype
Conversion, Contrast Enhancement, Brightness Enhancement, Bitwise operations: Different Bitwise
Operations
On a certain level, computer vision is all about pattern recognition which includes the training
process of machine systems for understanding the visual data such as images and videos, etc.
Firstly, a vast amount of visual labeled data is provided to machines to train it. This labeled data
enables the machine to analyze different patterns in all the data points and can relate to those
labels. E.g., suppose we provide visual data of millions of dog images. In that case, the computer
learns from this data, analyzes each photo, shape, the distance between each shape, color, etc.,
and hence identifies patterns similar to dogs and generates a model. As a result, this computer
vision model can now accurately detect whether the image contains a dog or not for each input
image.
Task Associated with Computer Vision
Although computer vision has been utilized in so many fields, there are a few common tasks for
computer vision systems. These tasks are given below:
The right side of this equation is digital image by definition. Every element of this matrix is
called image element , picture element , or pixel.
According to block 1,if input is an image and we get out image as a output, then it is termed as
Digital Image Processing.
According to block 2,if input is an image and we get some kind of information or description as
a output, then it is termed as Computer Vision.
According to block 3,if input is some description or code and we get image as an output, then it
is termed as Computer Graphics.
According to block 4,if input is description or some keywords or some code and we get
description or some keywords as a output,then it is termed as Artificial Intelligence
Advantages of Digital Image Processing:
1. Improved image quality: Digital image processing algorithms can improve the visual
quality of images, making them clearer, sharper, and more informative.
2. Automated image-based tasks: Digital image processing can automate many image-based
tasks, such as object recognition, pattern detection, and measurement.
3. Increased efficiency: Digital image processing algorithms can process images much
faster than humans, making it possible to analyze large amounts of data in a short amount
of time.
4. Increased accuracy: Digital image processing algorithms can provide more accurate
results than humans, especially for tasks that require precise measurements or
quantitative analysis.
Disadvantages of Digital Image Processing:
1. High computational cost: Some digital image processing algorithms are computationally
intensive and require significant computational resources.
2. Limited interpretability: Some digital image processing algorithms may produce results
that are difficult for humans to interpret, especially for complex or sophisticated
algorithms.
3. Dependence on quality of input: The quality of the output of digital image processing
algorithms is highly dependent on the quality of the input images. Poor quality input
images can result in poor quality output.
4. Limitations of algorithms: Digital image processing algorithms have limitations, such as
the difficulty of recognizing objects in cluttered or poorly lit scenes, or the inability to
recognize objects with significant deformations or occlusions.
5. Dependence on good training data: The performance of many digital image processing
algorithms is dependent on the quality of the training data used to develop the algorithms.
Poor quality training data can result in poor performance of the algorithm.
Difference between Image Processing and Computer Vision
Computer Vision:
In Computer Vision, computers or machines are made to gain high-level understanding from the
input digital images or videos with the purpose of automating tasks that the human visual system
can do. It uses many techniques and Image Processing is just one of them.
Image Processing:
Image Processing is the field of enhancing the images by tuning many parameter and features of
the images. So Image Processing is the subset of Computer Vision. Here, transformations are
applied to an input image and the resultant output image is returned. Some of these
transformations are- sharpening, smoothing, stretching etc.
Now, as both the fields deal with working in visuals, i.e., images and videos, there seems to be
lot of confusion about the difference about these fields of computer science. In this article we
will discuss the difference between them.
Difference between Image Processing and Computer Vision:
Despite being a straightforward method of image processing, image arithmetic has many uses. Due to its
simplicity, one of its key benefits is speed. For example, when reducing random noise by adding
successive images or detecting motion by subtracting two successive images, the images being
processed are often snapshots of the same scene recorded at various times.
In image arithmetic, logical operators are frequently employed to join binary images. Logical operators
are often applied bitwise when working with integer pictures. This enables the use of a binary mask to
choose particular areas inside an image.
The OpenCV function cv2.add() or the straightforward numpy operation addition = image1 + image2 can
be used to combine two images. Both images should be of the same depth and type, otherwise, the
second image can simply be a scalar number. But, adding the pixels is not optimal. As a result, we
employ the cv2.addweighted() function.
import cv2
import numpy as np
image1 = cv2.imread('/content/montains.jpeg')
image2 = cv2.imread('/content/sunrise.jpeg')
cv2_imshow(image1)
cv2_imshow(image2)
cv2_imshow(added_image)
Output
subtraction of images With cv2.subtract, we may subtract the pixel values from two images and merge
them . The images must be the same size and depth. It is customary to use a single image as input and to
subtract a constant value from all of the pixels.
import cv2
import numpy as np
image1 = cv2.imread('/content/montains.jpeg')
image2 = cv2.imread('/content/sunrise.jpeg')
image1 = cv2.resize(image1, (300, 300))
cv2_imshow(image1)
cv2_imshow(image2)
cv2_imshow(subtracted_image)
Output
Using the cv2.multiply() function, we achieve picture scaling by multiplying the first image by 0.5. The
cv2.multiply() function performs element-wise multiplication of the image's pixel values.
import cv2
import numpy as np
input_image = cv2.imread('/content/sunrise.jpeg')
scaling_factor = 0.4
cv2_imshow(input_image)
cv2_imshow(scaled_image)
Output
Division In computer vision, the division is used for image normalization and contrast adjustment. It is
also employed in several feature extraction methods. When working with huge images, the division
might be computationally expensive.
import numpy as np
input_image = cv2.imread('/content/montains.jpeg')
#normalization
normalized_image = cv2.divide(input_image, 1)
cv2_imshow(input_image)
cv2_imshow(normalized_image)
Output
Blending of Images
This is likewise image addition, but the images are given varied weights to create the illusion of blending
or transparency. The first image weights 0.7, whereas the second image has a weight of 0.3.
```import cv2
image1 = cv2.imread('/content/montains.jpeg')
image2 = cv2.imread('/content/air_balloons.jpeg')
cv2_imshow(image1)
cv2_imshow(image2)
cv2_imshow(blended_image)
Image processing operations such as blending and background subtraction make use of addition
and subtraction.
Normalization, contrast adjustment, and colour balance are all accomplished by division.
Subtraction and division are not commutative, but addition and multiplication are.
Subtraction and division are not associative, although addition and multiplication are.
Subtraction and division are distributive over each other, but addition and multiplication are not.
Each operation has distinct properties and applications, and a combination of these operations is
frequently utilised to do more complicated computer vision tasks.
Advanced mathematical operations are an essential part of computer vision and image processing. They
allow us to extract useful information from images, detect patterns, and perform complex tasks like
object recognition and tracking. These operations can be used to perform tasks like image filtering,
segmentation, feature extraction, and classification.
Image Filtering
Moreover, non-linear filters like median and bilateral filters are frequently employed.
Convolutional Operations
Semantic segmentation, object detection, and image classification are typical uses.
A few well-known convolutional neural networks are MobileNet, ResNet, VGG, and AlexNet.
Fourier Transform
The technique for converting images from the spatial to the frequency domain.
Edge detection, noise reduction, and image compression are typical uses.
In image processing, the discrete Fourier transform (DFT) and fast fourier transform (FFT) are
frequently utilized.
Wavelet Transform
The technique for converting images from the spatial to the frequency domain.
Involves breaking an image down into many wavelets with various sizes and orientations.
There are several wavelet families that are often utilised, including Haar, Daubechies, and
Coiflets.