Mercurial > hg > octave-shane
changeset 3904:6b00ac653c0f
[project @ 2002-04-24 04:56:10 by jwe]
author | jwe |
---|---|
date | Wed, 24 Apr 2002 04:56:11 +0000 |
parents | 1dbe160ea0d1 |
children | 0ca61efc1eaa |
files | liboctave/Array2-idx.h liboctave/ChangeLog scripts/ChangeLog scripts/image/rgb2hsv.m |
diffstat | 4 files changed, 40 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array2-idx.h +++ b/liboctave/Array2-idx.h @@ -160,32 +160,10 @@ if (idx_i && idx_j) { - if (idx_i.orig_empty () || idx_j.orig_empty ()) + if (idx_i.orig_empty () || idx_j.orig_empty () || n == 0 || m == 0) { retval.resize (n, m); } - else if (n == 0) - { - if (m == 0) - retval.resize (0, 0); - else if (idx_j.is_colon_equiv (nc, 1)) - retval.resize (0, nc); - else if (idx_i.is_colon_equiv (nr, 1)) - retval.resize (0, m); - else - (*current_liboctave_error_handler) ("invalid row index = 0"); - } - else if (m == 0) - { - if (n == 0) - retval.resize (0, 0); - else if (idx_i.is_colon_equiv (nr, 1)) - retval.resize (nr, 0); - else if (idx_j.is_colon_equiv (nc, 1)) - retval.resize (n, 0); - else - (*current_liboctave_error_handler) ("invalid column index = 0"); - } else if (idx_i.is_colon_equiv (nr) && idx_j.is_colon_equiv (nc)) { retval = *this;
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2002-04-23 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Array2-idx.h (Array2<T>::index (idx_vector&, idx_vector&) const): + Simplify indexing when one or both of the indices are empty. + 2002-04-11 John W. Eaton <jwe@bevo.che.wisc.edu> * DASSL.h (DASSL_options::init): Set absolute tolerance to eps ^ 2.
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2002-04-23 Paul Kienzle <pkienzle@users.sf.net> + + * image/rgb2hsv.m: Faster, more accurate, remove the + divide by zero warning. + 2002-04-09 Paul Kienzle <pkienzle@users.sf.net> * strings/deblank.m: Trim \0 as well as blank.
--- a/scripts/image/rgb2hsv.m +++ b/scripts/image/rgb2hsv.m @@ -43,48 +43,40 @@ error ("rgb2hsv: argument must be a matrix of size n x 3"); endif - # get saturation and value - v = max (rgb'); - s = (v' > 0) .* (1 .- min (rgb') ./ v)'; - - # if v==0 set s to 0 too - s(isnan (s)) = 0; + ## get the max and min + s = min (rgb')'; + v = max (rgb')'; - # subtract minimum and divide trough maximum - # to get the bright and saturated colors - sc = (rgb - kron ([1, 1, 1], min (rgb')')); - sv = sc ./ kron([1, 1, 1], max (sc')'); - - # if r=g=b (gray value) set hue to 0 - sv(isnan (sv)) = 0; - - # hue=f(color) must be splitted into 6 parts - # 2 for each color + ## set hue to zero for undefined values (gray has no hue) + h = zeros (size (v)); + notgray = (s != v); + + ## blue hue + idx = (v == rgb(:,3) & notgray); + if (any (idx)) + h(idx) = 2/3 + 1/6 * (rgb(idx,1) - rgb(idx,2)) ./ (v(idx) - s(idx)); + endif - # h1(green) - tmp = (sv(:, 1) == 1 & sv(:,3) == 0) .* (1/6 * sv(:,2) + eps); - # avoid problems with h2(red) since hue(0)==hue(1) - h = (tmp < 1/6) .* tmp; - # h2(green) - h = h + ((h == 0) & sv(:,1) == 0 & sv(:,3) == 1) \ - .* (-1/6 * sv(:,2) + 2/3 + eps); - - # h1(red) - h = h + ((h == 0) & sv(:,2) == 1 & sv(:,3) == 0) \ - .* (-1/6 * sv(:,1) + 1/3 + eps); + ## green hue + idx = (v == rgb(:,2) & notgray); + if (any (idx)) + h(idx) = 1/3 + 1/6 * (rgb(idx,3) - rgb(idx,1)) ./ (v(idx) - s(idx)); + endif - # h2(red) - h = h + ((h == 0) & sv(:,2) == 0 & sv(:,3) == 1) \ - .* (1/6 * sv(:,1) + 2/3 + eps); + ## red hue + idx = (v == rgb(:,1) & notgray); + if (any (idx)) + h(idx) = 1/6 * (rgb(idx,2) - rgb(idx,3)) ./ (v(idx) - s(idx)); + endif - # h1(blue) - h = h + ((h == 0) & sv(:,1) == 1 & sv(:,2) == 0) \ - .* (-1/6 * sv(:,3) + 1 + eps); + ## correct for negative red + idx = (h < 0); + h(idx) = 1+h(idx); - # h2(blue) - h = h + ((h == 0) & sv(:,1) == 0 & sv(:,2) == 1) \ - .* (1/6 * sv(:,3) + 1/3); + ## set the saturation + s(! notgray) = 0; + s(notgray) = 1 - s(notgray) ./ v(notgray); - hsval = [h, s, v']; + hsval = [h, s, v]; endfunction