Vectorizing nested for loops
Ältere Kommentare anzeigen
Hi,
I am having a few issuing trying to vectorise multiple nested for loops. This application is video and i am looping through each pixel in each line of each frame of all the frames.
for l=1:nFrames
currentVFrame = read(liveVid, l); % Read in next frame
alphaVFrame = zeros(vidHeight, vidWidth, 3, 'uint8'); % create and then reset to 0
for k = 1:3
for i=1:vidHeight
for j=1:vidWidth
if(currentVFrame(i,j,k) == 254) % 254 = green screen
alphaVFrame(i,j,k) = 000; % Set to transparent instead
else
alphaVFrame(i,j,k) = currentVFrame(i,j, k); % Keep original file info
end
end
end
end
%imshow(alphaVFrame); % Show a preview of trhe current frame
mov(l).cdata = im2uint8(alphaVFrame); % Write the frame to our mov structure (int)
writeVideo(OutputVideo, alphaVFrame); % write the frame to the video file (ext)
end
[i,j] = ndgrid(1:vidHeight*vidWidth);
r = reshape(a(i)+a(j), [nFrames, 3, VidHeight, VidWidth]);
But I get an error:
Maximum variable size allowed by the program is exceeded.
Error in ndgrid (line 63)
varargout{1} = x(:,ones(size(y)));
Can anyone point me in the right direction? I'm using Matlab R2013a.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!