showing image frames and statistics in figures
3 次查看(过去 30 天)
显示 更早的评论
I have a "real time" application that generates a stream of images, which I show as a four-part subplot (a few times every second). I also want to show a text box that has some statistics. I have two issues.
- The imshow for each subplot (and title) is to slow. I suspect too much re-layout. Since a single imshow outside of the subplot would keep up with 25 fps.
- I am trying to show the text statistics as a figure. Probably stupid, but it does not work as subplot. Anyway switching between figures causes new windows to appear.
Yes, all of this is a Class object, ticker an event handler that is called every time a new image frame is ready.
this.scope = figure();
this.stats = figure();
%%Private Methods
methods
function showScope(this)
% show raw input frame
figure(this.scope);
tTotAvg = this.stepper.tTotalAvg;
tMed = this.stepper.tMedian;
tConv = this.stepper.tConvolve;
tThresh = this.stepper.tThreshold;
subplot(1,4,1);
imshow(this.raw);
stext = sprintf('Total GPU: %0.2f ms', tTotAvg);
title(stext, 'Fontweight','Bold');
subplot(1,4,2);
imshow(this.background);
stext = sprintf('Median Filter: %0.2f ms', tMed);
title(stext, 'Fontweight','Bold');
subplot(1,4,3);
imshow(this.foreground, [50,255]);
stext = sprintf('Convolution Filter: %0.2f ms', tConv);
title(stext, 'Fontweight','Bold');
subplot(1,4,4);
imshow(this.mask, [0,1]);
stext = sprintf('Thresholding: %0.2f ms', tThresh);
title(stext, 'Fontweight','Bold');
end
function showStats(this)
tTotAvg = this.stepper.tTotalAvg;
tMed = this.stepper.tMedian;
tConv = this.stepper.tConvolve;
tThresh = this.stepper.tThreshold;
tTrans = this.stepper.tTransfer;
figure(this.stats);
clf(this.stats);
%imshow(ones(1,1));
s = cell(1,5);
s{1} = sprintf('Avg Total: %0.2f\n', tTotAvg);
s{2} = sprintf('Median: %0.2f\n', tMed);
s{3} = sprintf('Convolve: %0.2f\n', tConv);
s{4} = sprintf('Threshold: %0.2f\n', tThresh);
s{5} = sprintf('Transfer: %0.2f\n', tTrans);
stext = sprintf('%s%s%s%s%s',s{1},s{2},s{3},s{4},s{5});
text(0,0,stext);
end
function ticker(this, src, e)
% Event Handler for each frame processed by the SkyMarker
bits = uint8(this.stepper.raw);
this.raw = reshape(bits, [this.height,this.width]);
bits = uint8(this.stepper.background);
this.background = reshape(bits, [this.height,this.width]);
bits = single(this.stepper.foreground);
this.foreground = reshape(bits, [this.height,this.width]);
bits = uint8(this.stepper.mask);
this.mask = reshape(bits, [this.height,this.width]);
this.showScope();
%this.showStats();
end
1 个评论
Ced
2015-1-21
编辑:Ced
2015-1-21
When you need to update a plot a lot, the way to go is usually to save the plot handle, and then update the values by using "set", so something like this:
figure
h = plot([1 2], [1 2]);
set(h,'XData',[3 5])
drawnow
Not sure how to update this with full images though, but maybe this works too. 25 fps is a bit tricky... matlab may not be the best choice for that. But maybe somebody else has a better idea here.
Concerning the switching plots, there are two ways I can think of to fix that:
a) Give back the handle to the plot, and then always plot to the respective handle. This also works for subplots!
b) You can explicitely access a current figure through its number (e.g. call figure(2) to switch to that figure). Since version 2014a (or b, not sure), the number of a current figure (if you don't want to hardcode it) is a property and can be retrieved from the handle with get(handle,'Number').
Hint: if you have a handle, you can get a list of all possible settings by calling
set(handle)
without second argument
Hope this helps
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!