1

As the title says, I'm trying to scale images from their size to the size of 24x14. its used for numbers in a license plate. The code works fine with all numbers and letters except for the number 1. All other characters are 19x12 and they rescale to 24x14 without a problem. But the number 1 is 18x5. This is the code I have been using, which works fine until number 1 (18x5).

What can be done here if anything?

% inImg is the license plate and bbox are the coordinates for the bounding
% box of a number in the license plate

function [outImg,N]=Frame_RecognitionDigits(inImg,bbox)
% Auxiliary function that draws a specified bounding box in the image
outImg=inImg;
x1=bbox(:,1);     % Coordinates frame
y1=bbox(:,2);
x2=x1+bbox(:,3);
y2=y1+bbox(:,4);
%----------------Recognition of numbers--------------------
%----------Scaling the image size------------
if y2-y1>=15
    Nom=inImg(y1:y2-1,x1:x2,2);   % The images in the frame
    sizeNom=size(Nom);
    sizeNom
    figure,imshow(Nom) % single digits
    im2=zeros(24,14);           % The desired image size
    sizeIm2=size(im2);          % 24x14 pixel
    % coefficients
    k1=length(im2(:,1))/length(Nom(:,1));
    k2=length(im2(1,:))/length(Nom(1,:));
    for i=1:length(im2(:,1))        % 24
        for j=1:length(im2(1,:))    % 14
            y=round(i/k1);
            x=round(j/k2);
            imSt(i,j)=Nom(y,x); % Problem is here
        end
    end
end % the full function doesnt end here. I just closed it for this question

The error I get when the 18x5 image is passed to the function:

Attempted to access Nom(1,0); index must be a positive integer or logical.
Error in
            imSt(i,j)=Nom(y,x);

I read over the answers in Nearest-neighbor interpolation algorithm in MATLAB and it didnt help me since my function is taking different size images and not just a single size. Like I said at the top, I have images with the size 19x12 that work fine and then I get images 18x5 that don't.

Community
  • 1
  • 1
Recap
  • 168
  • 2
  • 15
  • can't you just use `imresize`? – Amro Mar 27 '16 at 19:30
  • @Amro Yes, I can use the Matlab imresize function but i wont learn anything from it. – Recap Mar 27 '16 at 19:52
  • 1
    ok, then refer to this question: http://stackoverflow.com/q/1550878/97160 – Amro Mar 27 '16 at 20:13
  • @Amro thanks but that isn't what I'm looking for – Recap Mar 27 '16 at 22:02
  • 1
    @Recap How exactly is that not what you're looking for. Looks to me like you *are* trying to do nearest neighbor interpolation – Suever Mar 27 '16 at 22:16
  • @Suever From what I understand. The other question was just scaling the image size *2 – Recap Mar 27 '16 at 22:28
  • 1
    @Recap You're never going to find a question 100% exactly like yours but rather one that can be directly adapted to your case. Yes, technically they wanted 2. But if you would read the first very good answer you will see that in the first line they define the scaling factor (which to answer that question was set to 2) which determines the scaling to use. Please read the complete answer. – Suever Mar 27 '16 at 22:30
  • @Recap Simply change the scale factor so that it's `scale = [24/18 14/5];` when referring to the other post. Flagging this question as a duplicate of the other question (and Amro's great answer). – rayryeng Mar 28 '16 at 05:58
  • @rayryeng I can't do it the way you said `scale = [24/18 14/5];` because that will expect the input image to always be 18x5 and my function is working with various dimensions <24x14. Anyway, thanks for trying to help. – Recap Mar 28 '16 at 14:15
  • .... Then change it to match the scales you want? I seriously don't see the problem here. – rayryeng Mar 28 '16 at 14:33
  • @rayryeng I got it now. After reading Amros answer a few times. – Recap Mar 28 '16 at 15:40

0 Answers0