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
.