/* * Copyright (c) 2001, University of Amsterdam, The Netherlands. * All rights reserved. * * Author(s): * Dennis Koelma (koelma@science.uva.nl) */ #include "HxUniformNonSep.h" #include "HxMakeFromValue.h" HxImageRep HxUniformNonSep(HxImageRep im, HxSizes sizes) { // An image signature for a 2D image with 64-bit real valued scalar pixels HxImageSignature sig(im.dimensionality(), 1, REAL_VALUE, 64); // The pixel value of the uniform kernel double val = 1.0 / (sizes.x() * sizes.y() * sizes.z()); // Now construct the kernel image HxImageRep kernel = HxMakeFromValue(sig, sizes, val); // and apply the operation return im.generalizedConvolution(kernel, "mul", "addAssign"); }
Basically, a uniform filter is a convolution with a uniform kernel. A convolution is performed by supplying the generalized convolution with multiplication and addition as basic operations.
A uniform kernel image is constructed from the following parameters:
Read 'flamingo' from disk. Apply the function HxUniformNonSep (menu 'GlobalOps/Images/Filter') with parameter '5 5'.
In order to do uniform filtering via a generic function we first have to construct the kernel image and then perform a convolution on the image via the generalized convolution.
Uniform filtering is demonstrated in demoUniform.cs
# Demo: shows how to apply a uniform 5x5 filter to Horus images println("Enter name of image, e.g. c:/images/flamingo.tif"); name = getline(); # Read image from disk a = OPS.HxMakeFromFile(name); # An image signature for a 2D image with 64-bit real valued scalar pixels sig = HxCorba.ImageSignature.SIG2DDOUBLE; # Define the sizes of the neighbourhood sizes = HxCorba.Sizes(5, 5, 1); # The pixel value of the uniform kernel val = HxCorba.PixValue(HxCorba.PixValueTag.SD, 1.0 / (sizes.x * sizes.y * sizes.z)); # Now construct the kernel image kernel = OPS.HxMakeFromValue(sig, sizes, val); # Apply the operation empty = CTOR.emptyTagList(); prec = HxCorba.ResultPrecision.ARITH_PREC; b = a.generalizedConvolution(kernel, "mul", "addAssign", prec, empty);
and executed with exec("x:/HxSamples/Scripts/demoUniform.cs");
.
Matlab
Uniform filtering is demonstrated in demoUniform.m
%demoUniform Demo: shows how to apply a uniform 5x5 filter to 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 % An image signature for a 2D image with 64-bit real valued scalar pixels sig = HxCorba.ImageSignature.SIG2DDOUBLE; % Define the sizes of the neighbourhood sizes = HxCorba.Sizes(5, 5, 1); % The pixel value of the uniform kernel val = HxCorba.PixValue; val.scalarDouble(1.0 / (sizes.x * sizes.y * sizes.z)); % Now construct the kernel image kernel = OPS.HxMakeFromValue(sig, sizes, val); % Apply the operation 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);
and executed with demoUniform
.