TD 4 Computer Vision
TD 4 Computer Vision
January 2017
Travaux Diriges #4
Objectives:
1) Learn how to implement the basic binary morphological operations
2) Learn how to perform boundary extraction
3) Learn how to fill object holes
4) Learn how to label objects in a binary
5) Learrn how to implement edge detection and associated techniques
Procedure:
1) Load and display the image morph.bmp, then by executing the following
statement:
2) Create and display the eroded; subtract the original image from its eroded
version to get the boundary image using the statement:
se = strel('square',3);
I_ero = imerode(I, se);
subplot(2,2,2), imshow(I), title('Eroded Image');
I_bou = imsubtract(I, I_ero);
subplot(2,2,3), imshow(I_bou), title('Boundary Extraction');
I_perim = bwperim(I,8);
subplot(2,2,4), imshow(I_perim), title('Boundary using bwperim');
I = imread (‘morph.bmp’);
figure,
subplot(2,2,1), imshow(I), title(‘Original Image’);
Original Image Eroded Image
Show that the I_perim image is exactly the same as the I_bou
% Showing that the I_perim image is exactly the same as the I_bou
figure,
I_perim = im2double(I_perim);
I_difference = imsubtract(I_perim, I_bou);
imshow(I_difference), title(' Difference between I_perim and I_bou: None');
% Or looking for the highest value in the difference image
max(I_difference(:))
Difference between I-perim and I-bou: None
4) Region filling:
Let fill holes within objects in a interactive manner as:
% let use imfill in a intereactive mode: click to select holes (black),
% shift-click for last selection
I_fill2 = imfill(I);
figure,
imshow(I_fill2), title('Interactive fill');
Labeled image
What other options can you choose to make it easer to to tell the different labelled regions apart?
6) Thinning:
Let use bwmorph to perform thinning on the original imagge with 5 iterations:
What happens if we specify 10, 15, or Inf (infinitely many) iterations instead?
7) Thickening:
I_thick = bwmorph(I, 'thicken', 5);
figure, imshow(I_thick), title('Thicken, 5 iterations');
Thicken, 5 iterations
How MATLAB knows when to stop thickening an object”? (hint: use Inf to check)
8) Skeletonization
I_skel = bwmorph(I, 'skel', Inf);
figure, imshow(I_skel), title('Skeleton of image');
Skeleton of image
What does the t1 variable represent? Threshold value (if now threshold value is
suggested, EDGE automatically chooses a value)
Let create a noisy image and observe the edge detection in a noisy image:
How did the Prewitt edge detector perform in the presence of noise compared
to no noise?
Did MATLAB use a different threshold value for the noisy image?
Try using different threshold values. Do these different values affect the
operator response to noise?
How does the threshold value affect the edges of the object?
10) Edge Detection using Sobel Operator
I = imread('lenna.tif');
figure,
subplot(2,2,1), imshow(I), title('Original Image');
[I_sob1, t1] = edge(I, 'Sobel');
subplot(2,2,2), imshow(I_sob1),title('Sobel, default threshold');
How does the Sobel operator compare with the Prewitt operator with and
without noise?
Turning off thinning during Sobel & Directions of edge detection
I = imread('lenna.tif');
figure,
subplot(2,2,1), imshow(I), title('Original Image');
[I_rob1, t1] = edge(I, 'Roberts');
subplot(2,2,2), imshow(I_rob1),title('Roberts, default threshold');
Compare the Roberts operator with the Sobel and Prewitt operators. How does it
hold up to noise?
12) Edge Detection using Laplacian of a Gaussian Operator
13) Edge Detection using Canny Operator
imshow(I); then
imshow(I), impixelinfo
These commands can be used on binary, intensity, and truecolor images.
Move the cursor on the image, what is the highest value (intensity level) that you
read?
14) To display indexed images, we must specify the color map along with
the image data. Display the color mapmed image trees.tif as follow:
imshow(X, map), impixelinfo
Hover your pixel on the image? What is the information provided by impixelinfo?
15) Display images side-by-side using subplot as:
subplot(1,2,2), imshow(X,map)
subplot(1,2,1), imshow(X_gray)
16) Let save the RGB image X_rgb as ‘rgb_trees.jpg’ using the following
command:
imwrite(X_rgb, ‘rgb_trees.jpg’);
Go to your Documents/MATLAB folder to check on the newly save file.