Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
set(h,'cdata',I) is slow for UINT8

Subject: set(h,'cdata',I) is slow for UINT8

From: Nick

Date: 4 Mar, 2012 23:45:14

Message: 1 of 2

I am trying to display a movie efficiently in matlab (with a high frame rate). I have experimented with using the image command as well as set(h,'cData',im);

I have noticed that the set command is faster than image for double, but NOT for Uint8. It is also faster to set the data to double precision than to Uint8, but it should be the other way around.

Has anyone else run into these efficiency issues? What is the fastest way to display movie (set of matrices) in MATLAB?

The following code tests these methods and gives this result on my Machine:
Double using Image command: 8.11 seconds
Double using Set command: 1.61 seconds
Uint8 using Image command: 4.68 seconds
Uint8 using set command: 4.62 seconds


CODE:

function dummy

rand('state',0);
r = double(rand([1000 1000 3]));
r8 = uint8(255*r);

clf; h=image(r*0);
tic;
for i=1:100
    clf; h=image(r);
    drawnow; pause(1e-7);
end
fprintf('Double using Image command: %3.3g seconds\n',toc);

clf; h=image(r*0);
tic;
for i=1:100
    set(h,'Cdata',r);
    drawnow; pause(1e-7);
end
fprintf('Double using Set command: %3.3g seconds\n',toc);

clf; h=image(r*0);
tic;
for i=1:100
    clf; h=image(r8);
    drawnow; pause(1e-7);
end
fprintf('Uint8 using Image command: %3.3g seconds\n',toc);

clf; h=image(r*0);
tic;
for i=1:100
    set(h,'Cdata',r8);
    drawnow; pause(1e-7);
end
fprintf('Uint8 using set command: %3.3g seconds\n',toc);

Subject: set(h,'cdata',I) is slow for UINT8

From: Philipp

Date: 14 Jan, 2013 00:32:11

Message: 2 of 2

"Nick" wrote in message <jj0uqa$pq6$1@newscl01ah.mathworks.com>...
> I am trying to display a movie efficiently in matlab (with a high frame rate). I have experimented with using the image command as well as set(h,'cData',im);
>
> I have noticed that the set command is faster than image for double, but NOT for Uint8. It is also faster to set the data to double precision than to Uint8, but it should be the other way around.
>
> Has anyone else run into these efficiency issues? What is the fastest way to display movie (set of matrices) in MATLAB?
>
> The following code tests these methods and gives this result on my Machine:
> Double using Image command: 8.11 seconds
> Double using Set command: 1.61 seconds
> Uint8 using Image command: 4.68 seconds
> Uint8 using set command: 4.62 seconds
>
>
> CODE:
>
> function dummy
>
> rand('state',0);
> r = double(rand([1000 1000 3]));
> r8 = uint8(255*r);
>
> clf; h=image(r*0);
> tic;
> for i=1:100
> clf; h=image(r);
> drawnow; pause(1e-7);
> end
> fprintf('Double using Image command: %3.3g seconds\n',toc);
>
> clf; h=image(r*0);
> tic;
> for i=1:100
> set(h,'Cdata',r);
> drawnow; pause(1e-7);
> end
> fprintf('Double using Set command: %3.3g seconds\n',toc);
>
> clf; h=image(r*0);
> tic;
> for i=1:100
> clf; h=image(r8);
> drawnow; pause(1e-7);
> end
> fprintf('Uint8 using Image command: %3.3g seconds\n',toc);
>
> clf; h=image(r*0);
> tic;
> for i=1:100
> set(h,'Cdata',r8);
> drawnow; pause(1e-7);
> end
> fprintf('Uint8 using set command: %3.3g seconds\n',toc);

Matlab overall is very slow crap. Like a time machine to the 80's.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us