ConcentrationChange.m
Getting a file reader of the video, along with the numer of frames
reader = mmreader('Trial1.avi'); numFrames=get(reader,'numberOfFrames');
Setting the thershold values
binaryThresh = 70; areaThresh = 150;
Looping through all of the frames
maxArea = zeros(1,numFrames);
for i = 1:numFrames
frame = read(reader,i);
Image Processing on the frame.
The frame is broken up into the red, green, and blue components
r = frame(:,:,1);
g = frame(:,:,2);
b = frame(:,:,3);
% A net frame is computed, which only has the red pixels
net = r - g - b;
% Thresholding the image
bw = net > binaryThresh;
% Creating a component map baseed on area
cc = bwconncomp(bw,4);
stats = regionprops(cc,'Area');
if isempty(stats) || isempty(fieldnames(stats))
fprintf(1,'Empty Stats structure at frame %d.\n',i);
break;
else
% Creating an index of all areas greater than the threshold
idx = find([stats.Area]>areaThresh);
bw2 = ismember(labelmatrix(cc),idx);
maxArea(i)= max([stats.Area]);
end
Empty Stats structure at frame 476.
end plot(maxArea); xlabel('Frame (t)'); ylabel('Area (conenctration)'); title('Concentration Evolution');

No comments:
Post a Comment