How I can write code for training and then do classification using naive Bayes either image is noisy or not ?

2 views (last 30 days)
I am a new user of MATLAB and want to do training and classification using naive Bayes. I have done it with confusion matrix but want to take result in the form of image. I am dealing with noisy images and want to classify either a given image is noisy or not?
I have matrix of features and matrix of (defined) Labels, How I can train and then do classification (using some sample image) either is it noisy or not ?
Please help, I shall be very thankful to you. Waiting for your kind response.

Answers (1)

Image Analyst
Image Analyst on 18 May 2017
I haven't used it yet, but have you tried putting your feature vectors into fitcnb()?
  5 Comments
shafaq nisar
shafaq nisar on 4 Jun 2017
clear all; clc;
folder = 'gambar 1'; dirImage = dir( folder );
numData = size(dirImage,1);
M ={} ;
for i=1:numData nama = dirImage(i).name; if regexp(nama, '(lion|tiger)-[0-9]{1,2}.jpg') B = cell(1,2); if regexp(nama, 'lion-[0-9]{1,2}.jpg') B{1,1} = double(imread([folder, '/', nama])); B{1,2} = 1; elseif regexp(nama, 'tiger-[0-9]{1,2}.jpg') B{1,1} = double(imread([folder, '/', nama])); B{1,2} = -1; end M = cat(1,M,B); end end
numDataTrain = size(M,1); class = zeros(numDataTrain,1); arrayImage = zeros(numDataTrain, 300 * 300);
for i=1:numDataTrain im = M{i,1} ; im = rgb2gray(im); im = imresize(im, [300 300]); im = reshape(im', 1, 300*300); arrayImage(i,:) = im; class(i) = M{i,2}; end
SVMStruct = svmtrain(arrayImage, class);
lionTest = double(imread('gambar 1/lion-test.jpg' )); lionTest = rgb2gray(lionTest); lionTest = imresize(lionTest, [300 300]); lionTest = reshape(lionTest',1, 300*300); result = svmclassify(SVMStruct, lionTest);
result;
I have taken this code from google. I want to show results in the form of image (like attached sample) actually when I give input images and train SVM/naive Bayes, want to get classification results giving some sample image to classifier, How to do this?
Please help. I will be very thankful to you.
Don Mathis
Don Mathis on 5 Jun 2017
Edited: Don Mathis on 5 Jun 2017
I'm sorry but I still don't understand. Your example code does not return the result in the form of an image. The line
result = svmclassify(SVMStruct, lionTest);
returns a class label, which is probably a string like 'lion'. On the svmclassify Doc page (<http://www.mathworks.com/help/stats/svmclassify.html?searchHighlight=svmclassify&s_tid=doc_srchtitle#outputarg_Group)>, there is an example that shows that the result returned is a class label, in this case strings. Maybe you are saying that you want to return an example image from the same class as the classifier result? In that case you could take the string 'lion' and return the first lion image from your training set. Or, in your case I suppose your labels would be 'noisy' or 'not noisy', and so you would show a random noisy image?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!