Demo of RBF learning applied to low-level vision

David Young

Radial basis functions can be trained to respond to image texture. This is illustrated here.

Contents

Setup

See http://module1a.html for setup information if you want to run the code yourself

Read in two images, with rather different structures, and display them, then preprocess with a centre-surround mask.

image1 = teachimage('edin_lib.bmp');
image2 = teachimage('butterflies1.bmp');

% Preprocessing
filt = fspecial('log', 5, 0.5);
cc1 = conv2(image1, filt, 'valid');
cc2 = conv2(image2, filt, 'valid');

figure(1); imshow(cc1, []); figure(2); imshow(cc2, []);

Set sampling parameters

As for the previous demo, we sample the image and place the samples in an array.

In this case we also set up targets for training. The target for the first image is -1, and for the second it is +1.

hsize = 10;   % patch size
nsamp = 200;  % number of samples for training

% Get samples
p1 = imsample(cc1, hsize, nsamp);
p2 = imsample(cc2, hsize, nsamp);
[len, nsamp] = size(p1);         % get size of p conveniently

p = [p1 p2];        % Put all the samples into one array

% Get targets
t1 = -ones(1, nsamp);
t2 = ones(1, nsamp);

t = [t1 t2];

Create and train the rbf network

We use the "exact" RBF network from the Matlab toolbox.

The warning that is printed is not a significant problem in this case.

spread = 4;                     % unit width parameter
net = newrbe(p, t, spread);     % training is one-pass

Test on the original samples

We expect perfect performance from this kind of net.

y1 = sim(net, p1);
y2 = sim(net, p2);
if max(abs(y1 + 1)) < 0.0001; disp('outputs 1 all close to -1'); end
if max(abs(y2 - 1)) < 0.0001; disp('outputs 2 all close to +1'); end
outputs 1 all close to -1
outputs 2 all close to +1

Test on new samples

The means of the outputs are somewhat different, but not as strongly as we might hope. The histograms show the difference in response more clearly - although there is much overlap, a large subset of library pixels are distinctive, and look quite different from the butterfly pixels.

p1 = imsample(cc1, hsize, nsamp);   % New random samples
p2 = imsample(cc2, hsize, nsamp);

y1 = sim(net, p1);
y2 = sim(net, p2);

meany1 = mean(y1), meany2 = mean(y2) % print mean outputs

figure(3);
hist(y1, -5:0.5:5);
title('Histogram of unit responses for library image');
figure(4);
hist(y2, -5:0.5:5);
title('Histogram of unit responses for butterfly image');
meany1 =
    0.1569
meany2 =
    0.6160