SlideShare a Scribd company logo
1 of 2
Download to read offline
Tutorial 3

Question 1
Write a program to implement Sobel edge detector using 4 convolution masks and the
approximate gradient magnitude calculation.

Question 2
Write a program to implement corner detector. The neighborhood is q x q, where q is the
first input of the function. The second input is the threshold. Highlight the location of
each detected corner by drawing a box in the neighborhood.

                                  Tutorial 3 Solution

Question 1
function sobeled4(t)
%   to perform Sobel edge detection using 4 convolution masks
%   and approximate gradient magnitude calculation
%   threshold is t

[f_name, f_path] = uigetfile('*.bmp', 'Select an input image');
in_name = [f_path, f_name];
image = imread(in_name);
[height, width] = size(image);
imshow(image)

h = fspecial('sobel');
sx = imfilter(image, h);
v = h';
sy = imfilter(image, v);
d = [2 1 0; 1 0 -1; 0 -1 -2];
sd = imfilter(image, d);
a = [0 1 2; -1 0 1; -2 -1 0];
sa = imfilter(image, a);
for i = 1:height
    for j = 1:width
        mag(i,j) = abs(sx(i,j))+abs(sy(i,j))+abs(sd(i,j))+abs(sa(i,j));
        if mag(i,j) > t
             sedimage(i,j) = 255;
        else
             sedimage(i,j) = 0;
        end
    end
end

figure
imshow(sedimage)

% save edge detection result
out_name = [f_path, 'sed4_', f_name];
imwrite(sedimage, out_name, 'BMP');

end
Question 2
Select image
Compute Gx, Gy
Compute Gx2, Gy2, GxGy
For each pixel
        Build matrix C
        Use svd to compute λ
        If λ2 is larger than threshold
                Save coordinates and λ2

Use sort to sort λ2 in decreasing order
Delete neighboring corners with lower λ2
Overlay corners on original image and show result

More Related Content

What's hot

Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Matlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionMatlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionDataminingTools Inc
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Presentation 2(power point presentation) dis2016
Presentation 2(power point presentation) dis2016Presentation 2(power point presentation) dis2016
Presentation 2(power point presentation) dis2016Daniel Omunting
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmJyotiraman De
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs fileshubham kanojia
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_projectManish Jauhari
 
Region filling
Region fillingRegion filling
Region fillinghetvi naik
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manualVivek Kumar Sinha
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics ProgramesAbhishek Sharma
 
4.5 tan and cot.ppt worked
4.5   tan and cot.ppt worked4.5   tan and cot.ppt worked
4.5 tan and cot.ppt workedJonna Ramsey
 
Dip 5 mathematical preliminaries
Dip 5 mathematical preliminariesDip 5 mathematical preliminaries
Dip 5 mathematical preliminariesManas Mantri
 
4.5 sec and csc worked 3rd
4.5   sec and csc worked 3rd4.5   sec and csc worked 3rd
4.5 sec and csc worked 3rdJonna Ramsey
 
Lecture03 p1
Lecture03 p1Lecture03 p1
Lecture03 p1aa11bb11
 
Turbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse ProgrammingTurbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse ProgrammingHuzaifa Butt
 
3 projection computer graphics
3 projection computer graphics3 projection computer graphics
3 projection computer graphicscairo university
 

What's hot (20)

Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Matlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionMatlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge Detection
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Presentation 2(power point presentation) dis2016
Presentation 2(power point presentation) dis2016Presentation 2(power point presentation) dis2016
Presentation 2(power point presentation) dis2016
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs file
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_project
 
Region filling
Region fillingRegion filling
Region filling
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
Module 6.7
Module 6.7Module 6.7
Module 6.7
 
4.5 tan and cot.ppt worked
4.5   tan and cot.ppt worked4.5   tan and cot.ppt worked
4.5 tan and cot.ppt worked
 
Dip 5 mathematical preliminaries
Dip 5 mathematical preliminariesDip 5 mathematical preliminaries
Dip 5 mathematical preliminaries
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
 
4.5 sec and csc worked 3rd
4.5   sec and csc worked 3rd4.5   sec and csc worked 3rd
4.5 sec and csc worked 3rd
 
Lecture03 p1
Lecture03 p1Lecture03 p1
Lecture03 p1
 
Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
 
Turbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse ProgrammingTurbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse Programming
 
3 projection computer graphics
3 projection computer graphics3 projection computer graphics
3 projection computer graphics
 

Similar to Tutorial 3 Solution Corner and Edge Detection

Similar to Tutorial 3 Solution Corner and Edge Detection (20)

matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Test
TestTest
Test
 
Test
TestTest
Test
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
 
Notes on image processing
Notes on image processingNotes on image processing
Notes on image processing
 
Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLAB
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer VisionTemplateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
 
ECE 565 Project1
ECE 565 Project1ECE 565 Project1
ECE 565 Project1
 
Primitives
PrimitivesPrimitives
Primitives
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Test
TestTest
Test
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcode
 

More from Kinni MEW (15)

Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Test
TestTest
Test
 
Lec1
Lec1Lec1
Lec1
 

Tutorial 3 Solution Corner and Edge Detection

  • 1. Tutorial 3 Question 1 Write a program to implement Sobel edge detector using 4 convolution masks and the approximate gradient magnitude calculation. Question 2 Write a program to implement corner detector. The neighborhood is q x q, where q is the first input of the function. The second input is the threshold. Highlight the location of each detected corner by drawing a box in the neighborhood. Tutorial 3 Solution Question 1 function sobeled4(t) % to perform Sobel edge detection using 4 convolution masks % and approximate gradient magnitude calculation % threshold is t [f_name, f_path] = uigetfile('*.bmp', 'Select an input image'); in_name = [f_path, f_name]; image = imread(in_name); [height, width] = size(image); imshow(image) h = fspecial('sobel'); sx = imfilter(image, h); v = h'; sy = imfilter(image, v); d = [2 1 0; 1 0 -1; 0 -1 -2]; sd = imfilter(image, d); a = [0 1 2; -1 0 1; -2 -1 0]; sa = imfilter(image, a); for i = 1:height for j = 1:width mag(i,j) = abs(sx(i,j))+abs(sy(i,j))+abs(sd(i,j))+abs(sa(i,j)); if mag(i,j) > t sedimage(i,j) = 255; else sedimage(i,j) = 0; end end end figure imshow(sedimage) % save edge detection result out_name = [f_path, 'sed4_', f_name]; imwrite(sedimage, out_name, 'BMP'); end
  • 2. Question 2 Select image Compute Gx, Gy Compute Gx2, Gy2, GxGy For each pixel Build matrix C Use svd to compute λ If λ2 is larger than threshold Save coordinates and λ2 Use sort to sort λ2 in decreasing order Delete neighboring corners with lower λ2 Overlay corners on original image and show result