Code: Difference between revisions

From Octave
Jump to navigation Jump to search
(+ Fixed point toolbox)
Line 85: Line 85:
*What does dicominfo do when a tag is not in its dictionary: skip it or give error? I was wondering about turning the tag into a variable name, something like Tag_3243_0010. (Matlab 6.5 (2002): Private__3243_0010)
*What does dicominfo do when a tag is not in its dictionary: skip it or give error? I was wondering about turning the tag into a variable name, something like Tag_3243_0010. (Matlab 6.5 (2002): Private__3243_0010)
*dicominfo: Items in sequences are not necessarily the same, so cannot be stored in arrays of structs. (Matlab 6.5 (2002): makes nested structs like dcm.RTDoseROISequence?.Item_1.DoseUnits?)
*dicominfo: Items in sequences are not necessarily the same, so cannot be stored in arrays of structs. (Matlab 6.5 (2002): makes nested structs like dcm.RTDoseROISequence?.Item_1.DoseUnits?)
== Fixed point toolbox ==
(initial announcement can be found [http://www.octave.org/octave-lists/archive/help-octave.2004/msg01274.html here], with the corresponding thread)
When implementing algorithms in hardware, it is common to reduce the accuracy of the representation of numbers to a smaller number of bits. This allows much lower complexity in the hardware, at the cost of accuracy and potential overflow problems. Such representations are known as fixed point.
OctaveForge now contains [http://octave.sourceforge.net/Fixedpoint/index.html a toolbox] to perform such fixed point calculations. This toolbox supplies a fixed point type that allows Octave to model the effects of such a reduction in accuracy of the representation of numbers. The major advantage of this toolbox is that with correctly written Octave scripts, the same code can be used to test both fixed and floating point representations of numbers.
What it does is create several new user types for fixed point scalar, complex scalars, matrices and complex matrices, and the corresponding operators on these types. As this code was first written against 2.1.50 there is no capabilities at this time for NDArray operations with this code, however I'm not sure this is a problem.
A typical use of the toolbox might be something like
n = 2;
a = rand (n, n);
b = rand (n, n);
## Create fixed-point version with 1 bit before decimal and 5 after.
af = fixed (1, 5, a);
bf = fixed (1, 5, b);
c = myfunc (a, b);
cf = myfunc (af, bf);
function y = myfunc (a, b)
    y = a * b;
endfunction
where as you can see the underlying function myfunc is unchanged, while it is called with either floating or fixed point types. The case above is for fixed-point values with 1-bit before the decimal point and 5 after, and for me gave a result of
octave:8> c
c =
  0.98105  0.94436
  0.82622  0.30831
octave:9> cf
cf =
  0.93750  0.90625
  0.78125  0.25000
which clearly shows the loss of precision of a fixed-point algorithm with only 6-bits of precision in a matrix multiply. One gotcha in this toolbox is the use of the concatenation operator "[ ]" which will implicitly reconvert fixed-point values back to floating-point, with Octave 2.1.57 or earlier. This is due to an internal limitation of octave that was removed in Octave 2.1.58. So for the best experience it is suggested you use this toolbox with octave 2.1.58 or later.
This package is only available with recent versions of OctaveForge (20040707 or later). With the package installed online help is available with the command
octave:1> fixedpoint info
As this package is relatively new, all feedback on its use would be most welcome.
Matlab also recently introduced a [http://www.mathworks.com/products/fixed Fixed Point Toolbox]. The Octave toolbox has been written independently of the Matlab toolbox and doesn't follow the same syntax. This might change in the future, if the author (DavidBateman) can be bothered to put the effort into making the required changes. Mathworks [http://www.mathworks.com/access/helpdesk/help/pdf_doc/fixedpoint/FPTUG.pdf documentation] for their fixed point toolbox also includes a generic discussion of fixed point numbers that might be a useful addition to the documentation supplied with Octave itself. Another short introduction to fixed point arithmetics is [http://home.earthlink.net/~yatescr/fp.pdf this].

Revision as of 01:52, 27 November 2011

Chaos and fractal contributions and toolboxes

Ecnometrics

Communications Toolbox

OctaveForge now contains a fairly complete implementation of a Matlab R13 compatible communications toolbox http://octave.sourceforge.net/communications/index.html. This includes

  • Random signal creation/analysis
  • Source coding (Quantization, Compand)
  • Block coding (BCH, Reed-Solomon)
  • Modulations (QASK, PSK, etc)
  • Galois fields of even order [i.e. GF(2^m) ]

With a recent version of the OctaveForge installed (version 20030602 or later), online help is available with the command

octave:1> comms info

There are still functions missing or with limitations, and the documentation is not complete. You are therefore welcome to send patches.

Various Communications-Related Octave Code

Digital communications in medicine (DICOM)

At an early development stage. octave-forge svn

  • Maintainer: Andy Buckle [1]
  • Currently worked on by: Kris Thielemans

Supporting library

GCDM. I think the libraries must be built. Getting source with subversion.

svn co https://gdcm.svn.sourceforge.net/svnroot/gdcm/branches/gdcm-2-0

cmake and g++ are required. create a gdcmbin directory parallel to the gdcm-2-0 directory. Change to gdcmbin and then run cmake (Linux/cygwin).

> mkdir gdcmbin
> ls
gdcmbin gdcm-2-0
> cd gdcmbin
> cmake -DGDCM_BUILD_SHARED_LIBS=ON ../gdcm-2-0/

This creates a Makefile in your gdcmbin directory. You can easily edit cmake options with "make edit_cache", for example to build applications like gdcmdump. "make help" is also very useful.

make install

On my system, I also had to add this to my ~/.bashrc.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

Mingw32 is similar. Get openSSL: Win32 Openssl v1.0.0a Light

cmake -G "MinGW Makefile" -DGDCM_BUILD_SHARED_LIBS=ON ..\gdcm-2-0
mingw32-make all

Features

All of these still need work, but they exist, and are usable to some extent.

  • dicomdict (load different dict - file follows same format as Matlab's)
  • dicominfo (load metadata into octave struct. nasty bug in SQ loading)
  • dicomlookup (keyword <-> tag)
  • dicomread (load pixel data, 2D or 3D int types. Does not yield colormaps, yet.)
  • dicomwrite (only does some 2D int types, ATM. No metadata control, yet)

Todo

  • dicomanon
  • dicomuid

Questions

I don't have a Matlab license available. I would like to make this package compatible with the dicom functions in Matlab's image processing toolbox, as far as possible.

  • Octave (and Matlab) stores images (y,x) and DICOM is intrinsically (x,y). Does Matlab transpose images when it loads them?
    • matlab reads the data from the dicom file as if it's a raw block of numbers (and then converts if necessary). Therefore, current Octave/dicom behaviour is compatible with matlab.
  • I would like people to try m-files that worked with Matlab to let me know of problems.
  • (not necessarily) Matlab related: I need examples of odd DICOM files. I have plenty with complex metadata, but I need some with unusual images.
    • More than one sample per pixel
    • Colour
    • Float types
  • DA (date) VR: does Matlab turn them into a string?
  • if the user supplies metadata (eg HighBit?, BitsStored?) that describe the type of the pixels and this is not in agreement with the type of the image matrix supplied, does Matlab
    • silently convert the image pixel type to match the metadata?
    • silently convert the metadata to match the pixel type?
    • error and do nothing?
  • What does dicominfo do when a tag is not in its dictionary: skip it or give error? I was wondering about turning the tag into a variable name, something like Tag_3243_0010. (Matlab 6.5 (2002): Private__3243_0010)
  • dicominfo: Items in sequences are not necessarily the same, so cannot be stored in arrays of structs. (Matlab 6.5 (2002): makes nested structs like dcm.RTDoseROISequence?.Item_1.DoseUnits?)

Fixed point toolbox

(initial announcement can be found here, with the corresponding thread)

When implementing algorithms in hardware, it is common to reduce the accuracy of the representation of numbers to a smaller number of bits. This allows much lower complexity in the hardware, at the cost of accuracy and potential overflow problems. Such representations are known as fixed point.

OctaveForge now contains a toolbox to perform such fixed point calculations. This toolbox supplies a fixed point type that allows Octave to model the effects of such a reduction in accuracy of the representation of numbers. The major advantage of this toolbox is that with correctly written Octave scripts, the same code can be used to test both fixed and floating point representations of numbers.

What it does is create several new user types for fixed point scalar, complex scalars, matrices and complex matrices, and the corresponding operators on these types. As this code was first written against 2.1.50 there is no capabilities at this time for NDArray operations with this code, however I'm not sure this is a problem.

A typical use of the toolbox might be something like

n = 2;
a = rand (n, n);
b = rand (n, n);

## Create fixed-point version with 1 bit before decimal and 5 after.
af = fixed (1, 5, a);
bf = fixed (1, 5, b);

c = myfunc (a, b);
cf = myfunc (af, bf);

function y = myfunc (a, b)
    y = a * b;
endfunction

where as you can see the underlying function myfunc is unchanged, while it is called with either floating or fixed point types. The case above is for fixed-point values with 1-bit before the decimal point and 5 after, and for me gave a result of

octave:8> c
c =

  0.98105  0.94436
  0.82622  0.30831

octave:9> cf
cf =

  0.93750  0.90625
  0.78125  0.25000

which clearly shows the loss of precision of a fixed-point algorithm with only 6-bits of precision in a matrix multiply. One gotcha in this toolbox is the use of the concatenation operator "[ ]" which will implicitly reconvert fixed-point values back to floating-point, with Octave 2.1.57 or earlier. This is due to an internal limitation of octave that was removed in Octave 2.1.58. So for the best experience it is suggested you use this toolbox with octave 2.1.58 or later.

This package is only available with recent versions of OctaveForge (20040707 or later). With the package installed online help is available with the command

octave:1> fixedpoint info

As this package is relatively new, all feedback on its use would be most welcome.

Matlab also recently introduced a Fixed Point Toolbox. The Octave toolbox has been written independently of the Matlab toolbox and doesn't follow the same syntax. This might change in the future, if the author (DavidBateman) can be bothered to put the effort into making the required changes. Mathworks documentation for their fixed point toolbox also includes a generic discussion of fixed point numbers that might be a useful addition to the documentation supplied with Octave itself. Another short introduction to fixed point arithmetics is this.