home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / COLOR.DI$ / HSV2RGB.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.6 KB  |  41 lines

  1. function M = hsv2rgb(H)
  2. %HSV2RGB Hue-saturation-value to red-green-blue conversion.
  3. %    M = HSV2RGB(H) converts an HSV color map to an RGB color map.
  4. %    Each map is a matrix with any number of rows, exactly three columns,
  5. %    and elements in the interval 0 to 1.  The columns of the input matrix,
  6. %    H, represent hue, saturation and value, respectively.  The columns of
  7. %    the resulting output matrix, M, represent intensity of red, blue and
  8. %    green, respectively.
  9. %
  10. %    As H(:,1), the hue, varies from 0 to 1, the resulting color varies
  11. %    from red, through yellow, green, cyan, blue and magenta, back to red.
  12. %    When H(:,2), the saturation, is 0, the colors are unsaturated; they
  13. %    are simply shades of gray.  When H(:,2) is 1, the colors are fully
  14. %    saturated; they contain no white component.  When H(:,3), the color
  15. %    value, varies from 0 to 1, the brightness increases.
  16. %
  17. %    The default colormap, HSV, is hsv2rgb([h s v]) where
  18. %    h is a linear ramp from 0 to 1 and both s and v are all 1's.
  19. %
  20. %    See also RGB2HSV, COLORMAP, RGBPLOT.
  21.  
  22. %    See Alvy Ray Smith, Color Gamut Transform Pairs, SIGGRAPH '78.
  23. %    C. B. Moler, 8-17-86, 5-10-91, 2-2-92.
  24. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  25.  
  26. h = H(:,1);
  27. s = H(:,2);
  28. v = H(:,3);
  29. h = 6*h(:);
  30. k = fix(h-6*eps);
  31. f = h-k;
  32. t = 1-s;
  33. n = 1-s.*f;
  34. p = 1-(s.*(1-f));
  35. e = ones(size(h));
  36. r = (k==0).*e + (k==1).*n + (k==2).*t + (k==3).*t + (k==4).*p + (k==5).*e;
  37. g = (k==0).*p + (k==1).*e + (k==2).*e + (k==3).*n + (k==4).*t + (k==5).*t;
  38. b = (k==0).*t + (k==1).*t + (k==2).*p + (k==3).*1 + (k==4).*1 + (k==5).*n;
  39. f = v./max([r(:);g(:);b(:)]);
  40. M = [f.*r f.*g f.*b];
  41.