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 view (last 30 days)
Show older comments
ramya ullagaddimath
on 4 Jul 2015
Commented: Image Analyst
on 12 Jul 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 Comments
Accepted Answer
Walter Roberson
on 4 Jul 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 Comments
More Answers (1)
Image Analyst
on 4 Jul 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 Comments
Image Analyst
on 12 Jul 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.
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!