问题
The code is for video processing in MATLAB and I have a problem in the first loop. I do not know what the problem is but the error that MATLAB gives is :
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in
fi
(line 34)
data(:,:,f) = I;
Here is my code:
clc;
close all;
clear all;
It1c = imread( '\\icnas1.cc.ic.ac.uk\fi15\Desktop\frames\Frames_V11\051.png' );
It600c = imread( '\\icnas1.cc.ic.ac.uk\fi15\Desktop\frames\Frames_V11\009.png' );
resf = 0.27e-6;
fr_r = 12000; %frame rate = 12000 fps
figure();
imagesc(It1c);
figure();
imagesc(It600c);
listing = dir('\\icnas1.cc.ic.ac.uk\fi15\Desktop\frames\Frames_V11\*.png');
N = 51;
data = zeros(624,1024,N);
for f = 1:N,
f
I = imread(['Frames_V11\',fullfile(listing(f).name)] );
data(:,:,f) = I;
end
figure; %see frames
for i = 1:N,
imagesc(data(:,:,i));
colorbar;
pause(0.1);
end
figure; %see frames
for i = 1:N,
imagesc(data(:,:,i)-data(:,:,1));
colorbar;
pause(0.1);
end
for i = 1:N,
i
data2(:,:,i) = data(:,:,i)-data(i);
end
figure; %see frames
for i = 1:N,
imagesc(data2(:,:,i));
colorbar;
pause(0.1);
end
figure;
imagesc(squeeze( mean(data2(230:270,:,:),1) ));
figure;
plot(squeeze(mean(mean(data5(210:235,395:425,:),1),2)));
回答1:
Your image data is likely RGB and therefore has the following dimensions [nRows, nCols, nChannels]
where nChannels
is likely 3. The error is because you're trying to assign this 3D matrix to a 2D slice in data
.
You need to therefore concatenate all of the images along the fourth dimension instead of the third.
data = zeros(624, 1024, 3, N);
for f = 1:N
data(:,:,:,f) = imread(['Frames_V11\',fullfile(listing(f).name)]);
end
来源:https://stackoverflow.com/questions/39044182/matlab-video-processing