Você está na página 1de 3

How to create feature vector ?

Asked by Explorer on 7 Oct 2013


Latest activity Edited by Walter Roberson on 30 Jan 2014
Accepted Answer by saranya
138 views (last 30 days)
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 Comments
Walter Roberson on 7 Oct 2013
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Also, When you put a breakpoint in at the line and run the program, what is size() of each of those variables ?
Image Analyst on 7 Oct 2013
Complete duplicate of http://www.mathworks.com/matlabcentral/answers/89252#comment_172673
Comment on this Question

Você também pode gostar