/*
 *  Copyright (c) 2000, University of Amsterdam, The Netherlands.
 *  All rights reserved.
 *
 *  Author(s):
 *  Marc Navarro            (mnavarro@wins.uva.nl)
 */
#include "HxThreshold.h"
HxImageRep
HxThreshold(HxImageRep im, HxValue level)
{
    HxTagList tags;
    HxAddTag(tags, "level", level);
    return im.unaryPixOp("threshold", tags);
}
This example introduces tags to pass parameters to the functor applied to each pixel in the image. Tags are used instead of parameters because they do not require changing the generic function signature. Tags are put in a HxTagList via the HxAddTag function. Be careful to give it the proper name, i.e. the same name as used in the functor.
The parameter is an HxValue. HxValue is able to represent all pixel types used in Horus.
MidApp
Read 'trui' from disk. Apply the function HxThreshold (menu 'GlobalOps/Images/Segmentation') with parameter 128. Set the display mode to 'Binary'.
In order to do thresholding via a generic function we first have to construct a taglist with the parameter. In general, Corba objects are constructed via a factory like mechanism since Corba doesn't have constructors. Once the taglist is constructed we can use it to add the parameter value and then pass it to the generic function.
Thresholding of images is demonstrated in demoThreshold.cs
# Demo: shows how to threshold Horus images
println("Enter name of image, e.g. c:/images/trui.tif");
name = getline();
# Read image from disk
a = OPS.HxMakeFromFile(name);
# Get an empty taglist from the constructor
tags = CTOR.emptyTagList();
# Allocate an HxValue object that represents a scalar integer 128
value = HxCorba.PixValue(HxCorba.PixValueTag.SD, 128);
# Add parameter to the tag list
tags.addValue("level", value);
# Do the actual operation
b = a.unaryPixOp("threshold", tags);
and executed with exec("x:/HxSamples/Scripts/demoThreshold.cs");.
Matlab
Thresholding of images is demonstrated in demoThreshold.m
%demoThreshold  Demo: shows how to threshold Horus images
echo on
clc
name = input('Enter name of image, e.g. c:/images/trui.tif\n', 's');
% Read image from disk
a = OPS.HxMakeFromFile(name);
% Display the image
hxShow(a);
pause % Press any key to continue
% Get an empty taglist from the constructor
tags = CTOR.emptyTagList;
% Allocate an HxValue object that represents a scalar integer 128
value = HxCorba.PixValue;
value.scalarInt(128);
% Add parameter to the tag list
tags.addValue('level', value);
% Do the actual operation
b = a.unaryPixOp('threshold', tags);
% And display it
hxShow(b);
and executed with demoThreshold.
1.2.12 written by Dimitri van Heesch,
 © 1997-2001