deriv

Contents

open file

file = 'corners1.jpg';
%file = 'binary_blobs.jpg';
%file='hallway.jpg'
%file = 'checks.jpg';
rgb = imread(file);
rgb2 = imresize(rgb,0.25);
g = rgb2gray(rgb2);
im = im2double(g);
imshow(im);
clear rgb rgb2 g
dmax = max(max(im));
dmin = min(min(im));
zm = 0.5*(dmax+dmin);
fprintf('mid level %g\n',zm);
mid level 0.411765

first moments

m0 = [ 1 2 1; 2 4 2; 1 2 1];
m1 = [ -1 0 1; -2 0 2; -1 0 1];
m2 = [ -1 -2 -1; 0 0 0; 1 2 1];
a0 = imfilter(im,m0);
a1 = imfilter(im,m1);
a2 = imfilter(im,m2);
slope = sqrt(a1.^2 + a2.^2);
gmax1 = max(max(slope));
slope = slope/gmax1;
imshow(2*slope);

second moments

b11 = imfilter(a1,m1);
b22 = imfilter(a2,m2);
b12 = imfilter(a1,m2);
b21 = imfilter(a2,m1);
br = (b11+b22)/2;
dmax = max(max(br));
dmin = min(min(br));
gmax2 = max(dmax,-dmin);
bipolar_image(2*br/gmax2);

corner operator

bc = (b11-b22);
bs = 2*b12;
ac = a1.^2 - a2.^2;
as = 2*a1.*a2;
e = bc.*as-bs.*ac;
dmax = max(max(e));
dmin = min(min(e));
gmax3 = max(dmax,-dmin);
bipolar_image(e/gmax3);
bipolar_image(e,a0/16,0.01);

derivative montage

----------------
| a0 | ax | as |
----------------
| ay | br | bs |
----------------
| ac | bc | e  |
----------------
[r c] = size(im);
data = ones(3*r,3*c);
ri = 1:r;
ci = 1:c;
% column 1
data(ri,ci)=a0/16;
data(r+ri,ci)=(a2/3+1)/2;
data(2*r+ri,ci)=(ac/9+1)/2;
% column 2
data(ri,c+ci)=(a1/3+1)/2;
data(r+ri,c+ci)=(br/12+1)/2;
data(2*r+ri,c+ci)=(bc/12+1)/2;
% column 3
data(ri,2*c+ci)=(as/9+1)/2;
data(r+ri,2*c+ci)=(bs/12+1)/2;
data(2*r+ri,2*c+ci)=abs(e/20);

imshow(imresize(data,1/3));