error in template creation

조회 수: 2 (최근 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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by