How to create feature vector ?
Afficher commentaires plus anciens
Someone suggested me to do as follows:
"take the histogram and construct a feature vector that has several comparison metrics, such as mean, std dev, skewness, range, RMS difference, and median absolute difference. Then compare feature vectors to see which are closest "
I have tried to do so which is mentioned below.
clear all; close all; clc;
im1=imread('106a.jpg');
im2=imread('107a.jpg');
im1g=rgb2gray(im1);
im2g=rgb2gray(im2);
%%Calculating mean of im1
grayImage=rgb2gray(im1);
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image');
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
%screen.
% Let's get its histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(1, 2, 2);
bar(pixelCount);
title('Histogram of original image');
xlim([0 grayLevels(end)]); % Scale x axis manually.
yRange = ylim;
% Calculate the mean gray level
meanGL = sum(pixelCount .* grayLevels) / sum(pixelCount)
%%Calculating mean of im2
grayImage2=rgb2gray(im2);
figure, subplot(1, 2, 1);
imshow(grayImage2, []);
title('Original Grayscale Image');
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
%screen.
% Let's get its histogram.
[pixelCount2 grayLevels2] = imhist(grayImage2);
subplot(1, 2, 2);
bar(pixelCount2);
title('Histogram of original image');
xlim([0 grayLevels2(end)]); % Scale x axis manually.
yRange2 = ylim;
% Calculate the mean gray level
meanGL2 = sum(pixelCount2 .* grayLevels2) / sum(pixelCount2)
%%Calculating standard deviation
st_d1=std(double(im1));
st_d2=std(double(im2));
%%Calculating Skewness
sk1=skewness(double(im1));
sk2=skewness(double(im2));
%%Calculating RMS
rms1=rms(im1);
rms2=rms(im2);
%%Calculating median absolute
md1=mad(double(im1));
md2=mad(double(im2));
%%Contruct a feature vector
fv1=[ meanGL, st_d1, sk1, rms1, md1 ]
fv2= [ meanGL2, st_d2, sk2, rms2, md2 ]
But it seems like I have not created feature vectors correctly because of reasons:
1. dimensions of meanGL, st_d1, sk1, rms1 and md1 are different. 2. after evaluating above code in MATLAB editor, I am getting error
" Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in oct6 (line 71)
fv1=[ meanGL, st_d1, sk1, rms1, md1 ] ; "
But it
2 commentaires
Walter Roberson
le 7 Oct 2013
Modifié(e) : Walter Roberson
le 7 Oct 2013
Also, When you put a breakpoint in at the line and run the program, what is size() of each of those variables ?
Image Analyst
le 7 Oct 2013
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Category Classification dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!