Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We have a dataset of 80 images of flowers. We are using 50 of them for training and 30 of them for tests. The problem

We have a dataset of 80 images of flowers. We are using 50 of them for training and 30 of them for tests. The problem has been solved but section 3.1 and 4.1 need to be completed.

Please try at least three types of features, e.g., histogram of color, histogram of gradient, SIFT-like features, and compare their performance. (MATLAB CODE)

Any answer will be appreciated!

% Step-1: Load training and test data using imageSet. imageDir = fullfile('./data');

flowerImageSet = imageSet(imageDir, 'recursive');

%% step-2: Partition the data set into a training set and a test set. tmparr=randperm(80); arrTrainID=tmparr(1:50); %training ID; arrTestID=tmparr(51:end);% testing ID;

%% Step-3: Train the classifier using features extracted from the training set.

% In this example, the |fitcecoc| function from the Statistics and Machine % Learning Toolbox(TM) is used to create a multiclass classifier using % binary SVMs.

% Step 3.1 Extract features from training images

% Loop over the trainingSet and extract features from each image. A % similar procedure will be used to extract features from the testSet.

trainingFeatures = []; trainingLabels = []; featureSize =128; for flower = 1:numel(flowerImageSet) numImages = numel(arrTrainID); features = zeros(numImages, featureSize); for i = 1:numImages img = rgb2gray(read(flowerImageSet(flower), arrTrainID(i))); %Start Your Code Here features(i, :) = rand(1,featureSize); %End Code end labels = repmat(flowerImageSet(flower).Description, numImages, 1); trainingFeatures = [trainingFeatures; features]; trainingLabels = [trainingLabels; labels ]; end

%% % Step 3.2, train a classifier using the extracted features.

classifier = fitcecoc(trainingFeatures, trainingLabels);

%% Step 4: Evaluate the Flower Classifier

% Evaluate the flower classifier using images from the test set, and % generate a confusion matrix to quantify the classifier accuracy. % % As in the training step, first extract features from the test images. % These features will be used to make predictions using the trained % classifier. The procedure is similar to what was shown earlier.

testFeatures=[]; testLabels=[]; % Step 4.1: Loop over the testing images and extract features from each image. for flower = 1:numel(flowerImageSet) %testing images numImages = numel(arrTestID); % features = zeros(numImages, featureSize); for i = 1:numImages img = rgb2gray(read(flowerImageSet(flower), arrTestID(i))); %Start Your Code Here features(i, :) = rand(1,featureSize); %End Code end labels = repmat(flowerImageSet(flower).Description, numImages, 1); testFeatures = [testFeatures; features]; testLabels = [testLabels; labels ]; end

% Step 4.2: Make class predictions using the test features. predictedLabels = predict(classifier, testFeatures);

% Step 4.3: Tabulate the results using a confusion matrix. confMat = confusionmat(testLabels, predictedLabels);

% Step 4.4: calculate accuracy fprintf('accuracy=%f',sum(diag(confMat))/sum(confMat(:)));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

LO32.2 Explain the factors that cause changes (shifts) in AD.

Answered: 1 week ago