f、α^2/αx^2*h
Δ^2 = α^2f/αx^2 + α^2f/αy^2
Canny Edge Operator
Gradients -> edges
1. smoothing derivatives to suppress noise and compute gradient.
2. threshold to find regions of “significant” gradient
3. thin to get localized edge pixels
The canny edge detector
% for your eyes only
pkg load image;
frizzy = imread('frizzy.png');
froomer = imread('froomer.png');
imshow(frizzy);
imshow(froomer);
frizzy_gray = rgb2gray(frizzy);
froomer_gray = rgb2gray(froomer);
frizzy_edges = edge(frizzy_gray, 'canny');
froomer_edges = edge(froomer_gray, 'canny');
imshow(frizzy_edges);
imshow(froomer_edges);
imshow(frizzy_edges & froomer_edges);
In the real world
f(x)
d/dx*f(x)
Finite differences responding to noise
Increasing noise
Solution: smooth first
f, h, h*f, α/αx*(h*f)
where is the edge?
for sigma = 1:3:10
h = fspecial('gaussian', fsize, sigma);
out = imfilter(im, h);
imshow(out);
pause;
end
Gradient
Differential operators – when applied to the image returns some derivatives.
Model these “operators” as masks/kernels that compute the image gradient function.
Discrete gradient
For discrete data, we can approximate using finite differences.
pkg load image;
function result = select_gdir(gmag, gdir, mag_min, angle_low, angle_high)
result = gmag >= mag_min
endfunction
img = double(imread('octagon.png'))/255.;
imshow(img);
[gx gx] = imgradientxy(img, 'sobel');
imshow((gy + 4) / 8);
[gmag gdir] = imgradient(gx, gy);
imshow(gmag / (4 * sqrt(2)));
my_grad = select_gdir(gmag, gdir, 1, 30, 60);
Edges
Origin of Edges
-surface normal discontinuity
-depth discontinuity
-surface color discontinuity
-illumination discontinuity
Edges seem to occur “change boundaries” that are related to shape or illumination.
A stripe on a sign is not such a boundary.
Edge Detection
Basic idea: look for a neighborhood with strong signs of change.
Problems:
– neighborhood size
– how to detect change
intensity function (along horizontal scanline)
first derivative
-edges correspond to extrema of derivative
Template matching
Scene
Template(mask)
Detected template
Correlation map
pkg load image;
function [yIndex xIndex] = find_template_2D(template, img)
endfunction
tablet = imread('tablet.png');
imshow(tablet);
glyph = tablet(75:165, 150:185);
imshow(plyph);
[y x] = find_template_2D(glyph, tablet);
disp([y x]);
1D (nx)correlation
Signal
Filter
Normalized cross-correlation
Matlab cross-correlation doc
onion = rgb2gray(imread(‘onion.png’));
peppers = rgb2gray(imread(‘peppers.png’));
imshowpair(peppers, onion,’montage’)
Matlab cross-correlation doc
c = normxcorr2(onion,peppers);
figure, surf(c), shading flat;
pkg load image;
function index = find_template_1D(t, s)
endfunction
s = [-1 0 0 1 1 1 0 -1 -1 0 1 0 0 -1];
t = [1 1 0];
disp('Signal:'), disp([1:size(s, 2); s]);
disp('Template:'), disp([1:size(t, 2); t]);
index = find_template_1D(t, s);
disp('Index:'), disp(index);
Median filter
10 15 20
23 90 27
33 31 30
sor-> 10 15 20 23 27 30 31 33 90
replace
10 15 20
23 27 27
33 31 30
Median filter is smooth nicer
pkg load image;
img = imread('moon.png');
imshow(img);
%% Add salt & pepper noise
noisy_img = imnoise(img, 'salt & pepper', 0.02);
imshow(noisy_img);
median_filtered = medfilt2(noisy_img);
imshow(median_filtered);
Practice with linear filters
original
filter
0 0 0
0 1 0
0 0 0
shifted left by 1 pexel
0 0 0
0 0 1
0 0 0
blur
1 1 1
1 1 1
1 1 1
sharpening filter
0 0 0 1 1 1
0 2 0- 1 1 1
0 0 0 1 1 1
unsharp mask
Linear Operation
division is a linear operation?
true becase (x + y)/z = x/z + y/z
Boundary Issues
full, same, valid
Boundary issues
methods:
clip filter(black):imfilter(f,g,0)
wrap around(f,g,’circular’)
copy edge(f,g,’replicate’)
reflect across edge(f,g,’symmetric’)
pkg load image;
img = imread('fall-leaves.png');
imshow(img);
filter_size = 21;
filter_sigma = 3;
filter = fspecial('gaussian', filter_size, filter_sigma);
smoothed = imfilter(img, filter, 0);
The reflection method of handling boundary conditions in filtering is good because
the created imagery has the same statistic as the original image