How to separate bounding boxes into separate images(figures)?

10 views (last 30 days)
Asking for a personal project on number plate recognition.
I have managed to isolate the number plate and get this:
I even managed to create the bounding boxes with help of MATLAB documentations and youtube. I have managed to get this :
Now i am stuck. I do not know how to extract the rectangles(the characters on Number plate) separately and form different figures of them.
Please help me. Thanks in advance.
Here is the part of my code:
%% reading the number plate
%we must now separate out the numbers on the numberplate to read them.
%to this, we use BoundingBox method.
figure(8)
imshow(no_plate)
title('Number plate character recognition - bounding boxes')
hold on
%hold on retains the current plot and certain axes properties so that
%subsequent graphing commands add to the existing graph.
labeledImage = bwlabel(no_plate, 8);
[L Ne] = bwlabel(no_plate, 8);
%bwlabel returns vectors of indices for the pixels that make up a
%specific object. Here 8 represents connectivity.
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
%regionprops is used to get the bunding boxes around the numbers.
%measurements is a structure with two fields area and boundingbox vector.
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
% drawing rectangle over each bounding box.
end
hold off

Accepted Answer

KLR
KLR on 12 Jul 2020
Well in order to extract the characters separately, you can calculate the boundries which will contain the starting and ending values for each box. Using that you can extract each character separately. The code would look something like this:
Hope this helps. I have attached a image from my libarary to explain the code. The figure 1 is the raw image showing the two objects. Figure 2 and figure 3 are the ones with the figures extracted
Measurements=regionprops(labeledImage,'BoundingBox','Area');
boundaries=bwboundaries(labeledImage) % This will give the boundries of the rectangle box which is being drawn
% Then you can ask for the minimum and maximum values of the boundary
[xmin, ymin]=min(boundaries{1,1}); % for the first character you will have to run this for the total number of boxes drawn
[xmax, ymax]=max(boundaries{1,1});
Image=labeledImage(xmin(1,1):xmax(1,1),xmin(1,2):xmax(1,2)); % This the image which has the first character
figure;imshow(Image)
  1 Comment
Viba Udupa
Viba Udupa on 12 Jul 2020
Thank you so much for taking out time to answer this question. It is just what i wanted. Thanks again.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!