-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRadiographyStackToVideo.m
More file actions
55 lines (47 loc) · 2.24 KB
/
RadiographyStackToVideo.m
File metadata and controls
55 lines (47 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
clear
clc
addpath(cd);
%% Imports and converts a stack of images into a video.
% Images should be named in the same order that they should appear in the video.
% No compression applied, ignores image type and size, and converts to 8-bit.
[FileGroup, DataPath] = uigetfile('*.*', 'DialogTitle', 'Select image files:',...
'MultiSelect', 'on' ) ; % Gets file names and location.
cd(DataPath); % Set active folder to curernt image directory.
NFC = length ( FileGroup ) ; % Number of files chosen.
%% Reading and image conversion parameters.
FirstImage = 1; % Index of image to be first frame of video.
LastImage = NFC; % Index of image to be final frame of video.
ImageSkip = 1; % To skip mages between frames. Set to 1 to skip no images.
TimeIncrement = 0.0005 ; % Time between frames in seconds.
TimeBoxColour = 'White'; % Box colour for time stamp.
VideoRotation = 0; % Image to video rotation angle.
% Define video title and start video writer.
FolderFormat = strfind(DataPath, '\'); % Determine folder delimiter.
if size(FolderFormat) == 0
Delimiter = '/';
else
Delimiter = '\';
end
% Use delimiter to find folder name.
VideoTitle = textscan(DataPath, '%s', 'Delimiter', Delimiter);
VideoTitle = strcat(VideoTitle{1}{end}, '.avi');
RadiographyVideo = VideoWriter(VideoTitle, 'Grayscale AVI');
open(RadiographyVideo); % Open the video.
%% Read in the image stack.
warning('Off'); % Turn off imread warning about image type.
for i = FirstImage : ImageSkip : LastImage % Iterate from first to last chosen images.
% Read, rotate and invert image.
ReadImage = imcomplement(imrotate(imread(FileGroup{i}), VideoRotation));
% Insert a text box with the frame time.
FrameTime = (TimeIncrement * (i - 1));
TimeString = sprintf('Time (s) = %.4f', FrameTime);
TimePosition = [10 10]; % Position of time index box.
ReadImage = insertText(ReadImage, TimePosition, TimeString,...
'FontSize', 12, 'BoxColor', TimeBoxColour, 'BoxOpacity', 0.6);
% Convert to uint8 and then to double, and just use R values from RGB.
ProcessedImage = im2double(im2uint8((ReadImage(:,:,1))));
% Append new frame to video.
writeVideo(RadiographyVideo, ProcessedImage);
end
warning('On'); % Swtich warnings back on.
close(RadiographyVideo); % Save video.