function [ outputImg ] = isolatePlate( inputImg ) % ISOLATEPLATE Draw a box around a license plate in the input image % More info. %%%%% Image Prep % Convert To Grayscale Using the NTSC standard %red = immultiply( double( inputImg(:,:,1) ), 299 ); % green = immultiply( double( inputImg(:,:,2) ), 587 ); % blue = immultiply( double( inputImg(:,:,3) ), 114 ); % newImg = red + green + blue; % newImg = imdivide( newImg, 1000 ); figure, imshow( inputImg ), title( 'Original Image' ); %%%%% Vertical Edge Detection % Create our mask - a Sobel for vertical edge detection mask = fspecial( 'sobel' ); mask = rot90( mask, 1 ); % Do the actual detection edges = imfilter( inputImg, mask ); % Show what we have so far figure, imshow( edges ), title( 'Vertical Edges' ); %%%%% Edge Density Map Generation % Create our mask of ones to add up the edge values densityMask = ones( 3, 15 ); % Sum it up edgeMap = imfilter( edges, densityMask ); edgeMap = imdivide( edgeMap, 45 ); % Show what we have so far figure, imshow( edgeMap, [] ), title( 'Edge Map' ); %%%%% Binarization / Clean Up / Dilation % Binarize!!!! Use Otsu's Method. It's fast. level = graythresh( edgeMap ); binary = im2bw( edgeMap, level ); % Show what we have so far figure, imshow( binary ), title( 'Binarized Edge Map' ); % Clean Up by getting rid of small horizontal lines % Loop over the columns threshold = 15; % Since this threshold can't be pre-determined, this limits % the generality of the code. cleanImage = []; for column = 1:1:size( binary, 2 ) % Segment into regions [ columnLabels, num ] = bwlabel( binary(:,column) ); % Create filler to sum up newColumn = zeros( size( columnLabels, 1 ), size( columnLabels, 2 ) ); % Loop over the labels for labels = 1:1:num if size( find( columnLabels == labels ), 1 ) > threshold newColumn = newColumn | ( columnLabels == labels ); end end % Assemble our image one column at a time cleanImage = cat( 2, cleanImage, newColumn ); end % Show what we have so far figure, imshow( cleanImage ), title( 'Cleaned Image' ); % Dilate the Image se = ones( 1, 9 ); dilated = imdilate( cleanImage, se ); % Show what we have so far figure, imshow( dilated ), title( 'Dilated Image' ); %%%%% License Plate Location % now return the processed image... outputImg = inputImg;