How can i replace this code to fast up?

for i=1:500,
subplot(23,23,i);
x=vishid(:,i);
imagesc(reshape(x,imagesize));
colormap gray;
end
Here,vishid is 784*500 matrix, imagesize=28*28

댓글 수: 2

Subha - the above code is trying to create 500 subplots within the figure, so it may take some time! :) Adding a drawnow command after the colormap gray line shows how the first 30-40 subplots get drawn relatively quickly, but over time, it takes longer and longer to add the newest subplot to the figure. Even just doing the above with something as simple as
for k=1:500
h = subplot(23,23,k);
set(gca,'XLim',[0 1]);
drawnow;
end
takes a long time (this was just to see if the bottleneck had to do with the reshape and imagesc - not the case).
Is there a need to show all 500 subplots on the same figure, or could you break it into two figures of 250?
subha
subha 2014년 8월 5일
Thanks for your post. Its not necessary to show all 500 plots in a same figure, But it will be better, if it is in same.
If time reduce by implementing this in more than one figure, i am happy about it

댓글을 달려면 로그인하십시오.

답변 (3개)

Jan
Jan 2014년 8월 5일

1 개 추천

Do you really need 500 images with separate axes objects? You can draw 500 im ages in one axes, when wet the coordinates appropriately. This would be much faster.

댓글 수: 3

subha
subha 2014년 8월 5일
How?
Image Analyst
Image Analyst 2014년 8월 6일
I totally agree. 500 subplots is absurd. Most of the space will be taken up be white space and you won't see the images.
Matt J
Matt J 2014년 8월 6일
Whether it's worthwhile depends on how well you need to see the images. Thumbnail views have their uses.

댓글을 달려면 로그인하십시오.

Matt J
Matt J 2014년 8월 5일

0 개 추천

Making the figure invisible until all subplots have been established might help,
h=figure;
set(h,'Visible','off')
for i=1:500,
subplot(23,23,i);
x=vishid(:,i);
imagesc(reshape(x,imagesize));
colormap gray;
end
set(h,'Visible','on')

댓글 수: 2

subha
subha 2014년 8월 5일
Thanks.Actually, in my case, already my figure appears only after it plots all the 500 plots. so, i am not sure, this will help. Let me try again and come back to u
subha
subha 2014년 8월 5일
I have done . But no difference with speed

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2014년 8월 6일

0 개 추천

If you have enough memory, use the montage() function. Or else just use regular indexing. Are the images grayscale or color?

댓글 수: 6

subha
subha 2014년 8월 6일
They are greyscale
Image Analyst
Image Analyst 2014년 8월 6일
OK. So did you try what I suggested? What happened?
I go with regular indexing method first.. can you please help me to understand and use regular indexing to plot these values.
I want to plot an image. So i used imagesc func, want to plot in grayscale, so used colormap. since i have a matrix, i have to use for loop. i have to take column wise , so used inc= 1:c, i need them to appear in 28 *28 pixel, so reshaped each column into 28*28. next my aim is i want plot this each column as one image. so i will have no of images = no of columns. i have to plot each column as one element of matrix. so, assigned k(inc) as an image. each k(inc ) will have one image. but result is not as i asked in this question.. just showing some randomn pixels..
could u please help to solve this.
function []= imageout(x);
[r,c]=size(x);
for inc=1:c,
l= x(:,inc);
l= reshape(l, [28,28]);
k(i)=imagesc(k(i),[0,1]);
end
colormap(gray); end
Image Analyst
Image Analyst 2014년 9월 25일
Seems like a weird thing to do, but I did it. Run the mfile attached below the image. I'll say one thing, it creates some interesting animation as it scans along the columns. Here is the final image it ends up with:
subha
subha 2014년 9월 25일
편집: subha 2014년 9월 25일
thanks a lot for your interesting animation ..
Image Analyst
Image Analyst 2014년 9월 25일
Does it do what you want? I thought it did what you said to do. If it does, please mark it "Accepted".

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2014년 8월 5일

편집:

2014년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by