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
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
2016-4-17
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
2016-4-17
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
2016-4-17
Image Analyst
2016-4-17
You forgot to attach it.
Loic Van Aelst
2016-4-17
Loic Van Aelst
2016-4-17
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
2016-4-17
编辑:Loic Van Aelst
2016-4-17
Image Analyst
2016-4-17
Then you will probably have to attach 'Zwemvideo1.mp4' so we can run your code completely.
Loic Van Aelst
2016-4-17
编辑:Loic Van Aelst
2016-4-17
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
2016-4-17
编辑:Loic Van Aelst
2016-4-17
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
2016-4-18
编辑:Loic Van Aelst
2016-4-18
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!