Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

細胞のカウント

この例では、基本的なモルフォロジー演算子とブロブ解析を組み合わせて使用して、ビデオ ストリームから情報を抽出する方法を説明します。ここでは各ビデオ フレームに含まれる大腸菌の数をカウントします。細胞の明るさが均一でないためにセグメンテーションのタスクが困難になる点に注意してください。

初期化

以下に挙げるコード セクションを使用して必要な変数とオブジェクトを初期化します。

VideoSize = [432 528];

avi ファイルからビデオを読み取る System object を作成します。

filename = 'ecolicells.avi';
hvfr = VideoReader(filename);

ビデオ内でセグメント化された細胞の重心を見つける BlobAnalysis の System object を作成します。

hblob = vision.BlobAnalysis( ...
                'AreaOutputPort', false, ...
                'BoundingBoxOutputPort', false, ...
                'OutputDataType', 'single', ...
                'MinimumBlobArea', 7, ...
                'MaximumBlobArea', 300, ...
                'MaximumCount', 1500);

% Acknowledgement
ackText = ['Data set courtesy of Jonathan Young and Michael Elowitz, ' ...
             'California Institute of Technology'];

ビデオを表示する System object を作成します。

hVideo = vision.VideoPlayer;
hVideo.Name  = 'Results';
hVideo.Position(1) = round(hVideo.Position(1));
hVideo.Position(2) = round(hVideo.Position(2));
hVideo.Position([4 3]) = 30+VideoSize;

ストリーム処理ループ

入力ビデオ内の細胞の数をカウントする処理ループを作成します。このループは上記でインスタンス化した System object を使用します。

frameCount = int16(1);
while hasFrame(hvfr)
    % Read input video frame
    image = im2gray(im2single(readFrame(hvfr)));

    % Apply a combination of morphological dilation and image arithmetic
    % operations to remove uneven illumination and to emphasize the
    % boundaries between the cells.
    y1 = 2*image - imdilate(image, strel('square',7));
    y1(y1<0) = 0;
    y1(y1>1) = 1;
    y2 = imdilate(y1, strel('square',7)) - y1;

    th = multithresh(y2);      % Determine threshold using Otsu's method    
    y3 = (y2 <= th*0.7);       % Binarize the image.
    
    Centroid = step(hblob, y3);   % Calculate the centroid
    numBlobs = size(Centroid,1);  % and number of cells.
    % Display the number of frames and cells.
    frameBlobTxt = sprintf('Frame %d, Count %d', frameCount, numBlobs);
    image = insertText(image, [1 1], frameBlobTxt, ...
            'FontSize', 16, 'BoxOpacity', 0, 'FontColor', 'white');
    image = insertText(image, [1 size(image,1)], ackText, ...
            'FontSize', 10, 'AnchorPoint', 'LeftBottom', ...
            'BoxOpacity', 0, 'FontColor', 'white');

    % Display video
    image_out = insertMarker(image, Centroid, '*', 'MarkerColor', 'green');   
    step(hVideo, image_out);

    frameCount = frameCount + 1;
    pause(1);
end

Figure Results contains an axes object and other objects of type uiflowcontainer, uimenu, uitoolbar. The axes object contains an object of type image.

まとめ

[Results] ウィンドウに元のビデオが表示されます。緑のマーカーは細胞の重心の位置を示します。左上隅にはフレーム番号とセルの数が表示されます。

データ セットの著作権について

この例で使用したデータ セットは、California Institute of Technology の Jonathan Young および Michael Elowitz により提供されたものです。データは許可を得て使用されています。このデータに関する追加情報については、次を参照してください。

N. Rosenfeld, J. Young, U. Alon, P. Swain, and M.B. Elowitz, "Gene Regulation at the Single-Cell Level, " Science 2005, Vol. 307, pp. 1962-1965.