Horus Doc || User Guide || Introduction   Installation   Getting Started  

An example of a generalized convolution: Erosion

The scripting languages may also be used to define functions that have no C++ counterpart (yet). The function 'myErosion' uses generalized onvolution to perform a classical erosion with a flat structuring element. The erosion is performed by supplying the generalized convolution with 'add' and 'minAssign' as basic operations.

IDL script

Erosion is demonstrated in demoErosion.cs

# Demo: shows how to do erosions on Horus images

# Definition of my own erosion function
#
# im is an ImageRep
# size is an int
#
proc myErosion(im, size)
{
    # Use the same signature as the input image
    sig = im.signature();

    # Define the sizes of the structuring element
    sizes = HxCorba.Sizes(size, size, 1);

    # The pixel value of the structuring element
    val = HxCorba.PixValue(HxCorba.PixValueTag.SI, 0);

    # Now construct the structuring element
    kernel = OPS.HxMakeFromValue(sig, sizes, val);
    
    # And apply the operation, using minimum
    empty = CTOR.emptyTagList();
    prec = HxCorba.ResultPrecision.ARITH_PREC;
    return im.generalizedConvolution(kernel, "add", "minAssign", prec, empty);
    
    # Could also use infimum, produces slightly different results.
    #return im.generalizedConvolution(kernel, "add", "infAssign", prec, empty);
}


println("Enter name of image, e.g. c:/images/flamingo.tif");
name = getline();

# Read image from disk
a = OPS.HxMakeFromFile(name);

# Apply my own erosion
b = myErosion(a, 5);

and executed with exec("x:/HxSamples/Scripts/demoErosion.cs");.

Matlab

Erosion is demonstrated in demoErosion.m

%demoErosion  Demo: shows how to do erosions on Horus images

echo on
clc

name = input('Enter name of image, e.g. c:/images/flamingo.tif\n', 's');

% Read image from disk
a = OPS.HxMakeFromFile(name);

% Display the image
hxShow(a);

pause % Press any key to continue

% Apply my own erosion
b = myErosion(a, 5);

% And display it
hxShow(b);

and executed with demoErosion.

The function myErosion is defined in myErosion.m

function r = myErosion(im, size)

%myErosion    Definition of my own erosion function 
%    im is a Horus image (Java stub).
%    size is an int.

global CTOR
global OPS

% Use the same signature as the input image
sig = im.signature;

% Define the sizes of the structuring element
sizes = HxCorba.Sizes(size, size, 1);

% The pixel value of the structuring element
val = HxCorba.PixValue;
val.scalarInt(0);

% Now construct the structuring element
kernel = OPS.HxMakeFromValue(sig, sizes, val);

% And apply the operation, using minimum
empty = CTOR.emptyTagList;
% Due to a bug in Matlab, the following statement crashes in a script.
%prec = HxCorba.ResultPrecision.ARITH_PREC;
prec = HxCorba.ResultPrecision.from_int(1);
r = im.generalizedConvolution(kernel, 'add', 'minAssign', prec, empty);

% Could also use infimum, produces slightly different results.
%r = im.generalizedConvolution(kernel, 'add', 'infAssign', prec, empty);


Go to the next section or return to the index.


Generated on Mon Jan 27 15:12:12 2003 for UserGuide by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001