Extract features from training images (Matlab)
up vote
-1
down vote
favorite
Thanks for reading my question. Sorry if it's an easy question but I'm new in Matlab and Computer Vision. I'm trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I'm lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile('./data');
% imageSet recursively scans the directory tree containing the images.
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.
% Step 3.1 Extract features from training images
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
features(i, :) = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
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
testFeatures=;
testLabels=;
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, :) = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
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(:)));
matlab
New contributor
add a comment |
up vote
-1
down vote
favorite
Thanks for reading my question. Sorry if it's an easy question but I'm new in Matlab and Computer Vision. I'm trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I'm lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile('./data');
% imageSet recursively scans the directory tree containing the images.
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.
% Step 3.1 Extract features from training images
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
features(i, :) = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
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
testFeatures=;
testLabels=;
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, :) = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
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(:)));
matlab
New contributor
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Thanks for reading my question. Sorry if it's an easy question but I'm new in Matlab and Computer Vision. I'm trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I'm lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile('./data');
% imageSet recursively scans the directory tree containing the images.
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.
% Step 3.1 Extract features from training images
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
features(i, :) = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
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
testFeatures=;
testLabels=;
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, :) = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
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(:)));
matlab
New contributor
Thanks for reading my question. Sorry if it's an easy question but I'm new in Matlab and Computer Vision. I'm trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I'm lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile('./data');
% imageSet recursively scans the directory tree containing the images.
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.
% Step 3.1 Extract features from training images
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
features(i, :) = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
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
testFeatures=;
testLabels=;
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, :) = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
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(:)));
matlab
matlab
New contributor
New contributor
New contributor
asked 2 days ago
Travis
1
1
New contributor
New contributor
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Travis is a new contributor. Be nice, and check out our Code of Conduct.
Travis is a new contributor. Be nice, and check out our Code of Conduct.
Travis is a new contributor. Be nice, and check out our Code of Conduct.
Travis is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402693%2fextract-features-from-training-images-matlab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown