Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How does a trained classifier label a picture by its own?

Asked by Lester Lim on 28 Jan 2013

How does a trained classifier label a picture by its own? Let's say I have a training set, train it using the LDA classifier and it shows me the accuracy/similarities. How do I use this to apply on the picture I want to label?

0 Comments

Lester Lim

Products

No products are associated with this question.

1 Answer

Answer by Image Analyst on 28 Jan 2013
Accepted answer

You have to do that in separate steps afterwards. Your classifier should give you some kinds of instructions for classifying pixels, for example, pixels darker than 130 are background, and pixels brighter than 130 are foreground.

8 Comments

Image Analyst on 29 Jan 2013

I'm not sure you've supplied enough info to answer, but I'd say yes. Run both sets of data and run them separately because you said that your data is so gigantic (I'm thinking several GB or more) that it won't fit into memory.

Lester Lim on 29 Jan 2013

Thanks for the guidance, Im trying it now and might get back to you later.

Lester Lim on 29 Jan 2013

Yup, calculated it to be 100+ GB. Pardon for being a newbie at this, but by running separately, do you mean this? Or should I put in as another GUI button?

data = importdata('Trial data4.mat');

features=data(:,1:end-1); %split data without labels

lable=data(:,end); %get the labels

trainSamples = im2double(features);%training samples

trainClasses = im2double(lable);%training labels

testSamples = im2double(features);%test samples

lableimage = reshape(handles.lableimage,[],1);

testClasses = im2double(handles.lableimage);%test labels

disp('GUI: trainSamples is')

class(trainSamples)

disp('GUI: testSamples is')

class(testSamples)

mLDA = LDA(trainSamples, trainClasses');

mLDA.Compute();

clear data

transformedTrainSamples = mLDA.Transform(trainSamples, 1);

transformedTestSamples = mLDA.Transform(testSamples, 1);

calculatedClasses = knnclassify(transformedTestSamples, transformedTrainSamples, trainClasses);

simmilarity = [];

for i = 1 : 1 : length(testClasses)

    similarity(i) = (testClasses(i)==calculatedClasses(i));

end

accuracy = sum(similarity) / length(testClasses);

fprintf('Testing: Accuracy is: %f %%\n', accuracy*100);

data = importdata('Trial data5.mat');

features=data(:,1:end-1); %split data without labels

lable=data(:,end); %get the labels

trainSamples = im2double(features);%training samples

trainClasses = im2double(lable);%training labels

testSamples = im2double(features);%test samples

lableimage = reshape(handles.lableimage,[],1);

testClasses = im2double(handles.lableimage);%test labels

disp('GUI: trainSamples is')

class(trainSamples)

disp('GUI: testSamples is')

class(testSamples)

mLDA = LDA(trainSamples, trainClasses');

mLDA.Compute();

clear data

transformedTrainSamples = mLDA.Transform(trainSamples, 1);

transformedTestSamples = mLDA.Transform(testSamples, 1);

calculatedClasses = knnclassify(transformedTestSamples, transformedTrainSamples, trainClasses);

simmilarity = [];

for i = 1 : 1 : length(testClasses)

    similarity(i) = (testClasses(i)==calculatedClasses(i));

end

accuracy = sum(similarity) / length(testClasses);

fprintf('Testing: Accuracy is: %f %%\n', accuracy*100);

guidata(hObject, handles);

Image Analyst

Contact us