MATLAB: How to crop license plate image automatically

draw rectangleimage cropImage Processing Toolboxlicense platelpr

1.How to crop the attached license plate image automatically? 2.And using these coordinates how to draw red rectangle around license plate in original image?

Best Answer

Get the bounding box with regionprops. Put up rectangle with rectangle. Crop with imcrop().
binaryImage = maskedImage > 0;
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'BoundingBox');
bb = [measurements.BoundingBox];
% Put up red rectangle
hold on;
rectangle('Position', bb, 'EdgeColor', 'r');
% Crop
croppedImage = imcrop(maskedImage, bb);