imshow shakes inside the for loop
6 views (last 30 days)
Show older comments
Dear MATLAB Community,
I could not grasp the details of plotting, i.e figure and axes handling etc. I have basic knowledge but for little more complicated tasks, I fail to implement. I have a basic image process application, which I read frame, appliying thresholds and obtaining particles and count them. I want to show, current frame, binary image and count plot in a figure windows. I'm using subplot to doing this. I've created 2x2 grid using subplot. First slot I'm using imshow to show current frame, on second slot, I'm using imagesc to show binary image and 3 and 4 slots I'm plotting counts w.r.t frame using plot command. Here my code looks something like this,
for k = starting_frame : NumberOfFrames
Frame = read(video,k);
[Frame_Binary,rgb] = createMask(Frame,red_min,red_max,green_min,green_max,blue_min,blue_max);
subplot(2,2,1)
imshow(Frame)
title('Original Frame')
subplot(2,2,2)
imagesc(Frame_Binary)
title('Detected Particles')
%Extracting Information from the Regions
%
%
subplot(2,2,[3 4])
plot(k/video_fps,particles(k),'-r')
axis([0 inf 0 inf ])
xlim([0 NumberOfFrames/video_fps])
title('Particle Counts')
xlabel('Seconds')
ylabel('Particle Count')
hold on
grid on
end
When I run, everything look ok, except the first subplot which shows current original frame looks like shaking, the size of the video frames is the same, idk what is causing this problem. Would you give any suggestion on how can I solve this problem and also how can I improve the implementation of plotting in such case,
Thanks for your time.
0 Comments
Answers (1)
Image Analyst
on 16 Dec 2020
Not sure what you mean by shaking. Is there a high frequency jitter, like what you see when someone on TV has a striped or patterned shirt? That's due to aliasing (look it up). It also happens if your image is way bigger than your viewing window so it has to subsample the image. You can try to reduce it by making your viewing window as large as possible.
You can check the frame sizes if you want
[rows, columns, numberOfColorChannels] = size(Frame);
fprintf('Frame %d has %d rows, %d columns, and %d color channels.\n', k, rows, columns, numberOfColorChannels);
but I think you'll find they are all the same size.
After the bottom of the loop (or after each call to title() if you want), I'd put a drawnow to force the screen to update immediately:
drawnow;
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!