Mercurial > hg > octave-image
annotate inst/roicolor.m @ 892:a2140b980079
iptcheckconn: implement in C++ as static method for connectivity.
* iptcheckconn.m: file removed; help text and tests reused for C++.
* conndef.cc: implement two new connectivity::validate() methods and
the iptcheckconn function for Octave as caller to those methods.
* conndef.h: define the connectivity::validate() static methods.
* COPYING
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Wed, 01 Oct 2014 20:22:37 +0100 |
parents | 1d04ebf01532 |
children |
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:
274
diff
changeset
|
1 ## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> |
186 | 2 ## |
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:
274
diff
changeset
|
3 ## This program is free software; you can redistribute it and/or modify it under |
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:
274
diff
changeset
|
4 ## the terms of the GNU General Public License as published by the Free Software |
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:
274
diff
changeset
|
5 ## Foundation; either version 3 of the License, or (at your option) any later |
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:
274
diff
changeset
|
6 ## version. |
186 | 7 ## |
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:
274
diff
changeset
|
8 ## This program is distributed in the hope that it will be useful, but WITHOUT |
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:
274
diff
changeset
|
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
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:
274
diff
changeset
|
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
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:
274
diff
changeset
|
11 ## details. |
186 | 12 ## |
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:
274
diff
changeset
|
13 ## You should have received a copy of the GNU General Public License along with |
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:
274
diff
changeset
|
14 ## this program; if not, see <http://www.gnu.org/licenses/>. |
186 | 15 |
16 ## -*- 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:
274
diff
changeset
|
17 ## @deftypefn {Function File} {@var{BW} =} roicolor (@var{A}, @var{low}, @var{high}) |
186 | 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 | |
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:
274
diff
changeset
|
31 function BW = roicolor (A, p1, p2) |
186 | 32 if (nargin < 2 || 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:
274
diff
changeset
|
33 print_usage; |
186 | 34 endif |
35 | |
36 if (nargin == 2) | |
37 if (!isvector(p1)) | |
38 error("BW = roicolor(A, v): v should be a vector."); | |
39 endif | |
40 BW=logical(zeros(size(A))); | |
41 for c=p1 | |
42 BW|=(A==c); | |
43 endfor | |
44 elseif (nargin==3) | |
45 if (!isscalar(p1) || !isscalar(p2)) | |
46 error("BW = roicolor(A, low, high): low and high must be scalars."); | |
47 endif | |
48 BW=logical((A>=p1)&(A<=p2)); | |
49 endif | |
50 endfunction | |
51 | |
52 %!demo | |
53 %! roicolor([1:10],2,4); | |
54 %! % Returns '1' where input values are between 2 and 4 (both included). | |
55 | |
56 %!assert(roicolor([1:10],2,4),logical([0,1,1,1,zeros(1,6)])); | |
57 %!assert(roicolor([1,2;3,4],3,3),logical([0,0;1,0])); | |
58 %!assert(roicolor([1,2;3,4],[1,4]),logical([1,0;0,1])); |