在MATLAB中播放图像序列

时间:2012-06-01 04:55:41

标签: image matlab user-interface video sequence

向大家致以问候。

我有这个令人沮丧的问题,我希望你帮我解决它。

我正在MATLAB中开发人体跟踪系统,并希望将结果展示在一个吸引人的GUI中(也可以在MATLAB中使用GUIDE)。

有一个主窗口,大小为320x240的大约2500张灰度图像的图像序列将像视频一样播放,但人们可以很好地勾勒出人物的轮廓。

挑战是;这些图像在显示在窗口之前需要进行一些处理(检测人类的轮廓)。

现在,是否可以显示一组图像,同时对另一组进行一些处理后显示?

我非常希望它像普通视频一样播放,但我想这会有点雄心勃勃。

1 个答案:

答案 0 :(得分:2)

以下示例显示了与您描述的方案类似的方案。这是根据我在评论中提到的demo改编的。

function ImgSeqDemo()
    figure()
    for i=1:10
        %# read image
        img = imread( sprintf('AT3_1m4_%02d.tif',i) );

        %# process image to extract some object of interest
        [BW,rect] = detectLargestCell(img);

        %# show image
        imshow(img), hold on

        %# overlay mask in red color showing object
        RGB = cat(3, BW.*255, zeros(size(BW),'uint8'), zeros(size(BW),'uint8'));
        hImg = imshow(RGB); set(hImg, 'AlphaData',0.5);

        %# show bounding rectangle
        rectangle('Position', rect, 'EdgeColor','g');
        hold off

        drawnow
    end
end

这是上面使用的处理功能。在您的情况下,您将插入您的算法:

function [BW,rect] = detectLargestCell(I)
    %# OUTPUT
    %#    BW    binary mask of largest detected cell
    %#    rect  bounding box of largest detected cell

    %# find components
    [~, threshold] = edge(I, 'sobel');
    BW = edge(I,'sobel', threshold*0.5);
    se90 = strel('line', 3, 90);
    se0 = strel('line', 3, 0);
    BW = imdilate(BW, [se90 se0]);
    BW = imclearborder(BW, 4);
    BW = bwareaopen(BW, 200);
    BW = bwmorph(BW, 'close');
    BW = imfill(BW, 'holes');

    %# keep largest component
    CC = bwconncomp(BW);
    stats = regionprops(CC, {'Area','BoundingBox'});
    [~,idx] = max([stats.Area]);
    rect = stats(idx).BoundingBox;
    BW(:) = 0;
    BW(CC.PixelIdxList{idx}) = 1;
end

screenshot