How to get the minimum mode image and a plot, using pixel values of all the frames of the video in the given program?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ramya ullagaddimath
le 4 Juil 2015
Commenté : Image Analyst
le 12 Juil 2015
That is, to get the image background of the site, so that i would be able to subtract the original frame to the mode frame and get the number of vehicles passing through?
The code is as follows:
nframes = trafficVid.NumberOfFrames;
I = read(trafficVid, 1);
taggedCars = zeros([size(I,1) size(I,2) 3 nframes], class(I));
for k = 1 : nframes
singleFrame = read(trafficVid, k);
% Convert to grayscale to do morphological processing.
I = rgb2gray(singleFrame);
% Remove dark cars.
noDarkCars = imextendedmax(I, darkCarValue);
% Remove lane markings and other non-disk shaped structures.
noSmallStructures = imopen(noDarkCars, sedisk);
% Remove small structures.
noSmallStructures = bwareaopen(noSmallStructures, 150);
% Get the area and centroid of each remaining object in the frame. The
% object with the largest area is the light-colored car. Create a copy
% of the original frame and tag the car by changing the centroid pixel
% value to red.
taggedCars(:,:,:,k) = singleFrame;
stats = regionprops(noSmallStructures, {'Centroid','Area'});
if ~isempty([stats.Area])
areaArray = [stats.Area];
[junk,idx] = max(areaArray);
c = stats(idx).Centroid;
c = floor(fliplr(c));
width = 2;
row = c(1)-width:c(1)+width;
col = c(2)-width:c(2)+width;
taggedCars(row,col,1,k) = 255;
taggedCars(row,col,2,k) = 0;
taggedCars(row,col,3,k) = 0;
end
end
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Juil 2015
before your "for" loop, add
minimg = inf(size(I));
for k = 1 : nframes
singleFrame = read(trafficVid, k);
minimg = min(minimg, singleFrame);
end
now minimg contains the minimum of all of the RGB components.
Note: the minimum RGB components for any given pixel will not necessarily be the darkest value. It will also not necessarily be the "background". Consider that if pedestrian wearing a black jacket walks through the scene, then the black may become the minimum ever found at the locations traveled through, but it would not be the background.
0 commentaires
Plus de réponses (1)
Image Analyst
le 4 Juil 2015
The mode frame sounds like a good idea, though it seems like people usually use Gaussian Mixture Models to get background from video. See http://www.mathworks.com/help/vision/examples/detecting-cars-using-gaussian-mixture-models.html?prodcode=VP&language=en
2 commentaires
Image Analyst
le 12 Juil 2015
Personally, I don't know because I don't have that toolbox and haven't used that code, but I would think you could do that.
Voir également
Catégories
En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!