Main Content

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

ピクセル情報を表示するアプリの作成

この例では、モジュラー ピクセル情報ツールを使用してイメージの特徴とピクセルに関する情報を表示するシンプルなアプリを作成する方法を説明します。

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

アプリを作成する関数を定義した後、このアプリをテストします。イメージをワークスペースに読み取ります。

I = imread('pears.png');

アプリ内のピクセル情報ツールでイメージを表示します。

 my_pixinfo_tool(I)

Figure My Pixel Info Tool contains 2 axes objects and other objects of type uipanel. Axes object 1 contains 53 objects of type line, image, text. Axes object 2 contains 17 objects of type line, text, patch, image.

アプリ作成関数

関数 my_pixinfo_tool は、イメージを引数として受け入れ、ピクセル情報ツール、表示範囲ツール、距離ツールおよびピクセル領域ツールと共に Figure ウィンドウにイメージを表示します。スクロール可能なナビゲーションは標準の MATLAB™ Figure ウィンドウのナビゲーション ツールとの互換性がないため、この関数は Figure ウィンドウのツール バーとメニュー バーを表示しないことに注意してください。

function my_pixinfo_tool(im)
% Create figure, setting up properties
fig = figure('Toolbar','none', ...
              'Menubar','none', ...
              'Name','My Pixel Info Tool', ...
              'NumberTitle','off', ...
              'IntegerHandle','off');

% Create axes and reposition the axes
% to accommodate the Pixel Region tool panel
ax = axes('Units','normalized', ...
           'Position',[0 .5 1 .5]);

% Display image in the axes
img = imshow(im);

% Add Distance tool, specifying axes as parent
distool = imdistline(ax);

% Add Pixel Information tool, specifying image as parent
pixinfo = impixelinfo(img);

% Add Display Range tool, specifying image as parent
drange = imdisplayrange(img);

% Add Pixel Region tool panel, specifying figure as parent
% and image as target
pixreg = impixelregionpanel(fig,img);

% Reposition the Pixel Region tool to fit in the figure
% window, leaving room for the Pixel Information and
% Display Range tools
set(pixreg, 'units','normalized','position',[0 .08 1 .4])

end

参考

| | |

関連する例

詳細