Main Content

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

イメージ比較ツールの作成

この例では、位置と倍率が同期している 2 つのイメージがスクロール パネルに並べて表示される GUI を作成する方法を説明します。

まず、アプリを作成する関数を定義します。この例では、my_image_compare_tool と呼ばれる関数を指定します (関数は例の終わりに添付します)。

アプリを作成する関数を定義した後、このアプリをテストします。2 つのイメージを取得します。

I = imread('flamingos.jpg');
L = rgb2lightness(I);
Iedge = edge(L,'Canny');

アプリでイメージを表示します。概要ツールで詳細四角形を移動したり、1 つのイメージで倍率を変えたりすると、両方のイメージが反応します。

my_image_compare_tool(I,Iedge);

Figure Overview (My Image Compare Tool) contains an axes object and other objects of type uipanel, uitoolbar, uimenu. The axes object contains 8 objects of type line, patch, image.

Figure My Image Compare Tool contains 2 axes objects and other objects of type uipanel, uicontrol. Axes object 1 contains an object of type image. Axes object 2 contains an object of type image.

アプリ作成関数

関数 my_image_compare_tool は、2 つのイメージを入力引数として受け入れ、スクロール パネルにイメージを表示します。カスタム ツールには概要ツールと倍率ボックスも含まれています。スクロール可能なナビゲーションは標準の MATLAB™ Figure ウィンドウのナビゲーション ツールとの互換性がないため、この関数は Figure ウィンドウのツール バーとメニュー バーを表示しないことに注意してください。

スクロール パネルを同期するため、この関数はコールバックおよびスクロール パネルの API 関数を使用して、ツール間の接続を作成します。倍率が変わるたびにコールバック関数が実行されるように指定されます。指定される関数は、もう一方のスクロール パネルの API 関数 setMagnification です。こうして、一方のスクロール パネルで倍率が変わると、もう一方のスクロール パネルの倍率が変わって一致します。位置の変更にも同様の接続が設定されます。

function my_image_compare_tool(left_image,right_image)

% Create the figure
hFig = figure('Toolbar','none',...
              'Menubar','none',...
              'Name','My Image Compare Tool',...
              'NumberTitle','off',...
              'IntegerHandle','off');
          
% Display left image              
subplot(121)  
hImL = imshow(left_image);

% Display right image
subplot(122)
hImR = imshow(right_image);

% Create a scroll panel for left image
hSpL = imscrollpanel(hFig,hImL);
set(hSpL,'Units','normalized',...
    'Position',[0 0.1 .5 0.9])

% Create scroll panel for right image
hSpR = imscrollpanel(hFig,hImR);
set(hSpR,'Units','normalized',...
    'Position',[0.5 0.1 .5 0.9])

% Add a Magnification box 
hMagBox = immagbox(hFig,hImL);
pos = get(hMagBox,'Position');
set(hMagBox,'Position',[0 0 pos(3) pos(4)])

%% Add an Overview tool
imoverview(hImL) 

%% Get APIs from the scroll panels 
apiL = iptgetapi(hSpL);
apiR = iptgetapi(hSpR);

%% Synchronize the left and right scroll panels
apiL.setMagnification(apiR.getMagnification())
apiL.setVisibleLocation(apiR.getVisibleLocation())

% When the magnification changes on the left scroll panel, 
% tell the right scroll panel
apiL.addNewMagnificationCallback(apiR.setMagnification);

% When the magnification changes on the right scroll panel, 
% notify the left scroll panel
apiR.addNewMagnificationCallback(apiL.setMagnification);

% When the location changes on the left scroll panel, 
% notify the right scroll panel
apiL.addNewLocationCallback(apiR.setVisibleLocation);

% When the location changes on the right scroll panel, 
% notify the left scroll panel
apiR.addNewLocationCallback(apiL.setVisibleLocation);

end

参考

| |

関連する例

詳細