I am working on a Currency Recognition System using Matlab's Image Processing toolbox. I am unable to make the database using the folder method.I'm using feture extraction for my project. I have attached the code.Please help me to form the database.
4 次查看(过去 30 天)
显示 更早的评论
%color feature
fet1=color_luv(rgbim);
%edge feature
fet2=edgehist(rgbim);
%texture feature
%glcm-gray level co occurrence matrix
glcm=graycomatrix(rgb2gray(rgbim));
fet3=glcm(:);
fet=[fet1;fet2;fet3];
function colfet=color_luv(rgb_im)
%three color moments,mean,color variance and color skewness in each channel
%(L,U and V respectively)
%total 9-D color moments
%Input image should be a rgb image,
%convert rgb to xyz colorspace
xyzTransformation = makecform('srgb2xyz');
xyzI = applycform(rgb_im,xyzTransformation);
%convert xyz to luv colorspace
warning('off');
luvTransformation = makecform('xyz2uvl');
luvI = applycform(xyzI,luvTransformation);
%figure,imshow(luvI,'initialmagnification','fit');
%seperate l,u,v
L=luvI(:,:,1);
U=luvI(:,:,2);
V=luvI(:,:,3);
%find mean,color variance and color skewness for each channel
colfet(1)= mean(L(:));
colfet(2) = std(L(:))^2;
colfet(3)= skewness(L(:));
colfet(4) = mean(U(:));
colfet(5) = std(U(:))^2;
colfet(6) = skewness(U(:));
colfet(7) = mean(V(:));
colfet(8) = std(V(:))^2;
colfet(9) = skewness(V(:));
colfet=colfet';
end
function edhist= edgehist(rgb_im)
%edge directional histogram
%Input image should be a rgb image,
%a 1x5 edge orientation histogram is computed (horizontal, vertical,
% 2 diagonals and 1 non-directional)
%convert rgb color space into ycbcr colorspace
new_im=rgb2ycbcr(rgb_im);
%extract only y component
y=double(new_im(:,:,1));
%figure,imshow(y,'initialmagnification','fit');
% define the filters for the 5 types of edges
f1 = zeros(3,3,5);
f1(:,:,1) = [1 2 1;0 0 0;-1 -2 -1]; %vertical
f1(:,:,2) = [-1 0 1;-2 0 2;-1 0 1]; %horizontal
f1(:,:,3) = [2 2 -1;2 -1 -1; -1 -1 -1];% 45 diagonal
f1(:,:,4) = [-1 2 2; -1 -1 2; -1 -1 -1];%135 diagonal
f1(:,:,5) = [-1 0 1;0 0 0;1 0 -1]; % non directional
% iterate over the posible directions
for i = 1:5
% apply the sobel mask
g_im(:,:,i) = filter2(f1(:,:,i),y);
end
% calculate the max sobel gradient and index of the orientation
[m, p] = max(g_im,[],3);
%detect the edges using canny
edim = edge(y, 'canny');
%figure,imshow(edim,'initialmagnification','fit');
%multiply edge image with the types of orientations detected
% by the Sobel masks
im2 =(p.*edim);
%find hisogram
edhist=hist(im2(:),5)';
end
4 个评论
Walter Roberson
2018-11-8
The code is commented as to the purpose of each group of lines, so you should ask specific questions so that we do not need to write a textbook.
回答(2 个)
Walter Roberson
2016-10-15
(It looks to me as if the beginning of your code is missing a "function" line.)
3 个评论
Walter Roberson
2016-10-15
Assume a project directory.
Assume that in the directory, there a bunch of .jpg files. Assume that each of the files is named starting with the name of a note, followed by an underscore, followed by some unique component. For example, Canada-$1-series1928_19.jpg Canada-$1-series1928_20.jpg Canada-$50-series1974_3.jpg Japan500YenHesei-11_007.jpg
Then,
projectdir = 'CurrencyRecognition';
dinfo = dir( fullfile(projectdir, '*.jpg') );
num_img = length(dinfo);
note_images = cell(num_img, 1);
note_names = cell(num_img, 1);
for K = 1 : num_img
note_filename = fullfile( projectdir, dinfo(K).name );
[~, basename, ~] = fileparts(note_filename);
name_pieces = strsplit(basename, '_');
note_names{K} = name_pieces{1};
note_images{K} = imread(note_filename);
end
[unique_notenames, ~, note_group] = unique(note_names);
At this point, unique_notenames is a list of the unique types of notes; with the above examples that would be Canada-$1-series1928 Canada-$50-series1984 Japan500YenHesei-11 . The images are stored in the note_images cell array, such as note_image{18} and the note name is stored in note_names{18}, and the group number (class number) is stored in the corresponding place in note_group such as note_group(18) . note_group is therefore your "target" information for training purposes, if you use neural networks.
With the data in hand, you can loop K from 1 to num_img doing feature extraction on note_images{K} and storing the results in a row (or column) of a matrix. Pass that and the group_number matrix into your training routine. Once you have that training done, you can store the training information into a .mat file.
To recognize, retrieve the unique_notenames variable and the coefficients. For each image to be recognized, do the feature extraction, and run the extracted feature through the pattern recognition routine with the coefficients. The result will be a class number, or possibly a series of probabilities of class numbers. Figure out which class number was most likely based on the returned information. Use that class number to index unique_notenames and output the string you find there.
====
Notice that the method of handling the files follows exactly along the framework suggested in the link http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F -- do a dir(), loop over the returned information, pull out one specific name, process that file, loop around to the next.
Aditya Katara
2017-1-25
hello ayush i am also working on currency recognition .. and i am total new to matlab .. plz can u guide me through or can u help me with the code .. thank you
shaily saigal
2017-3-24
Hello sir, I'm also working on this project and I'm not able to figure out the values that are fed into the database. Can you please explain me how these values are actually stored by default in the database.
1 个评论
Walter Roberson
2017-3-24
Use the outline I provided above, https://www.mathworks.com/matlabcentral/answers/307453-i-am-working-on-a-currency-recognition-system-using-matlab-s-image-processing-toolbox-i-am-unable-t#comment_398929 for how to structure your input directories for automatic processing and run through the processing.
For each input file, run through the color feature code that Ayush Arora provided, the few lines ending in
fet=[fet1;fet2;fet3];
When you have calculated this fet column vector, store it indexed by K in the code I outlined above, like changing
note_names{K} = name_pieces{1};
note_images{K} = imread(note_filename);
to
note_names{K} = name_pieces{1};
note_images{K} = imread(note_filename);
these_features = calculated_color_features(note_images{K});
note_features{K} = these_features;
and allow the loop to continue.
Now, the variables note_names, note_images, and note_features are your database. You could save them to a .mat at this point so you do not need to recalculate.
To do the training,
[unique_note_names, ~, target_idx] = unique(note_names);
feature_matrix = cell2mat(note_features);
Depending on which classifier you are using, you would either train with feature_matrix and targets target_idx directly, or you would take the additional step
target_vec = ind2vec(target_idx);
and train with feature_matrix and target_vec.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!