Make imshow more efficent

I currently have in my code a imshow command, then followed by drawnow. My program is processing data from a acquisition card and then displaying the results in real time. I am trying to do this ~15.3 times per second. But the imshow/drawnow combo is to slow processing wise, and it takes too long so my data acquisition cards memory gets filled, and errors out.
Is there anyway to make it faster?
imshow(-1 * squeeze(Pol1ChanACard1Avg),[],'Parent',imagePlot1, 'border','tight');
imshow(-1 * squeeze(Pol2ChanACard1Avg),[],'Parent',imagePlot2, border','tight');
drawnow;

Respuestas (2)

Walter Roberson
Walter Roberson el 1 de Mzo. de 2013

3 votos

displaydata = - squeeze(Pol1ChanACard1Avg);
p1 = imshow(displaydata, [], 'Parent', imagePlot1, 'border', 'tight');
p2 = imshow(displaydata, [], 'Parent', imagePlot2, 'border', 'tight');
then in the loop,
displaydata = - squeeze(Pol1ChanACard1Avg);
set(p1, 'CData', displaydata);
set(p2, 'CData', displaydata);

1 comentario

Ian Hunter
Ian Hunter el 8 de Jun. de 2019
Thanks!
I need to fullscreen programmatically generated images for a technical application.
I had been using the fullscreen function (https://www.mathworks.com/matlabcentral/fileexchange/11112-fullscreen) .The best time I could get was .03s to refresh the frame. It was very stable, but this was unsatisfying for the application.
Using:
hFig = gcf;
hAx = gca;
% set the figure to full screen
set(hFig,'units','normalized','outerposition',[0 0 1 1]);
% set the axes to full screen
set(hAx,'Unit','normalized','Position',[0 0 1 1]);
% hide the toolbar
set(hFig,'menubar','none')
% to hide the title
set(hFig,'NumberTitle','off');
frame = %generate image here%
p1 = imshow(frame, [], 'Parent', hAx, 'border', 'tight');
for loop...
frame = %generate image here%
tic;
set(p1, 'CData', frame);
toc;
end
I am now closer to .005

Iniciar sesión para comentar.

Shane
Shane el 1 de Mzo. de 2013
Editada: Shane el 1 de Mzo. de 2013

1 voto

Walter Roberson
When I do it that way, the image is not updated though.
Before loop (y is just initial data)
displaydata1 = y;
displaydata2 = y;
p1 = imshow(displaydata1, [], 'Parent', imagePlot1, 'border', 'tight');
p2 = imshow(displaydata2, [], 'Parent', imagePlot2, 'border', 'tight');
In the loop
displaydata1 = - squeeze(Pol1ChanACard1Avg);
displaydata2 = - squeeze(Pol1ChanACard1Avg);
set(p1, 'CData', displaydata1);
set(p2, 'CData', displaydata2);
drawnow;
But the image(s) do not update.

4 comentarios

Walter Roberson
Walter Roberson el 1 de Mzo. de 2013
I do not have the image processing toolbox to test imshow() itself with. Could you test from the command line? The equivalent of
foo = rand(50,60);
p1 = imagesc(foo);
pause(5);
foo = rand(50,60);
set(p1, 'CData', foo);
Side note: if you are displaying the same data for both plots, you only need a single displaydata variable.
Shane
Shane el 1 de Mzo. de 2013
The following does indeed work.
foo2 = rand(50,60);
p2 = imshow(foo2);
pause(5);
foo2 = rand(50,60);
set(p2, 'CData', foo2);
It seems in my previous code, it was updating the image. Only, it was not auto rescaling the image every time (that is what the [] does). As such, the image stayed black due to the values of the new data and the scale of the image. Any ideas on how to incorporate the auto scaling into that method as well?
Walter Roberson
Walter Roberson el 1 de Mzo. de 2013
How about if you switch to imagesc() instead of imshow(,[]) ?
Image Analyst
Image Analyst el 1 de Mzo. de 2013
Shane, this should have been a comment to Walter's Answer, not an answer in itself. Directly writing to cdata will be the fastest way but like you found out, it does not scale the intensity for each image individually. You would have to do that in advance and use the same intensity scale all the time. If you do want to adjust it for each image, then you're back to using a function that does that like imagesc and imshow and unfortunately you're slower again. I guess you could do it yourself by examining the range of each image and adjust the range to be wider only when you needed to expand the range, but that would probably be slow also since the functions do that internally, though you could save time by only widening the scale, which would happen for fewer and fewer images as you go along, and not narrowing it or widening it for each image.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Mzo. de 2013

Comentada:

el 8 de Jun. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by