如何在 MATLAB 中有效地找到所有像素颜色相同的视频帧?

How to efficiently find video frames with all pixels in a same color in MATLAB?

在 MATLAB 中读取具有此规格的视频文件 say:vid1.wmv 的有效方法(意味着使用更少的循环和更短的 运行 时间)是什么(长度:5 分钟,帧)宽度:640,帧高:480,帧速率:30 frames/sec) 并提取所有像素颜色相同(例如:黑色)且具有公差的帧的时间戳。 以下是我的代码,非常耗时。每帧大约需要三分钟!

clear
close all
clc

videoObject = VideoReader('vid1.wmv');
numFrames = get(videoObject, 'NumberOfFrames');
all_same_color_frame=[];
for i=1:numFrames
    frame = read(videoObject,i); % reading the 10th frame
    W = get(videoObject, 'Width');
    H = get(videoObject, 'Height');
    q=1;
    for j=1:H
        for k=1:W
            rgb(q).pixl(i).frm = impixel(frame,j,k);
            q=q+1;
        end
    end
    Q=1;
    for x=1:q-1
        if std(rgb(x).pixl(i).frm)==0 % strict criterion on standard deviation
            Q=Q+1;
        end
    end
    if Q>0.9*q % if more than 90 percent of all frames had the same color
        all_same_color_frame = [all_same_color_frame i];
    end
end

提前致谢

您可以并行化您的循环框架,因为没有依赖性。

不清楚您要做什么,但您绝对应该尝试计算每帧(二维)的标准偏差(或任何指标),而不是每次都将值收集到向量中,因为这不会有效率。

videoObject = VideoReader('vid1.wmv');
b=[];t=[];
i=1;
while hasFrame(videoObject)
    a = readFrame(videoObject);
    b(i) = std2(a); % standard deviation for each image frame
    t(i) = get(videoObject, 'CurrentTime'); % time stamps of the frames for visual inspection
    i=i+1;
end
plot(t,b) % visual inspection

以上是我的解决方案,使用标准偏差来检测几乎所有像素都具有相同颜色的帧。