Neural Network Toolbox - pattern recognition in images

  • Follow


I have just started using the Neural Network Toolbox for pattern
recognition and clustering. I don't have any experience with these
techniques and very little theoretical knowledge, but I am using the
Matlab help files as my learning tool. To start with pattern
recognition, I wanted to do what the following page is doing, but
without the need to use their toolbox:
http://www.neurosolutions.com/products/nsmatlab/appsum-textureclassification.html

So, basing myself on the code available at the bottom of that page and
Matlab help files, I did some modifications to be able to use without
that neurosolutions toolbox (see below). But then I reach a stage
where I have to use their function 'nsTest'  which I don't know
exactly what it is doing. They are using the trained network on the
whole image but I am not too sure how to achieve that.

Any help is greatly appreciated.

------
clear all
close all

A = imread('leopard.jpg');
a = A(:,:,1); % Use only one channel
[r,c] = size(a);

% Sample from the area of the image which consists of the leopard
trainImagesLeopard = [];
count = 1;
for i=126:5:175
    for j = 201:5:300
        imagetraintra  = a(i:i+4,j:j+4)';
        imagetraintrab = imagetraintra(:)';
        trainImagesLeopard = [trainImagesLeopard ;imagetraintrab];

        count = count + 1;
    end
end

% Assign a arbitary number to represent the class "leopard", here
number 1.
trainDesired1 = ones(count-1, 1);

% Sample images from the area of the figure which consists of the
background
trainImagesBackground = [];
count = 1;
for i=201:5:250
    for j = 1:5:100
        imagetraintra  = a(i:i+4,j:j+4)';
        imagetraintrab = imagetraintra(:)';
        trainImagesBackground =
[trainImagesBackground ;imagetraintrab];

        count = count + 1;
    end
end

% Assingn a arbitary number to represent the class "background", here
0
trainDesired2 = zeros(count-1,1);

% Combine the training data
trainImages  = double([trainImagesLeopard; trainImagesBackground])./
255;
trainDesired = double([trainDesired1;trainDesired2]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Neural network training
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);

% Set up Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

% Train the Network
[net,tr] = train(net,trainImages',trainDesired');

% Test the Network
outputs = net(trainImages');
errors = gsubtract(outputs,trainDesired');
performance = perform(net,trainDesired',outputs);


% Break up the entire image into small 5x5 images for use as testing
data

count = 1;
allImages = [];

for i=1:5:r
    for j = 1:5:c

        imagetraintra  = a(i:i+4,j:j+4)';
        imagetraintrab = imagetraintra(:)';
        allImages = [allImages ;imagetraintrab];

        count = count + 1;
    end
end
z = double(allImages);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Neural network testing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

tst = nsTest (net, z); %  nsTest is NeuroSolutions specific
0
Reply Jean 11/17/2010 4:50:45 PM


0 Replies
867 Views

(page loaded in 0.026 seconds)

Similiar Articles:













7/21/2012 5:03:07 PM


Reply: