Overlay movies witj two different color bars

4 views (last 30 days)
I want to overlay two movies and include ttwo color bars on the overlay movie (hot and black jet) each represnt one of the movies. The below code works fine for the overlay but it shows a only one color bar that is "parlua"... I don't need the "parula" colorbar I need "hot" color bar for ch9-mov and "blackkjet" for ch10-mo... I am unable to load the movies but the code is below:
file1 = 'ch9-mov.avi';
file2 = 'ch10-mov.avi';
% Create VideoReader objects for both input videos
videoReader1 = VideoReader(file1);
videoReader2 = VideoReader(file2);
% Check if the videos have the same number of frames
if videoReader1.NumFrames ~= videoReader2.NumFrames
error('Both videos must have the same number of frames.');
end
% Get video properties
width = videoReader1.Width;
height = videoReader1.Height;
frameRate = videoReader1.FrameRate;
% Create a VideoWriter object for the output video
outputFile = 'output_overlay.avi';
outputVideo = VideoWriter(outputFile, 'Uncompressed AVI');
outputVideo.FrameRate = frameRate;
% Open the VideoWriter object
open(outputVideo);
% Create a figure for displaying the overlaid video
figure;
% Display colorbars for hot and jet from the beginning
h = colorbar('Location', 'west', 'Position', [0.05, 0.1, 0.02, 0.8]);
colormap(h, hot);
h2 = colorbar('Location', 'east', 'Position', [0.93, 0.1, 0.02, 0.8]);
colormap(h2, jet);
% Loop through frames, overlay them, and display
for frameIdx = 1:videoReader1.NumFrames
% Read frames from both videos
frame1 = read(videoReader1, frameIdx);
frame2 = read(videoReader2, frameIdx);
% Perform overlay operation (e.g., add frames together)
overlayFrame = frame1 + frame2;
% Display the overlaid frame
imshow(overlayFrame);
title(['Frame: ' num2str(frameIdx) '/' num2str(videoReader1.NumFrames)]);
drawnow;
% Write the overlaid frame to the output video
writeVideo(outputVideo, overlayFrame);
end
% Close the VideoWriter object
close(outputVideo);
disp('Overlay process completed. Output video saved as output_overlay.avi');
  1 Comment
Walter Roberson
Walter Roberson on 31 Jan 2024
h = colorbar('Location', 'west', 'Position', [0.05, 0.1, 0.02, 0.8]);
colormap(h, hot);
h2 = colorbar('Location', 'east', 'Position', [0.93, 0.1, 0.02, 0.8]);
colormap(h2, jet);
It is not documented what will happen if you colormap() against a colorbar()
frame1 = read(videoReader1, frameIdx);
frame2 = read(videoReader2, frameIdx);
% Perform overlay operation (e.g., add frames together)
overlayFrame = frame1 + frame2;
% Display the overlaid frame
imshow(overlayFrame);
Numerically adding two videos is going to result in saturation of uint8.
You are adding the images rather than putting them side-by-side, so it is not clear why you would have two colormaps

Sign in to comment.

Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!