1## Copyright (C) 2016 Carnë Draug <carandraug@octave.org> 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 3 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} {} lab2double (@var{lab}) 18## Convert L*a*b* data to uint8 precision. 19## 20## @var{lab} must be a L*a*b* image or colormap, i.e., its dimensions 21## must be MxNx3xK or Mx3. Its type must be double, single, uint16, 22## or uint8. 23## 24## When converted from double or single, L* values must range from 0 to 25## 100, while a* and b* range from -128 to 127. Values outside this range 26## will be capped. 27## 28## @seealso{lab2double, lab2rgb, lab2single, lab2uint8, lab2uin16, lab2xyz} 29## @end deftypefn 30 31function [lab] = lab2uint8 (lab) 32 if (nargin () != 1) 33 print_usage (); 34 endif 35 lab = lab2cls (lab, "uint8"); 36endfunction 37 38## Instead of testing the lab2uint8 function here, we test the 39## conversion from uint8 type. The actual tests for lab2uint8, 40## are spread all other lab2* functions. This makes the tests 41## simpler. 42 43%!test 44%! cm_uint8 = uint8 ([0 1 2 3 4 127 128 200 254 255]); 45%! cm_uint8 = repmat (cm_uint8(:), [1 3]); 46%! im2d_uint8 = reshape (cm_uint8, [5 2 3]); 47%! imnd_uint8 = permute (im2d_uint8, [1 4 3 2]); 48%! 49%! cm_uint16 = uint16 ([0 256 512 768 1024 32512 32768 51200 65024 65280]); 50%! cm_uint16 = repmat (cm_uint16(:), [1 3]); 51%! assert (lab2uint16 (cm_uint8), cm_uint16) 52%! im2d_uint16 = reshape (cm_uint16, [5 2 3]); 53%! assert (lab2uint16 (im2d_uint8), im2d_uint16) 54%! assert (lab2uint16 (imnd_uint8), permute (im2d_uint16, [1 4 3 2])) 55%! 56%! l1 = 100/255; 57%! cm = [ 58%! 0 -128 -128 59%! l1 -127 -127 60%! 2*l1 -126 -126 61%! 3*l1 -125 -125 62%! 4*l1 -124 -124 63%! 127*l1 -1 -1 64%! 128*l1 0 0 65%! 200*l1 72 72 66%! 254*l1 126 126 67%! 100 127 127]; 68%! im2d = reshape (cm, [5 2 3]); 69%! imnd = permute (im2d, [1 4 3 2]); 70%! 71%! assert (lab2double (cm_uint8), cm) 72%! assert (lab2double (im2d_uint8), im2d) 73%! assert (lab2double (imnd_uint8), imnd) 74%! 75%! assert (lab2single (cm_uint8), single (cm)) 76%! assert (lab2single (im2d_uint8), single (im2d)) 77%! assert (lab2single (imnd_uint8), single (imnd)) 78