0% found this document useful (0 votes)
15 views6 pages

Lab 9

The lab report details various image segmentation techniques applied to a grayscale image, including Otsu's Thresholding, Multilevel Thresholding, Adaptive Thresholding, and others. Each technique is compared in terms of purpose, effects, and limitations, highlighting their suitability for different scenarios in image analysis. The report concludes by emphasizing the importance of segmentation in simplifying image data and enhancing object-based feature extraction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Lab 9

The lab report details various image segmentation techniques applied to a grayscale image, including Otsu's Thresholding, Multilevel Thresholding, Adaptive Thresholding, and others. Each technique is compared in terms of purpose, effects, and limitations, highlighting their suitability for different scenarios in image analysis. The report concludes by emphasizing the importance of segmentation in simplifying image data and enhancing object-based feature extraction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Course: CS-406 Digital Image Processing

Lab Report 09

Submitted By:

Muhammad Jahangir (21-CS-089)

Basit Ali (21-CS-104)

Muhammad Alrayan (21-CS-107)

Section B

Submitted To:
Ms. Syeda Aimal Fatima
Department of Computer Science HITEC University Taxila
Task 1
Code
clc;
clear;
close all;

% Load grayscale image


img = imread('cameraman.tif'); % Replace with your image
if size(img, 3) == 3
img = rgb2gray(img);
end
figure;
imshow(img);
title('Original Grayscale Image');

% 1. Otsu's Thresholding
level = graythresh(img);
bw_otsu = imbinarize(img, level);
figure;
subplot(2, 4, 1);
imshow(bw_otsu);
title('Otsu Thresholding');

% 2. Multilevel Thresholding
levels = multithresh(img, 2); % Example with 2 thresholds
seg_img = imquantize(img, levels);
seg_img_display = label2rgb(seg_img);
subplot(2, 4, 2);
imshow(seg_img_display);
title('Multilevel Thresholding');

% 3. Adaptive Thresholding
bw_adaptive = imbinarize(img, 'adaptive', 'ForegroundPolarity', 'dark',
'Sensitivity', 0.5);
subplot(2, 4, 3);
imshow(bw_adaptive);
title('Adaptive Thresholding');

% 4. Gray Connected Segmentation


seed_point = [100, 100]; % Change as needed
bw_grayconn = grayconnected(img, seed_point(1), seed_point(2), 0.1); %
Tolerance set to 0.1
subplot(2, 4, 4);
imshow(bw_grayconn);
title('Gray Connected Segmentation');

% 5. Lazy Snapping (requires user interaction)


mask = false(size(img));
mask(75:85, 75:85) = true; % Example foreground seed
bw_lazysnap = lazysnapping(img, mask, ~mask);
subplot(2, 4, 5);
imshow(bw_lazysnap);
title('Lazy Snapping');
% 6. Superpixels
num_superpixels = [300, 600, 900];
figure;
for i = 1:3
L = superpixels(img, num_superpixels(i));
BW = boundarymask(L);
img_superpixel = imoverlay(img, BW, 'cyan');
subplot(1, 3, i);
imshow(img_superpixel);
title(['Superpixels: ', num2str(num_superpixels(i))]);
end

% 7. GrabCut Segmentation (requires user-defined ROI)


roi = [60 60 100 100]; % Example rectangle [x, y, width, height]
mask = zeros(size(img), 'uint8');
mask(roi(2):(roi(2)+roi(4)), roi(1):(roi(1)+roi(3))) = 1;
bw_grabcut = grabcut(img, mask);
figure;
imshow(bw_grabcut);
title('GrabCut Segmentation');

% 8. Active Contour Segmentation


mask = zeros(size(img));
mask(30:100, 30:100) = 1; % Example initialization
bw_activecontour = activecontour(img, mask, 200);
figure;
imshow(bw_activecontour);
title('Active Contour Segmentation');
Output
Task 2

Comparison Table of Segmentation Techniques


