0% found this document useful (0 votes)
13 views11 pages

TD 4 Computer Vision

yty

Uploaded by

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

TD 4 Computer Vision

yty

Uploaded by

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

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');

3) Perform boundary extraction using the bwperim function

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

Boundary Extraction Boundary using bwperim

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');

What other parameter can be specified when using imfill? Location


5) Selecting and labelling objects:
I7 = grayslice(I1, 4); I8 = grayslice(I1, 2);

Labeled image

What do the different shades of gray represent?

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:

I_thin = bwmorph(I, 'thin', 5);


figure, imshow(I_thin), title('Thinning, 5 iterations');
Thinning, 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

What happens when we specify a higher number of 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

edge Find edges in intensity image.


edge takes an intensity or a binary image I as its input, and returns a
binary image BW of the same size as I, with 1's where the function
finds edges in I and 0's elsewhere.

edge supports six different edge-finding methods:

9) Edge Detection using Prewitt Operator


I = imread('lenna.tif');
figure,
subplot(2,2,1), imshow(I), title('Original Image');
[I_prw1, t1] = edge(I, 'prewitt');
subplot(2,2,2), imshow(I_prw1),title('Prewitt, default threshold');

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:

I_noise = imnoise(I, 'gaussian');


[I_prw2, t2] = edge(I_noise, 'prewitt');
subplot(2,2,3), imshow(I_noise), title('Image with noise');
subplot(2,2,4), imshow(I_prw2), title('Prewitt on noisy image');
Original Image Prewitt, default threshold

Image with noise Prewitt on 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');

I_noise = imnoise(I, 'gaussian');


[I_sob2, t2] = edge(I_noise, 'Sobel');
subplot(2,2,3), imshow(I_noise), title('Image with noise');
subplot(2,2,4), imshow(I_sob2), title('Sobel on noisy image');

Original Image Sobel, default threshold

Image with noise Sobel on noisy image

How does the Sobel operator compare with the Prewitt operator with and
without noise?
Turning off thinning during Sobel & Directions of edge detection

I_sob3 = edge(I, 'sobel', 'nothinning');


figure,
subplot(1,2,1), imshow(I_sob1), title('Sobel with thinning');
subplot(1,2,2), imshow(I_sob3), title('Soble, without thinning');
Sobel with thinning Soble, without thinning

[I_sob4, t, I_sobv, I_sobh] = edge(I, 'sobel');


figure,
subplot(2,2,1), imshow(I), title('Original Image');
subplot(2,2,2), imshow(I_sob4), title('Complete Sobel');
subplot(2,2,3), imshow(abs(I_sobv), []), title('Soble Vertical');
subplot(2,2,4), imshow(abs(I_sobh), []), title('Sobel Horizontal');
11) Edge Detection using Roberts Operator

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');

I_noise = imnoise(I, 'gaussian');5


[I_rob2, t2] = edge(I_noise, 'Roberts');
subplot(2,2,3), imshow(I_noise), title('Image with noise');
subplot(2,2,4), imshow(I_rob2), title('Roberts on noisy image');

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.

NEXT: Work on your Lab 1 Assignment

You might also like