[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
The contrast function
From: |
John W. Eaton |
Subject: |
The contrast function |
Date: |
Tue, 25 Mar 2008 11:29:26 -0400 |
On 25-Mar-2008, David Bateman wrote:
| 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
It does seem like a bug that 1 is always included but you can only
approach 0 as N -> Inf (if I understand correctly). Unless there is
some good reason for doing that, I'd say go with what you have.
jwe