/*
* Copyright (c) 2000, University of Amsterdam, The Netherlands.
* All rights reserved.
*
* Author(s):
* Marc Navarro (mnavarro@wins.uva.nl)
* Dennis Koelma (koelma@wins.uva.nl)
*/
#include "HxAdd.h"
#include "HxPixMax.h"
#include "HxUnaryMax.h"
HxImageRep
HxAdd(HxImageRep im1, HxImageRep im2)
{
HxString fname("HxAdd");
if (im1.isNull())
{
HxGlobalError::instance()->reportError(fname, im1.name(), "null image", HxGlobalError::HX_GE_INVALID);
return HxImageRep();
}
if (im2.isNull())
{
HxGlobalError::instance()->reportError(fname, im2.name(), "null image", HxGlobalError::HX_GE_INVALID);
return HxImageRep();
}
if (im1.dimensionality() != im2.dimensionality())
{
HxGlobalError::instance()->reportError(fname, "unequal image dimensionalities", HxGlobalError::HX_GE_UNEQUAL_IMAGES);
return HxImageRep();
}
if (im1.pixelDimensionality() != im2.pixelDimensionality())
{
HxGlobalError::instance()->reportError(fname, "unequal pixel dimensionalities", HxGlobalError::HX_GE_UNEQUAL_IMAGES);
return HxImageRep();
}
if (im1.sizes().x() != im2.sizes().x())
{
HxGlobalError::instance()->reportError(fname, "unequal image widths", HxGlobalError::HX_GE_UNEQUAL_IMAGES);
return HxImageRep();
}
if (im1.sizes().y() != im2.sizes().y())
{
HxGlobalError::instance()->reportError(fname, "unequal image heights", HxGlobalError::HX_GE_UNEQUAL_IMAGES);
return HxImageRep();
}
if (im1.dimensionality() > 2)
{
if (im1.sizes().z() != im2.sizes().z())
{
HxGlobalError::instance()->reportError(fname, "unequal image depths", HxGlobalError::HX_GE_UNEQUAL_IMAGES);
return HxImageRep();
}
}
// in case of byte, unsigned: generate warnings in case of potentially dangerous
// situations.
// Check if image is byte.
if (((im1.signature().pixelType() == INT_VALUE) &&
(im1.signature().pixelPrecision() == 8)) ||
((im2.signature().pixelType() == INT_VALUE) &&
(im2.signature().pixelPrecision() == 8)))
{
if ((im1.pixelDimensionality() == 1) && (im1.pixelDimensionality() == 1))
{
if ((HxPixMax(im1).HxScalarIntValue() +
HxPixMax(im2).HxScalarIntValue()) > HxScalarInt(255))
{
HxGlobalError::instance()->reportWarning(fname,
im1.name()+HxString(" ")+im2.name(),
"possible overflow due to byte precision",
HxGlobalError::HX_GW_OVERFLOW);
}
}
else if ((HxPixMax(HxUnaryMax(im1)).HxScalarIntValue() +
HxPixMax(HxUnaryMax(im2)).HxScalarIntValue()) > HxScalarInt(255))
{
HxGlobalError::instance()->reportWarning(fname,
im1.name()+HxString(" ")+im2.name(),
"possible overflow due to byte precision",
HxGlobalError::HX_GW_OVERFLOW);
}
}
return im1.binaryPixOp(im2, "add");
}
As shown in the code, HxAdd is just a wrapper around the generic binary pixel operation. For an example of how to use a global function in a C++ application see A first application.
MidApp
HxAdd can also be used via the menu and dialogue interface:
We can also execute the generic binary pixel operation directly:
Addition of images is demonstrated in demoAdd.cs
# Demo: shows how to add Horus images
println("Enter name of first image, e.g. c:/images/trui.tif");
name = getline();
println("Read image from disk");
a = OPS.HxMakeFromFile(name);
println("Enter name of second image, e.g. c:/images/cermet.tif");
name = getline();
println("Read image from disk");
b = OPS.HxMakeFromFile(name);
println("Now add the images using the global function HxAdd");
c = OPS.HxAdd(a, b);
println("Now add the images using the generic function");
d = a.binaryPixOp(b, "add", CTOR.emptyTagList());
and executed with exec("x:/HxSamples/Scripts/demoAdd.cs");.
Matlab
Addition of images is demonstrated in demoAdd.m
%demoAdd Demo: shows how to add Horus images
echo on
clc
name = input('Enter name of first image, e.g. c:/images/trui.tif\n', 's');
% Read image from disk
a = OPS.HxMakeFromFile(name);
% Display the image
hxShow(a);
name = input('Enter name of second image, e.g. c:/images/cermet.tif\n', 's');
% Read image from disk
b = OPS.HxMakeFromFile(name);
% And display it
hxShow(b);
pause % Press any key to continue
% Now add the images using the global function HxAdd
c = OPS.HxAdd(a, b);
% And display it
hxShow(c);
pause % Press any key to continue
% Now add the images using the generic function
d = a.binaryPixOp(b, 'add', CTOR.emptyTagList);
% And display it
hxShow(c);
and executed with demoAdd.
1.2.12 written by Dimitri van Heesch,
© 1997-2001