How to create feature vector ?
5 views (last 30 days)
Show older comments
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
Edited: Walter Roberson
on 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
on 7 Oct 2013
Accepted Answer
saranya
on 30 Jan 2014
As u have converted the image to gray scale it gives the 1D matrix.. so u get the "hor concate" error... try changing this code for the part of calculating mean and try u will the result..
%%Calculating mean of im1
grayImage=rgb2gray(im1);
meanGL = mean(im1);
now u will get the feature vector... for clarification see
size(meanGL)
size(st_d1)
size(sk1)
size(rms1)
size(md1)
see this value for ur previous coding and this coding..
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!