problem inconsistent dimension arrays

10 views (last 30 days)
Hello everyone. So here is my problem: i receive a dataset of images with signatures (specifically the CEDAR dataset) and i process it with the help of a function. What I'm actually doing in the function is extracting features (11 features). Ι want to create 4 patches for each image to better train the machine learning models to distinguish the fake signature from the real one. When i run the code i get this error: "Dimensions of arrays being concatenated are not consistent". Below, i will show you the main code for forgeries signatures (i have the same code for original signatures) and a piece of code of Function:
Main code:
clc;
clear;
close all;
format compact;
myFolder = './full_forg';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.png');
jpegFiles = dir(filePattern);
varray=[];
% for each fake image
for k = 1:length(jpegFiles)
k
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% read the image
im1=imread(fullFileName);
%im1=imresize(im1,[650 650]);
im1=imresize(im1,[1024 1024]);
% create the patches
patchit(im1,[512 512]);
% read the patches
load patches.mat;
% get the number of patches
[~,~,~,pn]=size(patch);
v=[];
active_pixesls=[];
% for each patch
for i=1:pn
im_patch=patch(:,:,:,i);
[F,croped_image]=featureExtraction(im_patch);
v=[v F];
active_pixesls=[active_pixesls sum(croped_image(:))];
end
response=0; % because it is a fake image
v=[v active_pixesls response];
varray=[varray; v];
end
Function:
function [Feat_Val,im_processed] = featureExtraction(I)
S=512;
I2=imresize(I,[S S]);
dbstop if error;
dbstop if warning;
%I3=rgb2gray(I2);
I3=im2gray(I2);
I3=im2double(I3);
I3=im2bw(I3); %converting image to black and white
%I3 = bwmorph(~I3, 'thin', inf) %thining the image
I3 = bwmorph(~I3, 'close', inf);
I3=~I3;
Can someone tell me how to deal with this error?
Thanks a lot!!
  2 Comments
the cyclist
the cyclist on 16 May 2023
Which lines gives the error, and what is the full error message?
ALEKSANDROS
ALEKSANDROS on 16 May 2023
The error i get it in command "varray=[varray ; v]". The full error message is: "Error using vertcat. Dimensions of arrays being concatenated are not consistent".

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 16 May 2023
Edited: the cyclist on 16 May 2023
We can't run your code because we don't have all the inputs to do so. I suggest using the debugger to halt your code at that line, and see that the variables look like. (It might not produce the error the first time through the loop.)
  17 Comments
ALEKSANDROS
ALEKSANDROS on 19 May 2023
Hello again. So i fixed it but also i have an issue. I send you two pictures one of the code which i filled and one with the error:
The reason that i use the function reshape is because i want the "v" vector to has equal dimension with "varray" vector.
the cyclist
the cyclist on 19 May 2023
First, instead of pasting screenshots, it is better to cut & paste the code itself, or upload the code as an M-file. If you do a screenshot, we need to re-type your code if we want to try it.
Second, and I am repeating myself now, you should share a complete example that I can just paste into MATLAB to replicate your error. For example, here, I don't know what input caused the error, I don't know the size of v, etc. I have to make a lot of guesses. Again, make it as easy as possible for people to help you.
In this particular case, here is my guess:
If v is shorter than 137 elements, look what happens:
% Define a vector that is too short
v = rand(1,125);
% Use your code
v = reshape(v(1:137),[1 137])
Index exceeds the number of array elements. Index must not exceed 125.
The reason is that your code tries to access elements that do not exist. (In my example, elements 126:137 do not exist.)
I don't know if it makes sense in your application, but if the vector is too short, perhaps you can add NaN or zero values to it, to make it length 137.

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!