error in template creation

1 次查看(过去 30 天)
I wish to create template of number and sign to extract the vehicle number plate. I got loading error
"Dimensions of matrices being concatenated are not consistent".
% Create Templates
one=imread('1.png'); two=imread('2.png');
three=imread('3.png');four=imread('4.png');
five=imread('5.png');
zero=imread('0.png');
sign=imread('sign.png');
number=[one two three four five zero ];
character=[number sign];
NewTemplates1=mat2cell(character,7,[24 24 24 24 24 24 24]);
save ('NewTemplates1','NewTemplates1')
clear all
can anyone help me to resolve this?

采纳的回答

SHOBA MOHAN
SHOBA MOHAN 2018-1-14
Thanks Guillaume !!!!!. I am able to create template of sign and symbol using the following code
%CREATE TEMPLATES
one=imread('1.png');
one=imresize(one,[42 24]);
two=imread('2.png');
two=imresize(two,[42 24]);
three=imread('3.png');
three=imresize(three,[42 24]);
four=imread('4.png');
four=imresize(four,[42 24]);
five=imread('5.png');
five=imresize(five,[42 24]);
zero=imread('0.png');
zero=imresize(zero,[42 24]);
sign=imread('sign.png');
sign=imresize(sign,[42 24]);
number=[one two three four five zero ];
character=[number sign];
NewTemplates1=mat2cell(character,42,[24 24 24 24 24 24 24], 3);
save ('NewTemplates1','NewTemplates1')
clear all
  2 个评论
Guillaume
Guillaume 2018-1-15
编辑:Guillaume 2018-1-15
Note: there's no point concatenating all the images into a matrix to then split them back up into a cell array. You can just put them straight into the cell array. Instead of
number = ...
character = ...
NewTemplates1 = ...
just
NewTemplates = {one two three four five zero sign};
Also, once you start writing more or less the same code several times it's a good indication that a loop would work better. You coud simplify the whole code to:
desiredsize = [42 24];
files = {'1', '2', '3', '4', '5', '0', 'sign'};
NewTemplates1 = cell(size(files));
for fileidx = 1:numel(files)
img = imread([files{fileidx}, '.png']);
img = imresize(img, desiredsize);
NewTemplates1{fileidx} = img;
end
SHOBA MOHAN
SHOBA MOHAN 2018-1-15
Thanks Guillaume. I included rgb2gray in the given code to make suitable for further processing (i.e. correlation and median filtering).
desiredsize = [42 24];
files = {'1', '2', '3', '4', '5', '0', 'sign'};
NewTemplates1 = cell(size(files));
for fileidx = 1:numel(files)
img = imread([files{fileidx}, '.png']);
img = rgb2gray(img);
img = imresize(img, desiredsize);
NewTemplates1{fileidx} = img;
end

请先登录,再进行评论。

更多回答(1 个)

Guillaume
Guillaume 2018-1-11
Your code tries to concatenates the images side by side but at least one of the images is not the same height as the others or is grayscale or indexed while the others are RGB. Hence the concatenation is not possible.
You can resolve this in many way:
  • concatenate images that are the same height and colour format
  • resize your images after loading them so they're all the same height
  • pad the smaller images (with black? white?)
It's all up to you.
  1 个评论
SHOBA MOHAN
SHOBA MOHAN 2018-1-14
I am resized the images but getting the following error
Number of input vector arguments, 2, does not match the input matrix's number of dimensions, 3.
This is the following code:
%CREATE TEMPLATES
one=imread('1.png');
one=imresize(one,[42 24]);
two=imread('2.png');
two=imresize(two,[42 24]);
three=imread('3.png');
three=imresize(three,[42 24]);
four=imread('4.png');
four=imresize(four,[42 24]);
five=imread('5.png');
five=imresize(five,[42 24]);
zero=imread('0.png');
zero=imresize(zero,[42 24]);
sign=imread('sign.png');
sign=imresize(sign,[42 24]);
number=[one two three four five zero ];
character=[number sign];
NewTemplates1=mat2cell(character,7,[24 24 24 24 24 24 24]);
save ('NewTemplates1','NewTemplates1')
clear all
please help me on this issue

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by