Video file of changing solid colors

7 ビュー (過去 30 日間)
Olivia Harris
Olivia Harris 2019 年 9 月 10 日
回答済み: Olivia Harris 2019 年 9 月 23 日
Hello. I want to create a video file of a solid screen changing colors. I am trying to change the color of the figure systematically through hexcodes and record this as a single video. This will be used ultimately for spectral reflectance recordings of different hexcodes, so I want a single stimulus video displaying one color at a time and changing color after a few seconds. This is the code I have so far, when d is a column of hexcodes. So far, this seems to be changing the background color of an empty plot and only 'recording' the last image to the .mp4. Any help would be appreciated
HexCodes = VideoWriter('\Users\~\Documents\MATLAB\Hexcode_Colors.mp4','MPEG-4');
open(HexCodes);
fig = gcf;
set(gca,'visible','off', 'xtick',[])
H = [0 0 0];
fig = figure('Color', H);
hold;
for i = 1:length(d)
d(i,1)
set(gcf,'color',ans)
pause(.05);
f = getframe;
writeVideo(HexCodes,f);
clf
end
close(HexCodes);

採用された回答

Olivia Harris
Olivia Harris 2019 年 9 月 23 日
I figured it out!
%so I want to cycle through all RGB values possible. This will take a
%series of for loops, one for each color value. Brightness is still
%unknown. Also need to convert 0-255 to 0-1.
RGBCycler = VideoWriter('\Users\~\Documents\MATLAB\RGB_by15units_5secs_withWhite.mp4','MPEG-4');
RGBCycler.FrameRate = .5; % Frames per second (speed of video)
open(RGBCycler);
% current figure handle
x = 0
y = 0
z = 0
k = 0
j = 0
i = 0
h = [0 1 1 0];
l = [0 0 1 1];
patch(h,l,[0 0 0])
set(gca,'visible','off')
tic
for k = 1:17
z = 0; y = 0
x = x + 15;
for j = 1:17
z = 0;
y = y + 15;
for i = 1:17
z = z + 15;
col = [ x/255 , y/255, z/255 ]
patch(h,l,col)
pause(.5);
f = getframe;
writeVideo(RGBCycler,f);
clf
%To seperate between slight differences in color and reset the spectrometer.
patch(h,l, [1, 1, 1])
pause(.5);
f = getframe;
writeVideo(RGBCycler,f);
clf
end
end
end
toc
close(RGBCycler);

その他の回答 (1 件)

darova
darova 2019 年 9 月 11 日
TRY
HexCodes = VideoWriter('\Users\~\Documents\MATLAB\Hexcode_Colors.mp4','MPEG-4');
HexCodes.FrameRate = 30; % Frames per second (speed of video)
open(HexCodes);
H = [0 0 0];
fig = figure('Color', H);
set(gca,'visible','off', 'xtick',[])
d = jet(100); % create 100 colors of 'jet' colormap
for i = 1:size(d,1)
set(gcf,'color',d(i,:))
pause(.1);
f = getframe;
writeVideo(HexCodes,f);
clf
end
close(HexCodes);
  1 件のコメント
Olivia Harris
Olivia Harris 2019 年 9 月 11 日
Unfortunately that's still only changing the background of the figure, and the recording is just the blank white figure. Also it's important that I can control the list of colors given.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by