Edge detection MATLAB source code

This page covers matlab code for edge detection in the figure provided as input

Edge Detection Methods Basics

•  Edges are those places in an image that correspond to object boundaries. Edges are pixels where image brightness changes abruptly
•  An edge is a property attached to an individual pixel and is calculated from the image function behavior in a neighborhood of the pixel.
•  It is a vector variable (magnitude of the gradient, direction of an edge) .

Edge detection basics

Edge Detection:
•  Edge information in an image is found by looking at the relationship a pixel has with its neighborhoods.
•  If a pixel's gray-level value is similar to those around it, there is probably not an edge at that point.
•  If a pixel's has neighbors with widely varying gray levels, it may present an edge point.

Edge detection Algorithm

edge detection algorithm

matlab code

clear all;
close all;
clc;

G=15; %Threshold value, one can vary this and observe the change in the outputs
f=imread('pepper.gif');

figure;imshow(f);
for k1=3:(length(f)-3)
for k2=3:(length(f)-3)
if( abs((f(k1,k2)- f(k1,k2+1)) > G) | ...
abs((f(k1,k2)- f(k1,k2-2)) > G) | ...
abs((f(k1,k2)- f(k1-1,k2)) > G) | ...
abs((f(k1,k2)- f(k1-1,k2+2)) > G) | ...
abs((f(k1,k2)- f(k1-1,k2-2)) > G) | ...
abs((f(k1,k2)- f(k1+2,k2-2)) > G) | ...
abs((f(k1,k2)- f(k1-1,k2+2)) > G) | ...
abs((f(k1,k2)- f(k1+2,k2+2)) > G) );
x(k1,k2)=1;
else
x(k1,k2)=0;
end
end
end
figure;imshow(x);

DOWNLOAD Input Image

You can either download image for the code from following link or you can have your own image as the input for the edge detection matlab code.

https://www.gergltd.com/cse486/project2/pepper.gif

Input to the MATLAB Code

Edge detection matlab input

Output from the MATLAB Code

Edge detection matlab output

Useful Links to MATLAB codes

Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation  Time off estimation corr  Freq off estimation corr  channel estimation  11a WLAN channel  PN sequence generation  OFDMA Tx Rx  AES DES  carrier aggregation  CCDF  FIR Filter  IIR Filter  Low Pass FIR  Viterbi decoder  CRC8 CRC32 

RF and Wireless tutorials

WLAN  802.11ac  802.11ad  wimax  Zigbee  z-wave  GSM  LTE  UMTS  Bluetooth  UWB  IoT  satellite  Antenna  RADAR