Vehicle detection in matlab
What I would try is to :


Get the HSL (Hue Saturation Lightness) decomposition of the original picture
Only keep the L component
Multiply the image you have from the last steps with the image you get after the morphological operation (the black and white one, after deleting the noise)
Do some thresholding on that
Use what you obtained from that instead of the image after the morphological operation for the following part of the algorithm.


I don't know well Matlab so I can't provide function names, but I guess you can find it easily with a bit of googling. And please keep me updated if you try this, I would like to know if it works well or not.