annotate inst/colorgradient.m @ 886:a0c42a32c6c4

Move conversion between each image type to imcast. * im2double.m, im2int16.m, im2single.m, im2uint16.m, im2uint8.m: move code into imcast. Fix several small bugs mainly dealing with indexed and logical images, small precision for Matlab compatibility, and increased performance. Expanded documentation. Added new tests. * imcast.m: implement the conversion between each image type instead of being a wrapper around functions for each conversion. This reduces code duplication, and places all very similar (but not equal) code together so that a bug fix in one can be easily notices that requires application in others. Expand documetation. Add more tests. * private/imconversion.m, private/im2float.m: remove no longer necessary function since this has all been moved to imcast. * COPYING: remove license for private/im2float.m and private/imconversion.m. * NEWS: make note of bug fixes for this functions.
author Carnë Draug <carandraug@octave.org>
date Mon, 24 Mar 2014 22:00:05 +0000
parents 1d04ebf01532
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
560
1d04ebf01532 image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
carandraug
parents: 220
diff changeset
1 ## Author: Paul Kienzle <pkienzle@users.sf.net>
1d04ebf01532 image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
carandraug
parents: 220
diff changeset
2 ## This program is granted to the public domain.
1d04ebf01532 image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
carandraug
parents: 220
diff changeset
3
220
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
4 ## -*- texinfo -*-
560
1d04ebf01532 image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
carandraug
parents: 220
diff changeset
5 ## @deftypefn {Function File} {@var{M} =} colorgradient (@var{C}, @var{w}, @var{n})
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
6 ## Define a colour map which smoothly traverses the given colors.
220
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
7 ## @var{C} contains the colours, one row per r,g,b value.
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
8 ## @var{w}(i) is the relative length of the transition from colour i to colour i+1
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
9 ## in the entire gradient. The default is ones(rows(C)-1,1).
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
10 ## n is the length of the colour map. The default is rows(colormap).
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
11 ##
220
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
12 ## E.g.,
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
13 ## @example
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
14 ## colorgradient([0,0,1; 1,1,0; 1,0,0]) # blue -> yellow -> red
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
15 ## x = linspace(0,1,200);
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
16 ## imagesc(x(:,ones(30,1)))';
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
17 ## @end example
df13bd973471 Documentation is now in Texinfo (looks better on the website)
hauberg
parents: 186
diff changeset
18 ## @end deftypefn
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
19
560
1d04ebf01532 image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
carandraug
parents: 220
diff changeset
20 function ret = colorgradient (C, w, n)
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
21 if nargin < 1 || nargin > 3
560
1d04ebf01532 image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
carandraug
parents: 220
diff changeset
22 print_usage;
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
23 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
24
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
25 if nargin == 1
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
26 n = rows(colormap);
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
27 w = ones(length(C)-1,1);
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
28 elseif nargin == 2
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
29 if (length(w) == 1)
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
30 n = w;
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
31 w = ones(rows(C)-1,1);
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
32 else
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
33 n = rows(colormap);
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
34 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
35 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
36
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
37 if (length(w)+1 != rows(C))
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
38 error("must have one weight for each color interval");
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
39 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
40
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
41 w = 1+round((n-1)*cumsum([0;w(:)])/sum(w));
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
42 map = zeros(n,3);
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
43 for i=1:length(w)-1
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
44 if (w(i) != w(i+1))
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
45 map(w(i):w(i+1),1) = linspace(C(i,1),C(i+1,1),w(i+1)-w(i)+1)';
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
46 map(w(i):w(i+1),2) = linspace(C(i,2),C(i+1,2),w(i+1)-w(i)+1)';
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
47 map(w(i):w(i+1),3) = linspace(C(i,3),C(i+1,3),w(i+1)-w(i)+1)';
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
48 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
49 endfor
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
50
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
51 if nargout == 0
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
52 colormap(map);
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
53 else
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
54 ret = map;
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
55 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
56 endfunction