The contrast function

David Bateman David.Bateman at motorola.com
Tue Mar 25 10:01:48 CDT 2008


The contrast function should be easy to implement.. It just comes down
to normalizing the data to the number of elements in the colormap and
counting the number of elements in the data between each integer value..
I've implemented a function that basically does this, this being

function map = contrast (x, n)
  if (nargin == 1)
    n = rows (colormap);
  elseif (nargin == 2)
    if (! isscalar (n))
      error ("contrast: n must be a scalar");
    endif
  else
    print_usage ();
  endif

  x = x (:);
  minx = min (x);
  map = find (diff (sort ([round(n * ((x - minx) ./ (max(x) - minx)));
[0:n]']))) - [1:n]';
  minm = min (map);
  map = (map - minm) ./ (max (map) - minm);
  map = [map , map, map];
endfunction

though I see a difference with the matlab behavior for the same
function.. It appears that matlab doesn't define the first term of the
colormap as [0,0,0] and so the maximum contrast can't be achieved as
pure black is excluded from the colormap. This can be seen with

imagesc(reshape(1:100,10,10))
map = contrast (1:100,10)
colormap(map)

It seems to me better to use both [0,0,0] and [1,1,1] as the limits of
the colormap for contrast. Does it make sense to have this inconsistency
with matlab? If so I'll propose a patch to add contrast based on the above

D.

-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



More information about the Octave-maintainers mailing list