Technique Name Purpose Effects
Otsu’s Thresholding Automatically determines the Efficient for bimodal
optimal global threshold to histograms, produces a
segment foreground from binary image. Struggles with
background. images having uneven
lighting.
Multilevel Thresholding Segments the image into Generates multiple
multiple regions based on segmented regions. Useful
intensity levels. for multi-object
segmentation but
computationally intensive.
Adaptive Thresholding Handles images with varying Effective for uneven
lighting by computing illumination but might over-
thresholds locally for small segment in highly textured
regions. areas.
Gray Connected Segments connected regions Extracts regions connected
in the image starting from a by intensity. Limited by the
seed point and a similarity initial seed point selection.
threshold.
Lazy Snapping Interactive segmentation Allows fine control of
using foreground and segmentation but requires
background labels. manual interaction.
Superpixels Groups pixels into Provides a higher-level
perceptually meaningful representation of the image;
regions (superpixels) for affected by the choice of the
advanced analysis. number of superpixels.
Grab Cut Iterative segmentation using Segments objects effectively
graph cuts, starting with a with minimal input; may fail
bounding box around the with complex boundaries or
object. low contrast.
Active Contour Refines segmentation by Suitable for smooth object
evolving a contour based on boundaries; sensitive to
object boundaries and initialization and may leak on
gradients. weak edges.

Explanation of Each Technique

Otsu’s Thresholding
Otsu's method is a global thresholding technique that finds an optimal threshold value to minimize
intra-class variance in a grayscale image. It works best on images with a bimodal intensity histogram but
struggles with non-uniform lighting.

Multilevel Thresholding
This technique extends Otsu's method by dividing the image into multiple regions based on intensity
thresholds. It is effective for images with multiple objects or regions of interest but requires more
computational resources.

Adaptive Thresholding
Unlike global thresholding, adaptive thresholding calculates thresholds for smaller image regions,
making it suitable for images with varying illumination. However, it might over-segment textured areas.

Gray Connected
Gray connected segmentation uses a seed point and similarity thresholds to extract connected regions
with similar intensities. It is simple but highly dependent on the correct seed point selection and
threshold.

Lazy Snapping
This semi-automatic technique requires the user to mark foreground and background regions, which are
then segmented using graph-based algorithms. It provides high accuracy but is time-consuming due to
manual input.

Superpixels
Superpixel segmentation reduces an image into small, visually meaningful regions (superpixels). These
are useful for downstream tasks like object detection or boundary detection. The outcome depends
heavily on the number of superpixels selected.

Grab Cut
Grab Cut is a powerful iterative segmentation method that starts with a rough bounding box around the
object and refines the segmentation using graph cuts. It works well for complex backgrounds but
struggles with low contrast or ambiguous edges.
Active Contour
Active contours (or snakes) evolve a curve to fit object boundaries. It is ideal for smooth, well-defined
edges but sensitive to poor initialization and weak gradients.

Conclusion
What is Segmentation?

Image segmentation is the process of dividing an image into meaningful regions, such as foreground and
background or distinct objects. It simplifies image analysis and enables object detection, recognition,
and other high-level computer vision tasks.

Why Do We Need Segmentation?

Segmentation helps in:


1. Identifying objects of interest.
2. Reducing complexity for image analysis.
3. Enhancing object-based feature extraction for tasks like classification, detection, and tracking.

Advantages of Segmentation

- Simplifies complex image data.


- Improves the accuracy of object-based analysis.
- Provides insights into image structure and regions.

Limitations of Segmentation

- Performance depends on image quality (e.g., lighting, noise, contrast).


- Computational complexity varies across techniques.
- Some methods require manual input or specific initialization.

Each segmentation technique has its purpose and is suitable for different scenarios. For instance, Otsu’s
and adaptive thresholding are quick methods for binarization, while advanced techniques like Grab Cut
or active contours provide higher accuracy for object segmentation. Selecting the appropriate method
depends on the image characteristics and the specific application requirements.

You might also like