C++ console application
An example of a C++ console application is given in HxSamples/ConsDemo/mainDemoImageOps.c :
/* * Copyright (c) 2000, University of Amsterdam, The Netherlands. * All rights reserved. * * Author(s): * Dennis Koelma (koelma@wins.uva.nl) * Edo Poll (poll@wins.uva.nl) * Marc Navarro (mnavarro@wins.uva.nl) * */ #include <cstdlib> #include "HxImageRepGlobalFuncs.h" #ifdef WIN32 const HxString inputDir = "//carol/horus/images/"; const HxString outputDir = "c:/output/"; #else const HxString inputDir = "/home/horus/images/"; const HxString outputDir = HxString(getenv("HOME")) + "/output/"; #endif int main(int argc, char* argv[]) { HxString inputFileName = inputDir + "bnoise.tif"; STD_COUT << "Reading [" << inputFileName << "]" << STD_ENDL; HxImageRep im = HxMakeFromFile(inputFileName); STD_COUT << "Applying percentile filter" << STD_ENDL; HxImageRep result = HxPercentile(im, 3, 0.5); HxString outputFileName = outputDir + "blittlenoise.tif"; STD_COUT << "Writing result to [" << outputFileName << "]" << STD_ENDL; HxWriteFile(result, outputFileName); STD_COUT << "Done" << STD_ENDL; return 0; }
See A C++ console application for more information on compilation and execution of this example.
Note : All images mentioned can be found in http://www.science.uva.nl/~horus/images/ (or /home/horus/images). Output is written to 'c:\output' or '$HOME/output'. Make sure this directory exists before executing the demo.
MidApp
MidApp executes C++ functions via the Java binding of the IDL definitions. The IDL definitions of the Horus classes are in the HxCorba interface. The most important IDL interfaces are HxCorba::Constructor and HxCorba::GlobalOps. The Constructor interface is generally the starting point as it is used to make objects. The GlobalOps interface contains all global (C++) functions and is used to do most of the image processing stuff.
The MidApp has two ways to execute the application : via the menu & dialogue interface and via the builtin IDL script interpreter (jidlscipt).
In the menu & dialogue interface the Constructor and GlobalOps interfaces are accessible via the 'HxCorba' menu. GlobalOps also has its own menu.
To execute the three functions of the mainDemoImageOps application do this: (Note that reading the left-hand side of the dialogue box in top-down order gives an impression of the function call that will be executed)
im
for the 'ImageRep' (this will give the name 'im' to the resulting object) en c:/images/bnoise.tif
for the 'fileName' parameter. Press 'OK'. (if all is well you will now see the image) result
for the name of the result object. Select 'im' for the 'ImageRep' parameter. Enter 3
for the 'neighSize' parameter and 0.5
for the 'perc' parameter. Press 'OK' c:/output/blittlenoise.tif
for the 'fileName' parameter. Press 'OK'. global
in the IDL script window. (If you didn't quit the application since you executed the functions via the menu & dialogue interface you will also see the ImageRep objects).
The jidlscript code for our first sample application is given in HxSamples/Scripts/mainDemoImageOps.cs :
# Copyright (c) 2001, University of Amsterdam, The Netherlands. # All rights reserved. # # Author(s): # Dennis Koelma (koelma@wins.uva.nl) # println("Reading c:/images/bnoise.tif"); im = OPS.HxMakeFromFile("c:/images/bnoise.tif"); println("Applying percentile filter"); result = OPS.HxPercentile(im, 3, 0.5); println("Writing result to c:/output/blittlenoise.tif"); OPS.HxWriteFile(result, "c:/output/blittlenoise.tif"); println("Done");
You can execute the script by typing
exec("x:/HxSamples/Scripts/mainDemoImageOps.cs")
in the IDL script window.
CorbaScript
Since cssh is a standalone application, the first thing we have to do is contact the HxServer. You can get the Constructor and GlobalOps objects by executing
exec("hxInit.cs")
Note : you have to specify the full path with the exec function unless you are in the 'x:/HxSamples/Scripts' directory since the environment variable CSPATH only seems to work for the 'import' command.
You can verify the existance of the objects by typing global
. Execution of the sample application is done via
exec("mainDemoImageOps.cs")
Matlab
The Matlab code is in '$HXSRC/HxSamples/Matlab'. To avoid specifying the full path see Installation.
In Matlab, the Constructor and GlobalOps object are obtained by executing hxInit
. The sample application is implemented in $HXSRC/HxSamples/Matlab/hxMainDemoImageOps.m :
%hxMainDemoImageOps Demo: shows the basics of how to use Horus images % Copyright (c) 2001, University of Amsterdam, The Netherlands. % All rights reserved. % % Author(s): % Dennis Koelma (koelma@wins.uva.nl) echo on % Read c:/images/bnoise.tif im = OPS.HxMakeFromFile('c:/images/bnoise.tif'); % Applying percentile filter result = OPS.HxPercentile(im, 3, 0.5); % Writing result to c:/output/blittlenoise.tif OPS.HxWriteFile(result, 'c:/output/blittlenoise.tif');
and executed with hxMainDemoImageOps
.
Horus images may be converted to arrays to manipulate the image data using Matlab functionality.
a = hxImToArray(im);
produces a Matlab array. The array is visualized via
imagesc(a)
hxShow(im)
uses hxImToArray
to show a Horus image in Matlab. The function also handles color images in RGB format. For other color models hxGetRgb2d
can be used to display the image. However, hxGetRgb2d
does not do array ordering conversion so you will see the image on its side.