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

回答 (1 件)

Image Analyst
Image Analyst 2016 年 4 月 16 日

0 投票

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 件のコメント

Loic Van Aelst
Loic Van Aelst 2016 年 4 月 17 日
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.
Walter Roberson
Walter Roberson 2016 年 4 月 17 日
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),:))))
Loic Van Aelst
Loic Van Aelst 2016 年 4 月 17 日
255 and 0
Image Analyst
Image Analyst 2016 年 4 月 17 日
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');
Loic Van Aelst
Loic Van Aelst 2016 年 4 月 17 日
whos frame gives the following:
Name Size Bytes Class Attributes
frameA 480x854x3 1229760 uint8
Image Analyst
Image Analyst 2016 年 4 月 17 日
You forgot to attach it.
Loic Van Aelst
Loic Van Aelst 2016 年 4 月 17 日
This is what imwrite saves
Loic Van Aelst
Loic Van Aelst 2016 年 4 月 17 日
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
Image Analyst
Image Analyst 2016 年 4 月 17 日
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 2016 年 4 月 17 日
編集済み: Loic Van Aelst 2016 年 4 月 17 日
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
Image Analyst
Image Analyst 2016 年 4 月 17 日
Then you will probably have to attach 'Zwemvideo1.mp4' so we can run your code completely.
Loic Van Aelst
Loic Van Aelst 2016 年 4 月 17 日
編集済み: Loic Van Aelst 2016 年 4 月 17 日
Its in the dropbox file
https://www.dropbox.com/sh/ziw5s7pcnp8nfmu/AABNrHJxiuhPuppGT7hE9rsPa?dl=0
Image Analyst
Image Analyst 2016 年 4 月 17 日
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 2016 年 4 月 17 日
編集済み: Loic Van Aelst 2016 年 4 月 17 日
load('zwemproef150219.mat'); data = ['acc_x';'acc_y';'acc_z';'gyr_x';'gyr_y';'gyr_z'];
I added this zwemproef in the last link.
Image Analyst
Image Analyst 2016 年 4 月 17 日
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 2016 年 4 月 18 日
編集済み: Loic Van Aelst 2016 年 4 月 18 日
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

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

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2016 年 4 月 16 日

編集済み:

2016 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by