0

I have taken a scanned image with characters, cropped the characters and stored them in a matrix.

X={}; 
Y={};
for cnt = 1:50
    rectangle('position',box(:,cnt),'edgecolor','r');
    X{cnt}=imcrop(I, box(:,cnt));
    Y{cnt}=im2bw(X{cnt});
 end

Here, box has the coordinates of the rectangle. I want to use Y as input to newsom to create a self organizing map. But i get the error:

net=newsom(Y', [10,1])
??? Error using ==> cat
CAT arguments dimensions are not consistent.

Error in ==> cell2mat at 89
m{n} = cat(1,c{:,n});

Error in ==> newsom>new_6p0 at 72
if isa(p,'cell'), p = cell2mat(p); end

Error in ==> newsom at 58
net = new_6p0(varargin{:});

The images formed have different dimensions(12x6, 15x12 etc). Can anyone tell me how I rectify my approach so that newsom gets the data of 50 binary images?

Community
  • 1
  • 1
Yash Upadhyay
  • 67
  • 2
  • 10
  • I'm not familiar with `newsom`, so am sure if this would affect the algorithm's output, but you could zero-pad all the images so that they are the same size as the largest image in the set. – wakjah Apr 12 '13 at 09:39

1 Answers1

1

In order to use newsom you need all your inputs to have the same size. You can achieve that using imresize

n = 50;
sz = [20 20]; this would be the size of ALL inputs
X = cell(1,n); % pre-allocate outputs, this is good practice
Y = cell(1,n);
for cnt = 1:50
    rectangle('position',box(:,cnt),'edgecolor','r');
    X{cnt}=imcrop(I, box(:,cnt));
    newSize = imresize( X{cnt}, sz, 'bicubic' ); % resize to the predefined size
    Y{cnt}=im2bw(newSize); % do binarization AFTER resizing!
end
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thanks, I tried this and got rid of that problem. However, there is a new problem: >> net=newsom(Y,[10,1]) ??? Error using ==> newsom>new_6p0 at 76 Inputs are not a matrix or cell array with a single matrix. Error in ==> newsom at 58 net = new_6p0(varargin{:}); I tried cell2mat but thats not the solution either. – Yash Upadhyay Apr 13 '13 at 13:02
  • @YashUpadhyay - I'm soory , but I am not too familiar with SOM. try converting your binary images to doubles (if they are logical). – Shai Apr 13 '13 at 19:46