Home » Posts tagged 'Vehicle detection'
Tag Archives: Vehicle detection
Vehicle detection, blob analysis
clc; clear all; close all;
% Read a grayscale or color image from the file img = imread('car3.jpg'); % Display the grayscale image I figure(1) imshow(img)
Convert the grayscale image I to a binary image
bwi = im2bw(img, graythresh(img));
bwi =~bwi; % As bacground is light its better to inverse the image
figure(2)
imshow(bwi)
Remove from a binary image all connected components (objects) that have fewer than 100 pixels.do some adjsutements based on image
bwi = bwareaopen(bwi,100); figure(3); imshow(bwi); % Create morphological structuring element, something which resemples the % blob str = strel('square',20); bw = imdilate(bwi,str);
Trace region boundaries in binary image, As you see there might be some false detections.
[B,L] = bwboundaries(bw,'noholes'); figure(4); imshow(img); hold on for i = 1:length(B) plot(B{i}(:,2), B{i}(:,1), 'r', 'LineWidth', 2.5) end