Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to process each frame of video using for loop and concatenate the result

3 Ansichten (letzte 30 Tage)
Kong
Kong am 28 Mär. 2020
Geschlossen: Stephen23 am 29 Mär. 2020
Hello.
I converted video to 3D image.
(180 x 144 x 84 = width x Height x frames)
I want to process each frame and concatenate the result. (M x M x frames)
If N and M have different values after the process, I want to reduce N and M to minimum values of them.
clear all
close all
%// read the video:
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list(k).name);
vid = {};
while hasFrame(reader)
vid{end+1} = readFrame(reader);
end
for i=1:25
fIdx(i) = i; %// do it for frame 1 ~ 25
frameGray{i} = rgb2gray(vid{fIdx(i)});
data{i} = frameGray{i}';
data{i} = double(data{i});
opt.init_num_secants = 180;
idx1{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
idx2{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
secants{i} = data{i}(:, idx1{i})-data{i}(:, idx2{i});
D1{i} = abs(secants{i});
numSecants = size(data{i},1);
options.landmarks = 1:180;
[geo{i}] = IsomapII(D1{i}, 'k', 3, options);
secants{i} = geo{i}/norm(geo{i},2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Parameter setting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
opt.outer_iterations = 1000;
switch 'l-bfgs'
case 'grad'
opt.linear_solver = 'grad';
opt.tau = 1e-1; % gradient step size
opt.inner_iterations = 10;
opt.beta1 = 1e-1; opt.beta2 = 1e-1; %penalty parameters
opt.eta1 = 1; opt.eta2 = 1; %lagrangian update
case 'cgs'
opt.linear_solver = 'cgs';
opt.linear_iterations = 10;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
case 'l-bfgs'
opt.linear_solver = 'l-bfgs';
opt.linear_iterations = 3;
opt.lbfgs_rank = 5;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%End parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delta = 0.3; %max-margin parameter
funA = @(z) funA_secants_WY(z, secants{i});
funAT = @(z) funAT_secants_WY(z, secants{i});
b = ones(numSecants, 1);
ticID = tic;
[P{i}, L{i}, q{i}, Lambda{i}, w{i}] = NuMax(funA, funAT, b, delta, opt);
toc(ticID);
[U{i}, S{i}, V{i}] = svd(P{i});
r{i} = rank(P{i});
U1{i} = U{i}(:, 1:r{i});
U1{i} = (U1{i} - min(U1{i}(:)))/(max(U1{i}(:))-min(U1{i}(:)));
Phi_NuMax = (U{i}(:, 1:r{i})*(S{i}(1:r{i}, 1:r{i}).^(1/2)))';
data = data{i};
Y = Phi_NuMax * data;
end
end
X = cell2mat(Y');

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by