MATLAB Answers

How to check after completing the Image Processing Machine Learning program.

4 views (last 30 days)
Huynh Thanh Sang
Huynh Thanh Sang on 19 Oct 2018
Answered: Bernhard Suhm on 9 Nov 2018
I want to import a picture from the computer to test the program but do not know how.
%%Import Training Data
imgSets = imageSet('folder','recursive');
[imgSets.Count] %show the corresponding count of images
%%Prepare Training Image Sets
minSetCount = min([imgSets.Count]); %determine the smallest a mount of image in a
trainingSets = partition(imgSets, minSetCount, 'randomize');
[trainingSets.Count]
%%Create a Visual Vocabulary from Training Data
bag = bagOfFeatures(trainingSets,'Vocabularysize',100,'Pointselection','Detector');
%%Display Visual Word Occurrence Histograms
% that becomes a new and reduced representation of image.
img = read(imgSets(1), randi(imgSets(1).Count));
featureVector = encode(bag, img);
figure(1)
subplot(3,2,1); imshow(img);
subplot(3,2,2);
bar(featureVector); title('Visual Word Occurrences'), xlabel('Visual Word Index'); ylabel('Frequency of occurrences');
img = read(imgSets(2), randi(imgSets(2).Count));
featureVector = encode(bag, img);
figure(1)
subplot(3,2,3); imshow(img);
subplot(3,2,4);
bar(featureVector); title('Visual Word Occurrences'), xlabel('Visual Word Index'); ylabel('Frequency of occurrences');
img = read(imgSets(3), randi(imgSets(3).Count));
featureVector = encode(bag, img);
figure(1)
subplot(3,2,5); imshow(img);
subplot(3,2,6);
bar(featureVector); title('Visual Word Occurrences'), xlabel('Visual Word Index'); ylabel('Frequency of occurrences');
%%Train a classifier to discriminate between categories
categoryClassifier = trainImageCategoryClassifier(trainingSets, bag); % Train Category Clssifier
Evalute Classifier Performance on Training Set
confMatrix = evaluate(categoryClassifier, trainingSets);
  2 Comments
Huynh Thanh Sang
Huynh Thanh Sang on 19 Oct 2018
%%Import Training Data
imgSets = imageSet('folder','recursive');
[imgSets.Count] %show the corresponding count of images
%%Prepare Training Image Sets
minSetCount = min([imgSets.Count]); %determine the smallest a mount of image in a
trainingSets = partition(imgSets, minSetCount, 'randomize');
[trainingSets.Count]
%%Create a Visual Vocabulary from Training Data
bag = bagOfFeatures(trainingSets,'Vocabularysize',100,'Pointselection','Detector');
%%Display Visual Word Occurrence Histograms
% that becomes a new and reduced representation of image.
img = read(imgSets(1), randi(imgSets(1).Count));
featureVector = encode(bag, img);
figure(1)
subplot(3,2,1); imshow(img);
subplot(3,2,2);
bar(featureVector); title('Visual Word Occurrences'), xlabel('Visual Word Index'); ylabel('Frequency of occurrences');
img = read(imgSets(2), randi(imgSets(2).Count));
featureVector = encode(bag, img);
figure(1)
subplot(3,2,3); imshow(img);
subplot(3,2,4);
bar(featureVector); title('Visual Word Occurrences'), xlabel('Visual Word Index'); ylabel('Frequency of occurrences');
img = read(imgSets(3), randi(imgSets(3).Count));
featureVector = encode(bag, img);
figure(1)
subplot(3,2,5); imshow(img);
subplot(3,2,6);
bar(featureVector); title('Visual Word Occurrences'), xlabel('Visual Word Index'); ylabel('Frequency of occurrences');
%%Train a classifier to discriminate between categories
categoryClassifier = trainImageCategoryClassifier(trainingSets, bag); % Train Category Clssifier
Evalute Classifier Performance on Training Set
confMatrix = evaluate(categoryClassifier, trainingSets);

Sign in to comment.

Answers (1)

Bernhard Suhm
Bernhard Suhm on 9 Nov 2018
Your code isn't complete - it references custom functions you (or your teacher) defined somewhere else such as trainImageCategoryClassifier and evaluate. - Conceptually, you can read an image from your computer using the imread functions, or a test image set by pointing a datastore to the directory with the images. Then you'll want to apply your actually classifier's predict function to that read image of datastore.

Community Treasure Hunt

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

Start Hunting!