]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/roicolor.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / roicolor.m
1 ## Copyright (C) 2004 Josep Mones i Teixidor
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{BW} = } roicolor (@var{A},@var{low},@var{high})
18 ## @deftypefnx {Function File} {@var{BW} = } roicolor (@var{A},@var{v})
19 ## Select a Region Of Interest of an image based on color.
20 ##
21 ## BW = roicolor(A,low,high) selects a region of interest (ROI) of an
22 ## image @var{A} returning a black and white image in a logical array (1 for
23 ## pixels inside ROI and 0 outside ROI), which is formed by all pixels
24 ## whose values lie within the colormap range specified by [@var{low}
25 ## @var{high}].
26 ##
27 ## BW = roicolor(A,v) selects a region of interest (ROI) formed by all
28 ## pixels that match values in @var{v}.
29 ## @end deftypefn
30
31 ## Author:  Josep Mones i Teixidor <jmones@puntbarra.com>
32
33 function BW = roicolor(A, p1, p2)
34   if (nargin < 2 || nargin > 3)
35     usage("BW = roicolor(A, low, high), BW = roicolor(A, v)");
36   endif
37
38   if (nargin == 2)
39     if (!isvector(p1))
40       error("BW = roicolor(A, v): v should be a vector.");
41     endif
42     BW=logical(zeros(size(A)));
43     for c=p1
44       BW|=(A==c);
45     endfor
46   elseif (nargin==3)
47     if (!isscalar(p1) || !isscalar(p2))
48       error("BW = roicolor(A, low, high): low and high must be scalars.");
49     endif
50     BW=logical((A>=p1)&(A<=p2));
51   endif
52 endfunction
53
54 %!demo
55 %! roicolor([1:10],2,4);
56 %! % Returns '1' where input values are between 2 and 4 (both included).
57
58 %!assert(roicolor([1:10],2,4),logical([0,1,1,1,zeros(1,6)]));
59 %!assert(roicolor([1,2;3,4],3,3),logical([0,0;1,0]));
60 %!assert(roicolor([1,2;3,4],[1,4]),logical([1,0;0,1]));
61
62 %
63 % $Log$
64 % Revision 1.2  2007/03/23 16:14:37  adb014
65 % Update the FSF address
66 %
67 % Revision 1.1  2006/08/20 12:59:35  hauberg
68 % Changed the structure to match the package system
69 %
70 % Revision 1.3  2004/09/15 17:54:59  pkienzle
71 % test that data type matches during assert
72 %
73 % Revision 1.2  2004/08/11 15:04:59  pkienzle
74 % Convert dos line endings to unix line endings
75 %
76 % Revision 1.1  2004/08/08 21:02:44  jmones
77 % Add roicolor function (selects ROI based on color)
78 %
79 %