video - To refresh imshow in Matlab? -


i want convert answer's code imshow. creates movie in movie2avi by

%# preallocate nframes = 20; mov(1:nframes) = struct('cdata',[], 'colormap',[]); %# create movie k=1:nframes    surf(sin(2*pi*k/20)*z, z)    mov(k) = getframe(gca); end close(gcf) movie2avi(mov, 'mypeaks1.avi', 'compression','none', 'fps',10); 

my pseudocode

%# preallocate nframes = 20; mov(1:nframes) = struct('cdata',[], 'colormap',[]); %# create movie k=1:nframes     imshow(signal(:,k,:),[1 1 1]) % or imshow(signal(:,k,:))     drawnow     mov(k) = getframe(gca); end close(gcf)  movie2avi(mov, 'mypeaks1.avi', 'compression','none', 'fps',10); 

however, creates animation in screen, saves avi -file size 0 kb. file mypeaks1.avi stored after running surf command not imshow. not sure command drawnow.

actual case code

%% hsv 3rd version  % https://stackoverflow.com/a/29801499/54964 rgbimage = imread('http://i.stack.imgur.com/cfosp.png'); % extract blue using hsv  hsvimage=rgb2hsv(rgbimage); i=rgbimage; r=i(:,:,1); g=i(:,:,2); b=i(:,:,3); r((hsvimage(:,:,1)>(280/360))|(hsvimage(:,:,1)<(200/360)))=255; g((hsvimage(:,:,1)>(280/360))|(hsvimage(:,:,1)<(200/360)))=255; b((hsvimage(:,:,1)>(280/360))|(hsvimage(:,:,1)<(200/360)))=255; i2= cat(3, r, g, b);  % binarize image, getting pixels "blue" bw=im2bw(rgb2gray(i2),0.9999);  % label repeated signal.  % find , separate background signal using label. % label each "blob" lbl=bwlabel(~bw);  % find blob highes amount of data. signal. r=histc(lbl(:),1:max(lbl(:))); [~,idxmax]=max(r); % profit! signal=rgbimage; signal(repmat((lbl~=idxmax),[1 1 3]))=255; background=rgbimage; background(repmat((lbl==idxmax),[1 1 3]))=255;  %% error testing comp_image = rgb2gray(abs(double(rgbimage) - double(signal))); if ( sum(sum(comp_image(32:438, 96:517))) > 0 )     break;  end  %% video        % 5001 units 13.90 (= 4.45 + 9.45) seconds.  % in rgb, original size 480x592.  % resize 480x491 signal = signal(:, 42:532, :);  % show 7 seconds (298 units) @ time.  % imshow(signal(:, 1:298, :));   %% video videowriter % movie2avi deprecated in matlab % https://stackoverflow.com/a/11054155/54964 % https://stackoverflow.com/a/29952648/54964 %# figure hfig = figure('menubar','none', 'color','white'); z = peaks;  h = imshow(z, [], 'initialmagnification',1000, 'border','tight'); colormap parula; axis tight manual off;  set(gca, 'nextplot','replacechildren', 'visible','off'); % set(gcf,'renderer','zbuffer'); % on windows   %# preallocate n = 40; % 491; vidobj = videowriter('mypeaks3.avi'); vidobj.quality = 100; vidobj.framerate = 10; open(vidobj);  %# create movie k=1:n    set(h, 'cdata', signal(:,k:k+40,:))    % drawnow    writevideo(vidobj, getframe(gca)); end  %# save avi file close(vidobj); 

how can substitute drawing function imshow or corresponding? how can store animation correctly?

here code try:

%// plot hfig = figure('menubar','none', 'color','white'); z = peaks; %h = surf(z); h = imshow(z, [], 'initialmagnification',1000, 'border','tight'); colormap jet axis tight manual off  %// preallocate movie structure n = 40; mov = struct('cdata',cell(1,n), 'colormap',cell(1,n));  %// aninmation k=1:n    %set(h, 'zdata',sin(2*pi*k/n)*z)    set(h, 'cdata',sin(2*pi*k/n)*z)    drawnow    mov(k) = getframe(hfig); end close(hfig)  %// save avi movie, , open video file movie2avi(mov, 'file.avi', 'compression','none', 'fps',10); winopen('file.avi') 

result (not video, gif animation):

animation


depending on codecs installed on machine, can apply video compression, e.g:

movie2avi(mov, 'file.avi', 'compression','xvid', 'quality',100, 'fps',10); 

(assuming have xvid encoder installed).


edit:

here implementation of code posted:

%%// extract blue ecg signal %// retrieve picture: http://stackoverflow.com/q/29800089 imgrgb = imread('http://i.stack.imgur.com/cfosp.png');  %// detect axis lines , labels imghsv = rgb2hsv(imgrgb); bw = (imghsv(:,:,3) < 1); bw = imclose(imclose(bw, strel('line',40,0)), strel('line',10,90));  %// clear masked pixels setting them background white color imgrgb2 = imgrgb; imgrgb2(repmat(bw,[1 1 3])) = 255;  %%// create sliding-window video len = 40; signal = imgrgb2(:,42:532,:); figure('menubar','none', 'numbertitle','off', 'color','k') himg = imshow(signal(:,1:1+len,:), ...     'initialmagnification',100, 'border','tight');  vid = videowriter('signal.avi'); vid.quality = 100; vid.framerate = 60; open(vid);  n = size(signal,2); k=1:n-len     set(himg, 'cdata',signal(:,k:k+len,:))     writevideo(vid, getframe()); end  close(vid); 

the result this:

signal_animation


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -