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

An example of a generalized convolution: Convolution

To demonstrate the use convolutions with user-defined kernels we 'implement' a simple derivate in the x-direction (kernel is [-1 0 1]) and a Laplacian filter.

IDL script

Convolution is demonstrated in demoConvolution.cs

# Demo: shows how to do convolutions on Horus images

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

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

# Construct a 2D kernel with 32-bit integer valued scalar pixels
# initialized with the values -1, 0, and 1
data = [-1, 0, 1];
kernel = OPS.HxMakeFromIntData(1, 2, HxCorba.Sizes(3, 1, 1), data);

# Do a convolution
empty = CTOR.emptyTagList();
prec = HxCorba.ResultPrecision.ARITH_PREC;
b = a.generalizedConvolution(kernel, "mul", "addAssign", prec, empty);

# Construct a 2D kernel with 32-bit integer valued scalar pixels
# initialized with:
#  0 -1  0
# -1  4 -1
#  0 -1  0
data = [0, -1, 0, -1, 4, -1, 0, -1, 0];
kernel = OPS.HxMakeFromIntData(1, 2, HxCorba.Sizes(3, 3, 1), data);

# Do a convolution
c = a.generalizedConvolution(kernel, "mul", "addAssign", prec, empty);

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

Matlab

Convolution is demonstrated in demoConvolution.m

%demoConvolution  Demo: shows how to do convolutions on 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

% Construct a 2D kernel with 32-bit integer valued scalar pixels
% initialized with the values -1, 0, and 1
data = [-1 0 1];
kernel = OPS.HxMakeFromIntData(1, 2, HxCorba.Sizes(3, 1, 1), data);

% Do a convolution
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);
b = a.generalizedConvolution(kernel, 'mul', 'addAssign', prec, empty);

% And display it
hxShow(b);

pause % Press any key to continue

% Construct a 2D kernel with 32-bit integer valued scalar pixels
% initialized with:
%  0 -1  0
% -1  4 -1
%  0 -1  0
data = [0 -1 0 -1 4 -1 0 -1 0];
kernel = OPS.HxMakeFromIntData(1, 2, HxCorba.Sizes(3, 3, 1), data);

% Do a convolution
c = a.generalizedConvolution(kernel, 'mul', 'addAssign', prec, empty);

% And display it
hxShow(c);


and executed with demoConvolution.


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