1. Describe otsu's thresholding technique used for image segmentation.
1. Otsu’s method is a global image thresholding algorithm.
2. Otsu Thresholding, a value of the threshold isn’t chosen but is determined
automatically.
3. A bimodal image (two distinct image values) is considered.
4. The histogram generated contains two peaks. So, a generic condition would be
to choose a threshold value that lies in the middle of both the histogram peak
values.
5. Otsu's thresholding method involves iterating through all the possible threshold
values and calculating a measure of spread for the pixel levels each side of the
threshold, i.e. the pixels that either fall in foreground or background. The aim is
to find the threshold value where the sum of foreground and background spreads
is at its minimum.
6. The algorithm will be demonstrated using the simple 6x6 image shown below.
The histogram for the image is shown next to it. To simplify the explanation,
only 6 greyscale levels are used.
7. Syntax: cv2.threshold(source, thresholdValue, maxVal,
thresholdingTechnique)
1. Parameters:
2. source: Input Image array (must be in Grayscale).
3. thresholdValue: Value of Threshold below and above which pixel
values will change accordingly.
4. maxVal: Maximum value that can be assigned to a pixel.
5. thresholdingTechnique: The type of thresholding to be applied.
2. List the Limitation of Contour Detection for Image Segmentation and illustrate
how watershed algorithm solves this limitation.
Contour detection is a fundamental step in image processing and computer vision,
especially in tasks like image segmentation. However, it has several limitations:
1. Sensitivity to Noise: Contour detection methods can be sensitive to noise present
in the image, leading to inaccurate or fragmented contour detection.
2. Disconnected Contours: In complex scenes, contours may not form closed loops,
leading to disconnected segments that are challenging to interpret.
3. Dependence on Edge Strength: Many contour detection algorithms rely on
detecting edges based on intensity gradients, which may not always accurately
represent object boundaries, especially in the presence of texture or low contrast.
4. Over-Segmentation: Contour detection can lead to over-segmentation, where
boundaries are detected excessively, resulting in fine-grained segmentation that
may not correspond to meaningful object boundaries.
The watershed algorithm is a popular technique used to overcome some of these
limitations. It is based on the analogy of a topographic surface, where pixels in an image
are treated as elevation points. The algorithm starts by flooding the image from user-
defined markers, which represent the desired regions or objects. As the flooding
progresses, boundaries naturally form at the points where flooding from different
markers meet.
Here's how the watershed algorithm addresses the limitations of contour detection:
1. Noise Robustness: By considering the entire image as a topographic surface, the
watershed algorithm can smooth out noisy regions, leading to more robust
segmentation results.
2. Connected Segments: The watershed algorithm tends to produce connected
segments since it considers the entire region simultaneously. This helps in
preventing fragmented contours.
3. Boundary Detection: Instead of relying solely on intensity gradients, the watershed
algorithm considers spatial relationships between pixels. This allows it to detect
boundaries more accurately, even in regions with low contrast.
4. Controlled Segmentation: By seeding the watershed algorithm with markers
representing different regions or objects, users can control the segmentation
process, reducing the likelihood of over-segmentation.
3. Illustrate the working of Haar cascade.
The Haar cascade is a machine learning-based object detection algorithm that is used to
detect objects in images or video. It's particularly popular for detecting faces but can be
trained to detect other objects as well. Here's an overview of how the Haar cascade
works:
1. Integral Image Calculation: The algorithm begins by converting the input image
into an integral image. The integral image representation allows for fast calculation
of pixel sum values within any rectangular area of the image.
2. Haar-like Feature Calculation: Haar-like features are rectangular patterns that are
used to detect objects. These features are essentially the difference in the sum of
pixel intensities between adjacent rectangular regions within the image. Haar-like
features are calculated efficiently using the integral image representation.
3. Adaboost Training: Adaboost is a machine learning algorithm used to select a
subset of features that are most discriminative for the object being detected. During
training, Adaboost selects a set of weak classifiers (typically Haar-like features) and
combines them into a strong classifier. The weak classifiers are selected in a way
that minimizes the classification error.
4. Cascade of Classifiers: The Haar cascade consists of multiple stages, each
containing a subset of the selected weak classifiers. The stages are arranged in a
cascade fashion, where the output of one stage serves as input to the next stage.
Each stage consists of multiple weak classifiers, and the cascade is designed such
that the majority of non-object regions are rejected early in the process, leading to
computational efficiency.
5. Sliding Window Detection: To detect objects in an image, the Haar cascade applies
the cascade of classifiers to overlapping regions (windows) of the image. The size
of the sliding window matches the size of the object being detected, and the window
is moved across the image with a certain step size. At each position, the cascade of
classifiers is applied to determine whether the region contains the object of interest.
6. Non-Maximum Suppression: After detecting objects using the sliding window
approach, non-maximum suppression is applied to eliminate redundant detections.
This involves removing overlapping detections and selecting the most confident
detection in each region.