2017-07-17 7 views
0

Matlabでimfreehand関数を使用して多重ROIを作成しようとしていました。ユーザーは必要なROIを十分に選択した後、ESCキーを押して停止することができます。ここに私のコードはありますが、エラーがあります。Matlabはimfreehandを使用して多重ROIを描画し、ESCプレスを使用して終了します

Error: Expected one output from a curly brace or dot indexing expression, but there were 0 results. 

誰かが私を助けて、問題を指摘することはできますか?コードは、問題は、あなたがEscキーを打ったとき、imfreehandツールが終了し、空の時間を返すことで、ここから

Draw multiple regions on an image- imfreehand

おかげ

I = imread('pout.tif'); 

totMask = zeros(size(I)); % accumulate all single object masks to this one 
f = figure('CurrentCharacter','a'); 
imshow(I) 

h = imfreehand(gca); setColor(h,'green'); 
position = wait(h); 
BW = createMask(h); 
while double(get(f,'CurrentCharacter'))~=27 
     totMask = totMask | BW; % add mask to global mask 
     % ask user for another mask 
     h = imfreehand(gca); setColor(h,'green'); 
     position = wait(h); 
     BW = createMask(h); 
     pause(.1) 
end 
% show the resulting mask 
figure; imshow(totMask); title('multi-object mask'); 

答えて

1

に変更されます。したがって、setColor(h,'green');が失敗します。 また、ループ内にBWを定義した後にtotMask = totMask | BW;を追加する必要があります。そうしないと、最後のROIが失われます。

はこれを試してみてください:

totMask = zeros(size(I)); % accumulate all single object masks to this one 
f = figure('CurrentCharacter','a'); 
imshow(I) 

h = imfreehand(gca); setColor(h,'green'); 
position = wait(h); 
BW = createMask(h); 
totMask = totMask | BW; % add mask to global mask 
while double(get(f,'CurrentCharacter'))~=27 
    % ask user for another mask 
    h = imfreehand(gca); 
    if isempty(h) 
     % User pressed ESC, or something else went wrong 
     continue 
    end 
    setColor(h,'green'); 
    position = wait(h); 
    BW = createMask(h); 
    totMask = totMask | BW; % add mask to global mask 
    pause(.1) 
end 
% show the resulting mask 
figure; imshow(totMask); title('multi-object mask'); 

はまた、最後に私が代わりにimshowimagescを使用していますのでご注意:これは正しく関心領域を示す、0と1の間の出力画像の色をスケールします。

+0

あなたの完璧なソリューションをありがとう!それはうまくいく、 – SimaGuanxing

関連する問題