対話型プログラム内で誤操作をした時に処理をやり直す方法はありますか
2 views (last 30 days)
Show older comments
現在,対話型のプログラムを作成しています.具体的な処理は画像を表示させてその画像をクリックしてピクセル値を読み取るといったものです.
プログラムの簡易的な例
figure
hIm=imshow(img); % 画像表示
[xi,yi] = getpts;%クリックでピクセル値取得
このプログラムに,誤って操作してしまった場合に画像の表示からやり直す処理を追加したいのですが何かいい方法はないでしょうか.解答よろしくお願いいたします.
1 Comment
Atsushi Ueno
on 6 Jul 2021
手続き型でも可能ですが、イベント駆動で分かり易いプログラム構成にすべきです。
また「関数 getpts は推奨されません」との指摘もありますし、AppDesignerとの親和性も考慮すると、getptsから下記drawpointに切り替えるべきだと思います。こちらを試しては如何でしょう。(Image Processing Toolboxを持っておらず動作確認出来ません)
Accepted Answer
Atsushi Ueno
on 6 Jul 2021
Edited: Atsushi Ueno
on 6 Jul 2021
下記ツールを使って、ユーザがピクセルを選択⇒YES回答するまで繰り返す処理を追加すれば良いと思います。
img = uint8(randi([0 255],[100 100 3])); % 仮の画像データ
figure
hIm=imshow(img); % 画像表示
answer = true;
while answer
[xi,yi] = getpts; % クリックでピクセル値取得
answer = questdlg('本当にそこですか?','ピクセル値取得','No');
switch answer
case 'Yes'
answer = false;
case 'No'
answer = true;
case 'Cancel'
answer = true;
end
end
More Answers (0)
See Also
Categories
Find more on コンピューター ビジョンと Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!