Dark image using imshow

Hello,
I'm having a problem with imshow. I'm going point per point through my data and want to plot the corresponding video while I do this.
The file works when there is no video in it. And in another file I was able to plot the whole data with the video playing.
BUT: now when I use "animatedline" with "addpoints" the video is black. The video is black and becomes lighter sometimes, but you can't see anything.I have added a screenshot of the figure while its going through the data in the attachment.
UPDATE: when i remove all the animatedlines and addpoints the video plays correctly
Here is my code
%code
daqrate = 40;
VID = VideoReader('Zwemvideo1.mp4','Tag','My reader object');
writerObj = VideoWriter('output_video','MPEG-4');
writerObj.FrameRate = 40;
fps=30;%VID.FrameRate;
totalframes=VID.NumberOfFrames;
rate=daqrate/fps;
frameA=read(VID,1);
x=[329 752];
y=[50 411];%56
ratio =(y(2)-y(1))/(x(2)-x(1));
acc_y = resample(acc_y,3,4);
acc_z = resample(acc_z,3,4);
gyr_y = resample(gyr_y,3,4);
gyr_x = resample(gyr_x,3,4);
figure
subplot(5,1,1)
xlabel('samples')
ylabel('gyr_x filtered')
title('Turn detection')
h = animatedline;
axis([0 length(gyr_x) -230 330])
x = linspace(0,length(gyr_x),length(gyr_x));
subplot(5,1,2)
xlabel('samples')
ylabel('acc_z filtered')
title('Stroke detection')
g = animatedline;
axis([0 length(acc_z) -1 1.5])
y = linspace(0,length(acc_z),length(acc_z));
subplot(5,1,3)
xlabel('samples')
ylabel('gyr_y filtered')
title('Stroke detection')
f = animatedline;
axis([0 length(gyr_y) -100 140])
z = linspace(0,length(gyr_y),length(gyr_y));
subplot(5,1,4)
xlabel('samples')
ylabel('acc_y filtered')
title('Stroke detection')
e = animatedline;
axis([0 length(acc_y) -2 2])
w = linspace(0,length(acc_y),length(acc_y));
for i = 1: length(gyr_x)
%video
drawnow
subplot(5,1,5)
frame= read(VID,1+i-1);
imshow(frame(y(1):y(2),x(1):x(2),:),[]);
%rest
gyr_x_memory= gyr_x(1:i);
gyr_x_lowpass = [gyr_x_lowpass lowpass_filter(32,gyr_x_memory,gyr_x_lowpass)];%32
%gyr_x_lowpass=abs(gyr_x_lowpass);
gyr_y_memory= gyr_y(1:i);
gyr_y_lowpass = [gyr_y_lowpass lowpass_filter(20,gyr_y_memory,gyr_y_lowpass)];
%gyr_y_lowpass=abs(gyr_y_lowpass);
acc_z_memory= acc_z(1:i);
acc_z_lowpass = [acc_z_lowpass lowpass_filter(20,acc_z_memory,acc_z_lowpass)];
%acc_z_lowpass=abs(acc_z_lowpass);
acc_y_memory= acc_y(1:i);
acc_y_lowpass = [acc_y_lowpass lowpass_filter(64,acc_y_memory,acc_y_lowpass)];%20->30 meer gesmooth
addpoints(h,x(i),gyr_x_lowpass(i));
drawnow limitrate
addpoints(g,y(i),acc_z_lowpass(i));
drawnow limitrate
addpoints(f,z(i),gyr_y_lowpass(i));
drawnow limitrate
addpoints(e,w(i),acc_y_lowpass(i));
drawnow limitrate
end

Answers (1)

Image Analyst
Image Analyst on 16 Apr 2016

0 votes

Your "frame" appears to be 3D. Using [] in imshow() doesn't work for RGB images. So you're going to have to figure out why your "frame" values are not integers in the range 0 - 255.

16 Comments

I'm sorry, I don't know what that means. I added the [] in imshow because I read somewhere it could help. But even by using x=[329 752]; y=[50 411]; imshow(frame(y(1):y(2),x(1):x(2),:));
It doesn't work. But the video does play when I only use imshow in the figure, without the animatedline.
what is max(max(max(frame(y(1):y(2),x(1):x(2),:)))) and min(min(min(frame(y(1):y(2),x(1):x(2),:))))
255 and 0
It's not double is it? What does this say:
whos frame
Can you call imwrite and then attach it here. Step through it and when you get a black image, type this in the command window and then attach it back here with the paper clip icon
imwrite(frame, 'frame.png');
whos frame gives the following:
Name Size Bytes Class Attributes
frameA 480x854x3 1229760 uint8
You forgot to attach it.
This is what imwrite saves
Here is a dropbox file with: https://www.dropbox.com/sh/ziw5s7pcnp8nfmu/AABNrHJxiuhPuppGT7hE9rsPa?dl=0
*A video of what happens when I put the animatedline in comment: this is what I want to have as video
  • What I have now: the animatedlines work but the video is black
  • my code: Parameter_extraction_for_lus_MET_DATA_SYNC_INGEBOUWD
I can't reproduce your issue. When I display that with imshow() it looks fine, not dark or black.
Loic Van Aelst
Loic Van Aelst on 17 Apr 2016
Edited: Loic Van Aelst on 17 Apr 2016
yes but not when you remove the comments on the animatedline. I can't plot the animatedline and the video together. See my videos I added
Then you will probably have to attach 'Zwemvideo1.mp4' so we can run your code completely.
Loic Van Aelst
Loic Van Aelst on 17 Apr 2016
Edited: Loic Van Aelst on 17 Apr 2016
Its in the dropbox file
https://www.dropbox.com/sh/ziw5s7pcnp8nfmu/AABNrHJxiuhPuppGT7hE9rsPa?dl=0
Your code here doesn't run.
Undefined function or variable 'acc_y'.
Error in test3 (line 14)
acc_y = resample(acc_y,3,4);
Exactly what would one need to do to run it?
Loic Van Aelst
Loic Van Aelst on 17 Apr 2016
Edited: Loic Van Aelst on 17 Apr 2016
load('zwemproef150219.mat'); data = ['acc_x';'acc_y';'acc_z';'gyr_x';'gyr_y';'gyr_z'];
I added this zwemproef in the last link.
Are the addpoints supposed to go to other axes, or onto the image axes?
If onto the image axes, then perhaps use hold on.
If onto one of the top 4 axes, then use subplot() to switch the current axes back to the one it's supposed to plot into.
Loic Van Aelst
Loic Van Aelst on 18 Apr 2016
Edited: Loic Van Aelst on 18 Apr 2016
The addpoints are supposed to go on the first 4 subplots. The 5th subplot is the video. Here is a video of the animatedline plot without the video: https://www.dropbox.com/sh/29yh6d0xw36kyw6/AABtTQugPHo5yt98a720DCtra?dl=0
Edit: I added subplot(5,1,1) and so on before the addpoints, but it doesn't chang anything

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Asked:

on 16 Apr 2016

Edited:

on 18 Apr 2016

Community Treasure Hunt

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

Start Hunting!