How to efficiently update an image if one matrix element is changed

43 ビュー (過去 30 日間)
Zoltán Csáti
Zoltán Csáti 2015 年 10 月 18 日
コメント済み: Image Analyst 2015 年 10 月 19 日
I have a matrix in which I change only one element in every iteration of a loop. I want to display that matrix as an image using image or imagesc. What I am doing now is to update the CData property of the image handle so as to refresh the image of the matrix. With several thousands of iterations, it turned out that the bottleneck is the image/imagesc function according to the Profiler. So I thought of changing the color of the tile corresponding to the changed matrix entry. How can I do that? There would be no problem with the colormap since the matrix only contains zeros and ones.
  9 件のコメント
Walter Roberson
Walter Roberson 2015 年 10 月 18 日
If you are using R2014a or earlier, EraseMode 'xor' can be used to potentially speed up drawing. As of R2014b that is no longer an option.
dpb
dpb 2015 年 10 月 18 日
Ewwww...that's a bummer, indeed! I'd also not thought of HG2 and latest releases in performance...I understand there is, so far at least, a big dropoff there.

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

採用された回答

Image Analyst
Image Analyst 2015 年 10 月 18 日
Don't use image. Use set(). See this demo:
grayImage = imread('moon.tif');
hImage = imshow(grayImage);
promptMessage = sprintf('Do you want to assign new pixels,\nor Quit?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(buttonText, 'Quit')
return;
end
for k = 1 : 50 : numel(grayImage);
grayImage(k) = 255; % Make this pixel bright white.
set(hImage, 'CData', grayImage);
end
msgbox('Done');
I think it should be fast enough for you.
  2 件のコメント
Zoltán Csáti
Zoltán Csáti 2015 年 10 月 19 日
This is what I did as you can see it in the attached code in a few comments above. The performance drop is probably due to HG2. However, your code sample made my think of other useful things, so I accept it.
Image Analyst
Image Analyst 2015 年 10 月 19 日
What attached code? Performance drop from what? On my system, my code was faster than a greased cheetah on steroids. So fast I couldn't even see it happen in real time - I just saw the final result.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHilbert and Walsh-Hadamard Transforms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by