X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Frgb2ycbcr.m;fp=octave_packages%2Fimage-1.0.15%2Frgb2ycbcr.m;h=f637adacad14cbaa856b4abf13ef96a4c21fb46f;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/image-1.0.15/rgb2ycbcr.m b/octave_packages/image-1.0.15/rgb2ycbcr.m new file mode 100644 index 0000000..f637ada --- /dev/null +++ b/octave_packages/image-1.0.15/rgb2ycbcr.m @@ -0,0 +1,39 @@ +## Copyright (C) 2011 Santiago Reyes González +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## -*- texinfo -*- +## @deftypefn {Function File} @var{B} = rgb2ycbcr(@var{A}) +## Perform colour convertion from RGB to YCbCr on a given image. +## +## The image @var{A} must be a NxMx3 image. The conversion +## The convertion changes the image from the RGB color model to YCbCr e.g. +## @example +## imOut = rgb2ycbcr(imIn); +## @end example +## Currently this function only works with @samp{uint8} and will always return +## an @samp{uint8} matrix. +## @seealso{cmunique} +## @end deftypefn + +function im_out = rgb2ycbcr(im) + if (nargin != 1) + print_usage; + elseif (length(size(im)) != 3 || size(im,3) != 3) + error("image must be NxMx3"); + endif + + im = im2double(im); + im_out(:,:,1) = uint8(floor(77*im(:,:,1) + 150*im(:,:,2) + 29*im(:,:,3))); + im_out(:,:,2) = uint8(floor(((-44*im(:,:,1) - 87*im(:,:,2) + 131*im(:,:,3))/256 + 0.5)*256)); + im_out(:,:,3) = uint8(floor(((131*im(:,:,1) - 110*im(:,:,2) - 21*im(:,:,3))/256 + 0.5)*256)); + +endfunction