-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all,
There seem to be several bugs in the histogram equalisation code at
histeq.m:
- - The second parameter should be used to specify the number of buckets
in the histogram, but it is not passed to the function that calculates
the histogram.
- - The imhist() function scales the image to [0...1] before calculating
the histogram, but histeq() treats the image as if it was unscaled.
Therefore the function only works correctly if the image contains at
least one black and one white pixel, respectively.
- - The output of the function is of type double, but containing values
between 0 and 255. Octave uses either images of type double with
values in [0...1] or uint8 with values in [0...255]. The input of the
function has to be a double image.
The attached patch adresses the issues:
- - The number of buckets is used consistently.
- - The image is scaled before processing.
- - The return type is of type double [0...1] (does this cause backward
compatibility issues?)
- - Assumptions on input and return type have been documented
The results are still not very nice, mostly due to roundoff errors in
imhist, but already very usable:
octave> g = im2double(uint8([0 1 2 3 255]));
octave> histeq(g)
ans =
~ 0.80000 0.80000 0.80000 0.80000 1.00000
Low precision with 64 buckets (default)
octave> histeq(g, 256)
ans =
~ 0.20000 0.40000 0.60000 0.80000 1.00000
compared to the previous version:
octave> g = im2double(uint8([0 1 2 3 255]));
octave> histeq(g)
ans =
~ 13 13 13 26 52
octave> histeq(g, 256)
ans =
~ 52 52 52 103 205
Hope this helps. Feedback is very much welcome since this is my first
contribution ever to an open source project (after having used GNU/Linux
for 6 years... shame on me...)
Greetings,
Jonas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHr+6I68Rj+pj1GF0RAvVCAJ0Y1YIu9+qZV4BEPOVgBTiyO1LuQgCeJfBx
SMZi5hz53Z8pU5nn2tnoWcQ=
=wiF1
-----END PGP SIGNATURE-----
--- histeq_svn.m 2008-02-11 12:37:45.000000000 +0800
+++ histeq.m 2008-02-11 12:53:45.000000000 +0800
@@ -14,14 +14,20 @@
## along with this program; If not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
-## @deftypefn {Function File} @var{J}= histeq (@var{I}, @var{n})
+## @deftypefn {Function File} @var{J} = histeq (@var{I}, @var{n})
## Histogram equalization of a gray-scale image. The histogram contains
## @var{n} bins, which defaults to 64.
+##
+## @var{I}: Image in double format, with values from 0.0 to 1.0
+##
+## @var{J}: Returned image, in double format as well
## @seealso{imhist}
## @end deftypefn
## Author: Kai Habel <[EMAIL PROTECTED]>
## Date: 08. August 2000
+## Modified-by: Jonas Wagner <[EMAIL PROTECTED]>
+## Date: 11. February 2008
function J = histeq (I, n)
if (nargin == 0)
@@ -30,10 +36,12 @@
n = 64;
endif
- [r,c] = size (I);
- [X,map] = gray2ind(I);
- [nn,xx] = imhist(I);
- Icdf = ceil (n * cumsum (1/prod(size(I)) * nn));
+ [r,c] = size(I);
+ I = mat2gray(I);
+ [X,map] = gray2ind(I, n);
+ [nn,xx] = imhist(I, n);
+ Icdf = 1 / prod(size(I)) * cumsum(nn);
J = reshape(Icdf(X),r,c);
- plot(Icdf,'b;;');
+
+ plot(Icdf,'b;Image Cumulative Density Function;');
endfunction
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev