低輝度、高輝度ピクセルの強調 その2 (Version 3.3)
その1のサンプルを発展させ、プログラムからフィルタのパラメータをコントロールする方法を示しています。
| Software | IC Imaging Control 3.3, Visual Studio™ 2010 | 
|---|---|
| サンプル(C#) | mark_pixels2_cs.zip | 
| サンプル(VB.NET) | mark_pixels2_vb7.zip | 
| 関連ファイル | clipping_vc7_framefilter.zip | 

このサンプルでは、低輝度/高輝度ピクセルの表示強調について専用のダイアログを使用するのではなく、直接パラメータを操作する方法を示しています。
まず、TIS.Imaging.FrameFilter のfilter 変数はForm1クラスの中で定義される必要があります。この変数はフレームフィルタとその通信に使用されます。
private TIS.Imaging.FrameFilter filter;Private filter As TIS.Imaging.FrameFilterこのフィルタは以下に示すパラメータを持っています。
Threshold: しきい値
        ClipAboveThreshold: しきい値以上、または以下どちらかかを示すスイッチ
FillMode, FillColor: 抽出したピクセルを表示するための色やパターンを示す
しきい値はスライドバーsldThresholdで操作します。しきい値以上、または以下どちらを抽出するのかについては、2つのラジオボタンrbClipAbove と rbClipBelow でコントロールします。プログラムの最初にそのメインフォームで 指定、初期化されています。
InitControls();
UpdateControls();InitControls()
UpdateControls()InitControls 関数により、スライドバーsldThresholdの最小値と最大値が初期化されています。
private void InitControls()
{
    sldThreshold.Minimum = 0;
    sldThreshold.Maximum = 255;
}  Private Sub InitControls()
    sldThreshold.Minimum = 0
    sldThreshold.Maximum = 255
End SubUpdateControls 関数にて、"Enable", "Threshold", "ClipAboveThreshold" のパラメータはそれぞれチェックボックス cbEnable, スライドバーsldThresholdと、ラジオボタン rbClipAboveとrbClipBelowにそれぞれ割り当てられます。
private void UpdateControls()
{
    filter.BeginParameterTransfer();
    // "Enable" チェックボックスの更新
    cbEnable.Checked = filter.GetBoolParameter("Enable");
    // ラジオボタンの更新
    bool state = filter.GetBoolParameter("ClipAboveThreshold");
    rbClipAbove.Checked = state;
    rbClipBelow.Checked = !state;
    // スライダーの更新
    sldThreshold.Value = filter.GetIntParameter("Threshold");
    txThreshold.Text = sldThreshold.Value.ToString();
    filter.EndParameterTransfer();
} Private Sub UpdateControls()
    filter.BeginParameterTransfer()
    ' "Enable" チェックボックスの更新
    cbEnable.Checked = filter.GetBoolParameter("Enable")
    ' ラジオボタンの更新
    Dim state As Boolean = filter.GetBoolParameter("ClipAboveThreshold")
    rbClipAbove.Checked = state
    rbClipBelow.Checked = Not state
    ' スライダーの更新
    sldThreshold.Value = filter.GetIntParameter("Threshold")
    txThreshold.Text = sldThreshold.Value
    filter.EndParameterTransfer()
End SubスクロールバーsldThresholdのイベントハンドラーで、その現在の値をフィルタのパラメータ"Threshold"に更新してそのテキストフィールドtxThresholも更新します。
private void sldThreshold_Scroll(object sender, System.EventArgs e)
{
    filter.BeginParameterTransfer();
    filter.SetIntParameter("Threshold", sldThreshold.Value);
    filter.EndParameterTransfer();
    txThreshold.Text = sldThreshold.Value.ToString();
}  Private Sub sldThreshold_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sldThreshold.Scroll
    filter.BeginParameterTransfer()
    filter.SetIntParameter("Threshold", sldThreshold.Value)
    filter.EndParameterTransfer()
    txThreshold.Text = sldThreshold.Value
End Sub
ラジオボタン rbClipAboveのイベントハンドラーで、"ClipAboveThreshold" をTrueに、rbClipBelowをfalseに設定します。 rbClipBelow のイベントハンドラーでは逆に設定します。
private void rbClipAbove_CheckedChanged(object sender, System.EventArgs e)
{
    filter.BeginParameterTransfer();
    filter.SetBoolParameter("ClipAboveThreshold", true);
    filter.EndParameterTransfer();
    rbClipBelow.Checked = false;
}
private void rbClipBelow_CheckedChanged(object sender, System.EventArgs e)
{
    filter.BeginParameterTransfer();
    filter.SetBoolParameter("ClipAboveThreshold", false);
    filter.EndParameterTransfer();
    rbClipAbove.Checked = false;
}  Private Sub rbClipBelow_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbClipBelow.CheckedChanged
    filter.BeginParameterTransfer()
    filter.SetBoolParameter("ClipAboveThreshold", False)
    filter.EndParameterTransfer()
    rbClipAbove.Checked = False
End Sub
Private Sub rbClipAbove_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbClipAbove.CheckedChanged
    filter.BeginParameterTransfer()
    filter.SetBoolParameter("ClipAboveThreshold", True)
    filter.EndParameterTransfer()
    rbClipBelow.Checked = False
End Sub


