% ————————% Main% ————————function maincleanEverything();%Read the originial registration plate imageimage = im2double(imread(‘reg.jpg’));%Normalizationnormalized = normalize(image);% Edge DetectionedgeDetected = edge(rgb2gray(normalized), ‘Canny’);% Color SegmentationcolorSegmented = colorSegment(normalized);% Morphological operation output = morph(normalized, colorSegmented | edgeDetected);% Show imagessubplot(1,2,1), imshow(image), title(‘Original’);subplot(1,2,2), imshow(output), title(‘Output’);end% ————————% Clean everything% ————————function cleanEverything% Clear and clean enviromentclc;        % Clear command lineclear all;  % Clear all variablesclose all;  % Close all sub-windowsend% ————————% Normalization (Contrast Stretching)% ————————function output = normalize(image)gray = rgb2gray(image); gMin = min(gray(:));gMax = max(gray(:));gStd = std(gray(:));% Apply statistics three-sigma rule to bound to 99.73% of datagLowerBound = max(gMin, (gMax + gMin) / 2 – gStd * 3);gUpperbound = min(gMax, (gMax + gMin) / 2 + gStd * 3);output = (image – gLowerBound) / (gUpperbound – gLowerBound);end% ————————% Color Segmentation% ————————function output = colorSegment(image)% Convert to HSV color space imageHsv = rgb2hsv(image);h = imageHsv(:, :, 1);s = imageHsv(:, :, 2);v = imageHsv(:, :, 3);% Segment blue colorroi = ((h > 0.5) & (h < 0.833)) & (s > 0.5) & (v > 0.5);% Remove smaller components roi = bwareafilt(roi, 1, ‘largest’);% Fill the enclosed areaoutput = imfill(roi, ‘holes’);end% ————————% Morphological Operation% ————————function output = morph(image, roi)% Filter out rubbishroi = bwareafilt(roi, 1, ‘largest’);% Fill the enclosed arearoi = imfill(roi, ‘holes’);% Restore to RGB colored imageoutput = image;for i = 1:3    output(:, :, i) = roi .* image(:, :, i);endend%%