error in template creation

1 回表示 (過去 30 日間)
SHOBA MOHAN
SHOBA MOHAN 2018 年 1 月 11 日
コメント済み: SHOBA MOHAN 2018 年 1 月 15 日
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