how determine head light on car
Show older comments
hi my teacher ask me determind car's headlight in picture on matlab and draw circule on thoes and measure distance between thoes how can i do it ...please help me
thanks in advance.
3 Comments
In order to solve any problem, start by defining the problem and what's expected of a solution.
So far, your problem description is "find car headlight (presumed plural), and distance between them". That's incredibly vague. It's not clear what sort of images you expect, what distance metric is needed, or whether this process is even intended to be entirely automated.




I just searched for "headlights". Are these useful images? Would you hope to get any meaningful information from them? What are the expected conditions? Would you expect to be able to programmatically tell which lights belong to a particular vehicle? Does it matter which car they belong to? Would you expect to be able to tell the difference between headlights and streetlights? What if a car has auxillary fog lamps? Is there a distinction?
When you ask for the distance, what does that mean? Distance in pixels? Distance in centimeters? Do you expect to have spatial calibration information or to be able to correct for perspective?
You might try a number of things. I can't think of anything that would be universal, though.
You might try sorting bright spots based on their y-position, but that would get fooled by streetlights, clearance lights, and other cars.
You might try some sort of clustering to associate bright spots with their own reflections and then sorting within those groups to exclude the reflections. That could probably be defeated by a little rain or fog.
inpict = imread('ahb27.jpg');
% create a mask somehow
% i'm going to use HSV only because there is some
% color information which might help subdue the penumbra
% but S information is extremely damaged due to the downsampled chroma
[~,S,V] = rgb2hsv(inpict);
mask = S < 0.05 & V > 0.98;
% get blob area and position
% include an index list, so that it gets transformed during sorting
PS = regionprops(mask,'area','centroid');
A = vertcat(PS.Area);
C = vertcat(PS.Centroid);
roiblobs = (1:numel(PS)).';
% discard small objects
% i'm just going to use the median
% but there's not universally appropriate
junkblobs = A<median(A);
C(junkblobs,:) = [];
roiblobs(junkblobs) = [];
% sort blobs by y-position
[~,idx] = sort(C(:,2));
C = C(idx(1:2),:);
roiblobs = roiblobs(idx(1:2));
% if we want to truncate PS or A, we can
% similarly, the excluded objects could be removed from mask
PS = PS(roiblobs);
A = A(roiblobs);
% plot it i guess
% i'm calculating R based on A
imshow(mask,'border','tight')
viscircles(C,2*sqrt(A/pi));
% distance between blob centroids in pixels
D = sqrt(sum(diff(C).^2))
Answers (1)
ali
on 16 Nov 2023
0 votes
Categories
Find more on Tracking and Motion Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!