What is the ratio of area of the flame between the last frame and the first? What is wrong with my approach? I am getting an incorrect answer upon submission.
Question 3 Create a mask for each frame of this video that isolates the nearly-white flame exiting the rocket. Do this by converting each frame to grayscale. Then label all pixels with intensities less than or equal to 245 as false, and all pixels with intensities greater than 245 as true.
What is the ratio of area of the flame between the last frame and the first? (Use the number of true pixels for area.)
% Load the video file ‘shuttle.avi’
videoFile = ‘shuttle.avi’;
v = VideoReader(videoFile);
% Read the first frame
firstFrame = readFrame(v);
% Move to the last frame
while hasFrame(v)
lastFrame = readFrame(v);
end
% Convert both frames to grayscale
firstGray = rgb2gray(firstFrame);
lastGray = rgb2gray(lastFrame);
% Create masks where pixel intensities > 245 are true, the rest are false
firstMask = firstGray > 245;
lastMask = lastGray > 245;
% Calculate the flame area (number of ‘true’ pixels) for both frames
areaFirst = sum(firstMask(:));
areaLast = sum(lastMask(:));
% Calculate the ratio of the flame area between the last and the first frame
if areaFirst == 0
error(‘No flame detected in the first frame.’);
else
ratio = areaLast / areaFirst;
end
% Display the results
fprintf(‘Area of the flame in the first frame: %d pixelsn’, areaFirst);
fprintf(‘Area of the flame in the last frame: %d pixelsn’, areaLast);
fprintf(‘Ratio of flame area (last frame / first frame): %.2fn’, ratio);
% Optional: Display the original frames and the masks for visual verification
figure;
subplot(2,2,1), imshow(firstFrame), title(‘First Frame’);
subplot(2,2,2), imshow(lastFrame), title(‘Last Frame’);
subplot(2,2,3), imshow(firstMask), title(‘First Frame Mask’);
subplot(2,2,4), imshow(lastMask), title(‘Last Frame Mask’);Question 3 Create a mask for each frame of this video that isolates the nearly-white flame exiting the rocket. Do this by converting each frame to grayscale. Then label all pixels with intensities less than or equal to 245 as false, and all pixels with intensities greater than 245 as true.
What is the ratio of area of the flame between the last frame and the first? (Use the number of true pixels for area.)
% Load the video file ‘shuttle.avi’
videoFile = ‘shuttle.avi’;
v = VideoReader(videoFile);
% Read the first frame
firstFrame = readFrame(v);
% Move to the last frame
while hasFrame(v)
lastFrame = readFrame(v);
end
% Convert both frames to grayscale
firstGray = rgb2gray(firstFrame);
lastGray = rgb2gray(lastFrame);
% Create masks where pixel intensities > 245 are true, the rest are false
firstMask = firstGray > 245;
lastMask = lastGray > 245;
% Calculate the flame area (number of ‘true’ pixels) for both frames
areaFirst = sum(firstMask(:));
areaLast = sum(lastMask(:));
% Calculate the ratio of the flame area between the last and the first frame
if areaFirst == 0
error(‘No flame detected in the first frame.’);
else
ratio = areaLast / areaFirst;
end
% Display the results
fprintf(‘Area of the flame in the first frame: %d pixelsn’, areaFirst);
fprintf(‘Area of the flame in the last frame: %d pixelsn’, areaLast);
fprintf(‘Ratio of flame area (last frame / first frame): %.2fn’, ratio);
% Optional: Display the original frames and the masks for visual verification
figure;
subplot(2,2,1), imshow(firstFrame), title(‘First Frame’);
subplot(2,2,2), imshow(lastFrame), title(‘Last Frame’);
subplot(2,2,3), imshow(firstMask), title(‘First Frame Mask’);
subplot(2,2,4), imshow(lastMask), title(‘Last Frame Mask’); Question 3 Create a mask for each frame of this video that isolates the nearly-white flame exiting the rocket. Do this by converting each frame to grayscale. Then label all pixels with intensities less than or equal to 245 as false, and all pixels with intensities greater than 245 as true.
What is the ratio of area of the flame between the last frame and the first? (Use the number of true pixels for area.)
% Load the video file ‘shuttle.avi’
videoFile = ‘shuttle.avi’;
v = VideoReader(videoFile);
% Read the first frame
firstFrame = readFrame(v);
% Move to the last frame
while hasFrame(v)
lastFrame = readFrame(v);
end
% Convert both frames to grayscale
firstGray = rgb2gray(firstFrame);
lastGray = rgb2gray(lastFrame);
% Create masks where pixel intensities > 245 are true, the rest are false
firstMask = firstGray > 245;
lastMask = lastGray > 245;
% Calculate the flame area (number of ‘true’ pixels) for both frames
areaFirst = sum(firstMask(:));
areaLast = sum(lastMask(:));
% Calculate the ratio of the flame area between the last and the first frame
if areaFirst == 0
error(‘No flame detected in the first frame.’);
else
ratio = areaLast / areaFirst;
end
% Display the results
fprintf(‘Area of the flame in the first frame: %d pixelsn’, areaFirst);
fprintf(‘Area of the flame in the last frame: %d pixelsn’, areaLast);
fprintf(‘Ratio of flame area (last frame / first frame): %.2fn’, ratio);
% Optional: Display the original frames and the masks for visual verification
figure;
subplot(2,2,1), imshow(firstFrame), title(‘First Frame’);
subplot(2,2,2), imshow(lastFrame), title(‘Last Frame’);
subplot(2,2,3), imshow(firstMask), title(‘First Frame Mask’);
subplot(2,2,4), imshow(lastMask), title(‘Last Frame Mask’); image processing MATLAB Answers — New Questions