im2grayが未定義となり先に進めません。

6 ビュー (過去 30 日間)
Noruji Muto
Noruji Muto 2021 年 12 月 10 日
コメント済み: Noruji Muto 2021 年 12 月 10 日
お世話になります。
現在、動画内を移動する微粒子の数を取得するというコードの作成のために、
ヘルプセンターにある「オブジェクトのカウント」を参照しています。↓
このURLのコードの中で、「im2gray」という関数が出てくるのですが、コードをそのままコピペして自分の開発環境で実行すると
「関数または変数 'im2gray' が未定義です。」と表示されてしまい、先に進めず困っています。
image = im2gray(im2single(readFrame(hvfr)));
エラーは以下のとおりです。
関数または変数 'im2gray' が未定義です。
エラー: Untitled2 (line 2)
image = im2gray(im2single(readFrame(hvfr)));
実際に実行したコードの全体以下のとおりです。
VideoSize = [432 528];
filename = 'ecolicells.avi';
hvfr = VideoReader(filename);
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'];
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;
which
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, 'TextColor', 'white');
image = insertText(image, [1 size(image,1)], ackText, ...
'FontSize', 10, 'AnchorPoint', 'LeftBottom', ...
'BoxOpacity', 0, 'TextColor', 'white');
% Display video
image_out = insertMarker(image, Centroid, '*', 'Color', 'green');
step(hVideo, image_out);
frameCount = frameCount + 1;
end
エラーは全く同じものが出てきます。
どうか皆様のお知恵をお貸し下さい。

採用された回答

Atsushi Ueno
Atsushi Ueno 2021 年 12 月 10 日
ドキュメントの最後に書いてあるのですが、im2gray関数は「R2020b で導入」という事なので、R2019aでは使用できません。代わりに、もっと前から在るrgb2gray関数でも機能すると思います。
  1 件のコメント
Noruji Muto
Noruji Muto 2021 年 12 月 10 日
ご回答ありがとうございます。
そのとおりにしたところ、無事に動きました。
ありがとうございました。

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchangeインポート、エクスポートおよび変換 についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!