Hold on not working in for loop for imshow

11 ビュー (過去 30 日間)
Allan Millsteed
Allan Millsteed 2021 年 7 月 23 日
コメント済み: Allan Millsteed 2021 年 7 月 23 日
For visual verification of my algorithm as I develop it, I have been using imshow to display representations of my data and at one point I overlay 2 images from arrays in a for loop, with reduced transperancy so I can see both. I have been using the following and it has been working fine (virtually an animation is displayed as the loop progresses):
for k = 1:length(maskedArray)
imshow(maskedArray{k})
hold on;
imshow(allPoints{k})
alpha(0.6);
hold off;
pause(0.05)
end
However, I have changed my workflow so that I now import a single image and process it through each iteration of a loop, so I can handle huge numbers of images. At the end of the loop, if I use imshow() for a single image, I still get the expected 'animation' as the loop runs through each iteration.
The problem is, as soon as I use 'hold on' as i have above, or even with the single image, I don't get any images at all displayed until the final loop iteration.
So code such as:
for k=1:100
...processing, etc.
imshow(myImage)
end
generates a 'slideshow' animation just fine, but code such as:
for k=1:100
...processing, etc.
imshow(myImage)
hold on;
hold off;
end
will only show the final image in the sequence.
I don't understand why the 'hold' command supresses the imshow until the final loop iteration but work fine when I use an array of images? Is there a way around this or do I have to revert to smaller data sets and generating image arrays?

採用された回答

Simon Chan
Simon Chan 2021 年 7 月 23 日
It just executing too fast and not able to observe from the screen.
You may add a pasue and try to see whether the output is what you want.
for k=1:100
...processing, etc.
imshow(myImage)
hold on;
hold off;
pause(1)
end
  3 件のコメント
Simon Chan
Simon Chan 2021 年 7 月 23 日
Actually you may remove the hold on and hold off command shown below.
My previous code just showing hold on and hold off are functioning correctly but run too fast.
for k=1:100
...processing, etc.
imshow(myImage)
pause(1)
end
Allan Millsteed
Allan Millsteed 2021 年 7 月 23 日
That is very strange. If I remove the hold on and hold off and also remove the pause then I get the images being displayed each iteration and I can observe them. However, if I put the hold on back in (with or wihout hold off) then no images display and I need to use the pause feature to get them to work.
I don't understand how adding the hold on could increase my processing rate.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDisplay Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by