Edge Demo
>>%% Read Lena image
>>Lena = imread(‘lena.png’);
>>Figure, imshow(lena), title(‘Original image, color’);
>>%% Convert to monochrome *grayscale) using rgb2gray
>>lenaMono = rgb2gray(lena);
>>Figure, imshow(lenaMono), title(‘Original image, monochrome’);
>>%% Make a blurred/smoothed version
>>H = fspecial(‘gaussian’, [11 11], 4);
>>H
>> figure, surf(h);
lenaSmooth = imfilter(lenaMono, h);
>> %% Method 1 : Shift left and right, and show diff image
>> lenaL = lenaSmooth;
>> lenaL(;, [1:(end - 1) ] ) = lenaL(:, [2:end]);
>> lenaR = lenaSmooth;
>>lenaR(:, [2:(end)]) = lenaR(:, [1:(end - 1)]);
>>lenaDiff = double(lenaR) - double(lenaL);
>>Figure, imshow(lenaDiff, []), title(“Diff”)’
>> %% Method 2 : Canny edge detector
>> cannyEdges = edge(lenaMono, ‘canny’);
>>figure, imshow(cannyEdge), title(‘edge canny’);
>> cannyEdges = edge(lenaSmooth, ‘canny’);
>>figure, imshow(cannyEdge), title(‘edge canny’);
>> %% Method 3: Lapacian of Gaussian
>> logEdges = edge(lenaMono, ‘log’);
>> figure, imshow(logEdge), title(‘log’);
Doc edge