|
#define | SIGNAL3D_bilinear(__A, __B, __C, __D, __px, __py, __target) |
|
#define | GO_SIGNAL3D_EACHELEMENT(__dothis, __signal, __type) |
|
#define | GO_SIGNAL3D_EACHELEMENT_GENERIC(__dothis, __signal) |
| For generic (void type) signals. More...
|
|
#define | GO_SIGNAL3D_EACHELEMENT_GENERIC_CONST(__dothis, __signal) |
|
#define | GO_SIGNAL3D_EACHELEMENT_2(__dothis, __signal, __signal_target, __type, __type_target) |
|
#define | GO_SIGNAL3D_EACHELEMENT_2_GENERIC(__dothis, __signal, __signal_target) |
|
#define | GO_SIGNAL3D_EACHELEMENT_2_GENERIC_CONST(__dothis, __signal, __signal_target) |
|
|
static bool | goFileIO::readImage (const char *filename, goSignal3D< void > *signal, bool linear=false) throw (goFileIOException, goTypeException) |
|
static bool | goFileIO::writeImage (const char *filename, const goSignal3DBase< void > *signal) throw (goFileIOException, goTypeException) |
| Write an image file from a goSignal3DBase<void> object. More...
|
|
bool | goNormalizeSignal (const goSignal3DBase< void > *sig, goSignal3D< void > *targetSig) |
| Normalizes or translates a float or double type signal to the interval [0,1]. More...
|
|
bool | goNormalizeSignal (goSignal3DBase< void > *sig) |
| Normalizes or translates a float or double type signal to the interval [0,1]. More...
|
|
bool | goFindZeroCrossings (const goSignal3DBase< void > *sig, goArray< goPointf > &pointsRet) |
| Find zero crossings in sig and return an array of points. More...
|
|
bool | goConvertSignal (const goSignal3DBase< void > *sig, goSignal3DBase< void > *targetSig) |
| Convert a signal to another signal with a given data type. More...
|
|
bool | goCopySignal (const goSignal3DBase< void > *sig, goSignal3DBase< void > *targetSig) |
| Copies a signal to another signal. More...
|
|
bool | goCopySignalChannel (const goSignal3DBase< void > *sig, goSignal3DBase< void > *targetSig) |
| Copies a channel from a signal to another signal. More...
|
|
template<class T > |
bool | goCopySignalArray (const goSignal3DBase< void > *sig, T *targetArray, int *strides=0) |
| Copies the signal values to the linear array targetArray . More...
|
|
template<class T > |
bool | goCopySignalArray (const T *array, goSignal3DBase< void > *targetSig, int *strides=0) |
| Copies the values in a linear array to a signal. More...
|
|
bool | goFillSignal (goSignal3DBase< void > *sig, goFloat value) |
| Fills a signal with a float value (will be converted). More...
|
|
bool | goRGBAtoScalar (const goSignal3DBase< void > *sig, goSignal3DBase< void > *targetSig) |
| Converts an RGBA 3- or 4-channel signal to a scalar 1-channel signal. More...
|
|
void | goSignalInfoText (const goSignal3DBase< void > &sig, goString &strRet, bool html=false) |
| Get some description (as ASCII text) for a signal. More...
|
|
goDouble | goSignalMean (const goSignal3DBase< void > &sig) |
| Calculate the signal mean. More...
|
|
void | goSignalMeanVariance (const goSignal3DBase< void > &sig, goDouble &mean, goDouble &variance) |
| Calculate mean and variance of a signal. More...
|
|
void | goSignalFlipY (const goSignal3DBase< void > &sig, goSignal3DBase< void > &target) |
| Flip the signal data in Y direction. More...
|
|
bool | goSignalCOM (const goSignal3DBase< void > &sig, goMath::Vectord &comRet) |
| Calculate centre of mass of sig . More...
|
|
bool | goSignalMinMaxCoord (const goSignal3DBase< void > &sig, goDouble thresh, goMath::Vector< goSize_t > &minRet, goMath::Vector< goSize_t > &maxRet) |
| Find min and max coordinates in sig where the value is below thresh . More...
|
|
bool | goSignalMinMaxCoord (const goSignal3DBase< void > &sig, goAutoPtr< goFunctorBase1< bool, goDouble > > f, goMath::Vector< goSize_t > &minRet, goMath::Vector< goSize_t > &maxRet) |
| Generic ROI finding. Find min and max coordinates in sig where f (value ) is true . More...
|
|
bool | goSignalMinMaxCoordHigher (const goSignal3DBase< void > &sig, goDouble thresh, goMath::Vector< goSize_t > &minRet, goMath::Vector< goSize_t > &maxRet) |
| Like goSignalMinMaxCoord(), but finds a light border. More...
|
|
bool | goSignalCrop (goSignal3DBase< void > &sig, goSubSignal3D< void > &target, goDouble thresh) |
| Crop dark or empty borders from sig . More...
|
|
bool | goSignalCrop (goSignal3DBase< void > &sig, goSubSignal3D< void > &target, goAutoPtr< goFunctorBase1< bool, goDouble > > f) |
| Generic image cropping. More...
|
|
bool | goSignalCropHigher (goSignal3DBase< void > &sig, goSubSignal3D< void > &target, goDouble thresh) |
| Like goSignalCrop(), but crops light border. More...
|
|
bool | goSignalMax (const goSignal3DBase< void > &sig1, const goSignal3DBase< void > &sig2, goSignal3DBase< void > &target) |
|
bool | goSignalMin (const goSignal3DBase< void > &sig1, const goSignal3DBase< void > &sig2, goSignal3DBase< void > &target) |
|
const goSize3D & | goSignal::defaultBlockSize3D () |
|
const goSize3D & | goSignal::defaultBlockSize2D () |
|
bool | goSignal::canny (const goSignal3DBase< void > &image, goSignal3DBase< void > &ret, goDouble thresh1, goDouble thresh2) |
| Canny edge detector for 2D images. More...
|
|
bool | goSignal::smooth (goSignal3DBase< void > &sig, goSize_t width=3) |
|
bool | goSignal::convert (const goSignal3DBase< void > &source, goSignal3DBase< void > &target, const int *source_chan, const int *target_chan, int channelCount) |
|
bool | goSignal::RGB2BGRA (goSignal3DBase< void > &source, goSignal3DBase< void > &target) |
|
bool | goSignal::toBGRA (goSignal3DBase< void > &source, goSignal3DBase< void > &target, goFloat alpha=-1.0) |
|
goAutoPtr< goSignal3D< void > > | goSignal::toBGRA (goSignal3DBase< void > &source, goFloat alpha=-1.0) |
|
Introduction
Golib provides a few classes for handling data storage and access of data arranged in an up to 3-dimensional regular grid. Data can be stored in goSignal3D objects and be accessed through the base class goSignal3DBase or through goSubSignal3D, which provides access to rectilinear sub-regions of a goSignal3DBase. All classes are provided as templates and there are instantiations for the most important simple scalar data types, but it is recommended to use the <void> template parameter and use the (newer) generic interface to the data. The special instantiations do work, but will be deprecated some time in the future and new features will be provided for the <void> instantiations. For those, the data type of the stored data is managed by the class itself. This makes the signal classes more flexible to use and takes away the necessity for functions and classes that use the signal classes also to be templates (which can be a pain).
Organisation
goSignal3DBase is the base class for all signal classes. All data is organised as a rectilinear grid of up to 3 dimensions. The memory is allocated following the concept of data locality by allocating the data in blocks the size of which can be adjusted by the user. This allows for speed-up of code which accesses local neighbourhoods of data points by providing block sizes which enable efficient use of cache structures of the used processor architecture (which naturally is machine dependent). Of cource, by choosing the block size accordingly, data can also be organised linearly. A mechanism allowing to provide borders for a signal is also provided, making it easier to use algorithms which rely on certain assumptions on the border, e.g. that a signal is periodic or that the border is constant.
goSignal3D is the class that actually allocates memory and stores data.
goSubSignal3D can be used to get a window or region of interest from another goSignal3DBase.
Usage
General Usage And Iterators
Using the signal classes is quite simple once you get used to the fact the data is not linear in memory in general. In the simplest case, data can be accessed by the goSignal3DBase::getPtr() methods. However, this is quite slow if you want to go through a lot of points and not just, say, 10 out of a 1024^3 cube. If you want to iterate over all data points, you can make use of goSignal3DGenericIterator and goSignal3DGenericConstIterator:
goSignal3D<void> mySignal;
... // fill the signal, load data, whatever.
goSignal3DGenericIterator it(&mySignal);
while(!it.endZ())
{
it.resetY();
while (!it.endY())
{
it.resetX();
while (!it.endX())
{
*(goFloat*)*it = calculate_something();
it.incrementX();
}
it.incrementY();
}
it.incrementZ();
}
The end[X|Y|Z]() methods indicate the end of one of the three dimensions. You can think of the resetX(), resetY(), resetZ() methods as carriage returns for each dimension. The increment methods of course increment the iterator in one dimension. Note that after this loop, you have to resetZ() the iterator in order to be able to use it again in the same manner, since it reached the end of the Z dimension. Also note that if you have multi-channel signals, you must choose the active channel using setChannel() BEFORE initialising (i.e. creating) the iterator.
Multiple Channels
Signals can hold multi-channel data which can be accessed by selecting an active channel with setChannel(). The number of channels can be retrieved with getChannelCount(). Note that the channel data is stored linearly at a point, so by getting the pointer to the 0th channel with the dereference operator of an iterator, you can access the other channels simply by adding the respective value to the pointer. I expect that I will keep this data organisation in the future, so go ahead and use it. But keep in mind that this means using some sort of internal knowledge about the signal storage, which should be avoided in general because of course it is not completely impossible that something is changed about this in the future (however unlikely). However, I think in this case it can mean significant speed-ups.
Reads a PGM (8 bit raw) file into the signal. Signal is newly created.
- Todo:
- Fix readPGM etc. for signal3d
Writes the signal as 8 bit raw PGM file. The signal should contain only values up to 255, since the values are simply casted to goInt8.
◆ GO_SIGNAL3D_EACHELEMENT
#define GO_SIGNAL3D_EACHELEMENT |
( |
|
__dothis, |
|
|
|
__signal, |
|
|
|
__type |
|
) |
| |
Value:{ \
__type *__ptr_z = __signal.getPtr(0, 0, 0); \
__type *__ptr; \
__type *__ptr_y; \
const goPtrdiff_t* __dx = __signal.getXDiff(); \
const goPtrdiff_t* __dy = __signal.getYDiff(); \
const goPtrdiff_t* __dz = __signal.getZDiff(); \
goSize_t __i,__j,__k; \
\
for (__i = 0; __i < __signal.getSizeZ(); __i++) \
{ \
__ptr_y = __ptr_z; \
for (__j = 0; __j < __signal.getSizeY(); __j++) \
{ \
__ptr = __ptr_y; \
for (__k = 0; __k < __signal.getSizeX(); __k++) \
{ \
{ \
__dothis; \
__ptr += __dx[__k]; \
} \
} \
__ptr_y += __dy[__j]; \
} \
__ptr_z += __dz[__i]; \
} \
\
}
Executes __dothis
for each element in the goSignal3D
__signal
of type __type
.
The signal is went through using the pointer differences provided by goSignal3D
.
- Author
- Christian Gosch
◆ GO_SIGNAL3D_EACHELEMENT_2
#define GO_SIGNAL3D_EACHELEMENT_2 |
( |
|
__dothis, |
|
|
|
__signal, |
|
|
|
__signal_target, |
|
|
|
__type, |
|
|
|
__type_target |
|
) |
| |
Does the same as GO_SIGNAL3D_EACHELEMENT
but provides walking through 2 signals of the same size. That can be used to store the results in a second signal.
- Examples
- dwt.cc, and filter3d.cc.
◆ GO_SIGNAL3D_EACHELEMENT_GENERIC
#define GO_SIGNAL3D_EACHELEMENT_GENERIC |
( |
|
__dothis, |
|
|
|
__signal |
|
) |
| |
For generic (void type) signals.
__dothis will be executed for each signal sample. The pointer __ptr is a pointer to the first byte of the current sample. Cast to an appropriate pointer.
- Parameters
-
__dothis | Code to be executed in the inner loop. |
__signal | Signal. |
◆ GO_SIGNAL3D_EACHELEMENT_GENERIC_CONST
#define GO_SIGNAL3D_EACHELEMENT_GENERIC_CONST |
( |
|
__dothis, |
|
|
|
__signal |
|
) |
| |
Value:{ \
const goUInt8 *__ptr_z = (const goUInt8*)__signal.getPtr(0, 0, 0); \
const goUInt8 *__ptr; \
const goUInt8 *__ptr_y; \
const goPtrdiff_t* __dx = __signal.getXDiff(); \
const goPtrdiff_t* __dy = __signal.getYDiff(); \
const goPtrdiff_t* __dz = __signal.getZDiff(); \
goSize_t __i,__j,__k; \
\
for (__i = 0; __i < __signal.getSizeZ(); __i++) \
{ \
__ptr_y = __ptr_z; \
for (__j = 0; __j < __signal.getSizeY(); __j++) \
{ \
__ptr = __ptr_y; \
for (__k = 0; __k < __signal.getSizeX(); __k++) \
{ \
{ \
__dothis; \
__ptr += __dx[__k]; \
} \
} \
__ptr_y += __dy[__j]; \
} \
__ptr_z += __dz[__i]; \
} \
\
}
◆ SIGNAL3D_bilinear
#define SIGNAL3D_bilinear |
( |
|
__A, |
|
|
|
__B, |
|
|
|
__C, |
|
|
|
__D, |
|
|
|
__px, |
|
|
|
__py, |
|
|
|
__target |
|
) |
| |
Value:{ \
goFloat __p1 = __A + ((__B - __A)*__px); \
goFloat __p2 = __C + ((__D - __C)*__px); \
__target = (__p1 + ((__p2 - __p1)*__py)); \
}
◆ godwt_t
Type for transformed data. Using goDouble for this takes double the amount of memory than goFloat. The goDouble Haar transforms are about 18 percent slower than the goFloat operations. There is, however, a loss in precision when using goFloat.
◆ canny()
Canny edge detector for 2D images.
Compute the edge map after Canny. The detector consists of 3 steps: First, a Sobel operator is run on the image to find gradient directions and magnitudes. If the image is a colour image (in RGB(A)), it will be converted to a scalar gray value image first. Second, non-maximum suppression is used to thin out the result of the Sobel operator. Third, a hysteresis thresholding is used to reduce the edge map to prominent edgels. Here, thresh1
is the high threshold, and thresh2
is the low threshold. That means that first, only the responses higher than thresh1
are marked as edgels, and then neighbouring responses higher than thresh2
are added successively.
- Parameters
-
image | Image |
ret | Return value, contains the edge map on successful return. Must be properly sized or must be a goSignal3D<void>. If in the latter case it is not of matching size, it will be resized and the type will be set to GO_UINT8. |
thresh1 | High threshold for hysteresis (default 80.0) |
thresh2 | Low threshold for hysteresis (default 40.0) |
- Returns
- True is successful, false otherwise.
◆ goConvertSignal()
Convert a signal to another signal with a given data type.
The signal sig will be converted if possible to targetSig. The target data type is determined by the data type of targetSig. (set with targetSig->setDataType()). The size of the target signal must be the same as the source signal. The signals should only differ in their data types.
- Parameters
-
sig | Pointer to the signal to convert. |
targetSig | Pointer to the target signal. The size must be the same as sig. |
- Returns
- True if successful, false otherwise.
◆ goCopySignal()
Copies a signal to another signal.
The signals do not have to have the same data type. The size is not checked, but each dimension is only copied until the smallest size is reached. Same holds for channels. All channels are copied until one of the signals runs out of channels.
- Parameters
-
sig | Signal to copy. |
targetSig | Signal to hold the target. |
- Returns
- True if successful, false otherwise.
◆ goCopySignalArray() [1/2]
template<class T >
bool goCopySignalArray |
( |
const goSignal3DBase< void > * |
sig, |
|
|
T * |
targetArray, |
|
|
int * |
strides |
|
) |
| |
Copies the signal values to the linear array targetArray
.
The values will be copied in the order X, then Y, then Z.
- Parameters
-
sig | Signal to copy. |
targetArray | Linear target array. |
strides | For each dimension, the stride to take in array , in number of elements. May be null, in that case array is assumed to simply linear. |
- Returns
- True if successful, false otherwise.
◆ goCopySignalArray() [2/2]
template<class T >
bool goCopySignalArray |
( |
const T * |
array, |
|
|
goSignal3DBase< void > * |
targetSig, |
|
|
int * |
strides |
|
) |
| |
Copies the values in a linear array to a signal.
The size of targetSig
must be pre-set and it must be allocated ( e.g. with make()
).
- Parameters
-
array | Array containing values. |
targetSig | Target signal. |
strides | For each dimension, the stride to take in array , in number of elements. May be null, in that case array is assumed to simply linear. |
- Returns
- True if successful, false otherwise.
◆ goCopySignalChannel()
Copies a channel from a signal to another signal.
The signals do not have to have the same data type. The size is not checked, but each dimension is only copied until the smallest size is reached. The currently active channel from sig is copied to the currently active channel of targetSig.
- Parameters
-
sig | Signal to copy. |
targetSig | Signal to hold the target. |
- Returns
- True if successful, false otherwise.
- Examples
- videocapture/videocapture.cpp.
◆ goFillSignal()
Fills a signal with a float value (will be converted).
- Parameters
-
sig | Signal to fill. |
value | Float value. This value will be converted to an appropriate data type for the signal. |
- Returns
- True if successful, false otherwise.
◆ goFindZeroCrossings()
Find zero crossings in sig
and return an array of points.
On returning true, pointsRet
will contain the point coordinates of zero crossings on the grid lines of sig
.
- Parameters
-
sig | Signal to search in. |
pointsRet | Points array (return value). |
- Returns
- True if successful, false otherwise.
◆ goNormalizeSignal() [1/2]
Normalizes or translates a float or double type signal to the interval [0,1].
If the signal values are out of the interval [0,1], the signal is normalized to it. If (maxValue - minValue) <= 1.0, the signal values are just translated into [0,1]. This function works only on the currently selected channel.
- Parameters
-
sig | Signal to be normalized. |
targetSig | Target containing the normalized signal after the call. Note that targetSig is reallocated during the call. |
- Returns
- True if successful, false otherwise (e.g. if the signal is not float or double).
◆ goNormalizeSignal() [2/2]
Normalizes or translates a float or double type signal to the interval [0,1].
- Note
- This does only work on the currently active channel.
If the signal values are out of the interval [0,1], the signal is normalized to it. If (maxValue - minValue) <= 1.0, the signal values are just translated into [0,1].
- Parameters
-
sig | Signal to be normalized. |
- Returns
- True if successful, false otherwise (e.g. if the signal is not float or double).
◆ goRGBAtoScalar()
Converts an RGBA 3- or 4-channel signal to a scalar 1-channel signal.
The source signal must have 3 or 4 channels that are interpreted as RGB(A). The alpha channel is currently not taken into account. The conversion is to luminance after ITU CCR 601:
Y = 0.299 * R + 0.587 * G + 0.114 * B
- Note
- The target signal used to be normalised for GO_FLOAT and GO_DOUBLE types. This is no longer the case.
- Parameters
-
sig | Source signal, must be of type GO_UINT8 and have >= 3 channels. |
targetSig | Target signal. Data type must be set and the size must be the same as that of the source signal. |
- Returns
- True if successful, false otherwise.
◆ goSignalCOM()
Calculate centre of mass of sig
.
- Parameters
-
sig | Data. |
comRet | On returning true, contains the centre of mass. |
- Returns
- True if successful, false otherwise.
◆ goSignalCrop() [1/2]
Generic image cropping.
Given a function f
, works like the other goSignalCrop() function but the border is sought using f
. Instead of testing for value
>= thresh
, f
(value
) == true
is tested.
- Parameters
-
sig | Signal to crop. |
target | On success, is a sub signal of sig . |
f | Functor taking a goDouble and returning a bool . |
- Returns
- True if success, false otherwise.
◆ goSignalCrop() [2/2]
Crop dark or empty borders from sig
.
Uses goSignalMinMaxCoord() to find a region which contains all values >= thresh
.
- Parameters
-
sig | Signal to crop. |
target | On success, is a subsignal of sig representing the region of interest. |
thresh | Threshold. |
- Returns
- True if successful, false otherwise.
◆ goSignalCropHigher()
Like goSignalCrop(), but crops light border.
Crops the borders where value >= thresh.
- Parameters
-
sig | Signal to crop. |
target | On success, is a sub signal to sig (the cropped region). |
thresh | Threshold. |
- Returns
- True if successful, false otherwise.
◆ goSignalFlipY()
Flip the signal data in Y direction.
This does a deep copy. The actual flip() method for goSignal3DBase is defunct, so this was written as a hack to be able to flip images conveniently. It is, however, slow due to the copy procedure.
- Parameters
-
sig | Original signal. |
target | Target, contains the flipped sig after return. target must be the same size as sig , or nothing will be copied (check log file). |
◆ goSignalInfoText()
Get some description (as ASCII text) for a signal.
- Parameters
-
sig | Signal to get the description for. |
strRet | String to hold the description. |
html | If true, the text will be HTML formatted, if false, the text will be plain ASCII. |
◆ goSignalMean()
Calculate the signal mean.
- Parameters
-
sig | Signal to calculate the mean of. |
- Returns
- Mean value as goDouble. For multichannel signals, just do setChannel() and then goSignalMean() for each channel.
◆ goSignalMeanVariance()
void goSignalMeanVariance |
( |
const goSignal3DBase< void > & |
sig, |
|
|
goDouble & |
mean, |
|
|
goDouble & |
variance |
|
) |
| |
Calculate mean and variance of a signal.
- Parameters
-
sig | Signal. |
mean | After returning, holds the mean value as double. |
variance | After returning, holds the variance as double. |
◆ goSignalMinMaxCoord() [1/2]
Generic ROI finding. Find min and max coordinates in sig
where f
(value
) is true
.
Given a function f
, works like the other goSignalCrop() function but the border is sought using f
. Instead of testing for value
>= thresh
, f
(value
) == true
is tested.
- See also
- goSignalMinMaxCoord()
- Parameters
-
sig | Signal. |
f | Pointer to a functor returning bool, taking one goDouble as argument. |
minRet | On success, contains the minimum coordinates of the rectangular region of interest with values for which f() is true. |
maxRet | On success, contains the maximum coordinates of the rectangular region of interest with values for which f() is true. |
- Returns
- True if success, false otherwise.
◆ goSignalMinMaxCoord() [2/2]
Find min and max coordinates in sig
where the value is below thresh
.
This gets e.g. used in goSignalCrop(). It finds the rectangular region of interest which contains all values larger than thresh
. Good for example to crop dark borders from images or simply "empty space".
- Parameters
-
sig | Signal. |
thresh | Threshold. |
minRet | On success, contains the minimum coordinates of the rectangular region of interest with values larger than thresh . |
maxRet | On success, contains the maximum coordinates of the rectangular region of interest with values larger than thresh . |
- Returns
- True if successful, false otherwise.
◆ goSignalMinMaxCoordHigher()
Like goSignalMinMaxCoord(), but finds a light border.
Finds the borders when they have values higher than thresh
.
- See also
- goSignalMinMaxCoord()
- Parameters
-
sig | Signal. |
thresh | Threshold. |
minRet | On success, contains the min. coordinates of the region of interest without the light border. |
maxRet | On success, contains the max. coordinates of the region of interest without the light border. |
- Returns
- True if successful, false otherwise.
◆ writeImage()
Write an image file from a goSignal3DBase<void> object.
This function needs goLib to be compiled with support for the libIL image library. The supported image types depend on the types supported by libIL. At the time of this being written, those were
- .bmp
- .dds
- .jpg
- .pcx
- .png
- .pnm
- .raw
- .sgi
- .tga
- .tif
- .pal
Note that these differ from the types supported for reading. The image type is selected by the filename's suffix.
- Parameters
-
- Note
- This method only works when libGo was compiled with libIL support (http://openil.sourceforge.net). If not, it always returns false.
-
This does not yet work for multichannel data.
- Todo:
- This works only for float signals. Add other types. Add multichannel.
- Returns
- True if successful, false otherwise.
- Examples
- videocapture/videocapture.cpp.