"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/macros/color_classify.sci" (2 Nov 2011, 2817 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scilab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 function [label, certainty_level, confidence, secondary_label] = color_classify(RGB, method, aggregation)
    2 //
    3 // Classifies an image window into a single color: Red, Green, Blue, Yellow,
    4 // Black, or others.
    5 // Should work well under different lighting conditions and is robust to wrong white
    6 // balance. Should be simple enough for real time applications.
    7 //
    8 // AUTHOR 
    9 //  Ricardo Fabbri <rfabbri@gmail.com>
   10 //
   11 // USAGE
   12 //
   13 // INPUT 
   14 //  RGB - truecolor image
   15 //  method - 'hsv_sip' (default), 'distance_to_reference'
   16 //  aggregation - 'median' (default), 'mean', 'histogram', 'ransac'
   17 //
   18 // OUTPUT 
   19 //
   20 //  label - 'red', 'green', 'blue', 'yellow', 'black', 'white' or something else
   21 //
   22 //  certainty_level - 'certain', 'good guess', 'unreliable'.
   23 //
   24 //  confidence - a scalar from 0 to 1 indicating the confidence in the guess,
   25 //  for those algorithms that enable it; for other algorithms this is just -1.
   26 //   
   27 //  secondary_label - a secondary class label for the color when ambiguity
   28 //  occurs. This will only be set if certainty_level <> 'certain'. Multiple
   29 //  labels can be present here and are separated by '-'.
   30 //
   31 //  TODO
   32 //   perhaps a mask option.
   33 
   34 select argn(2)
   35   case 0
   36     error('Invalid number of arguments.')
   37   case 1
   38     method = 'hsv_sip';
   39     aggregation = 'median'
   40   case 2
   41     aggregation = 'median'
   42 end
   43 
   44 select aggregation
   45 case 'median'
   46   r = median(RGB(:,:,1));
   47   g = median(RGB(:,:,2));
   48   b = median(RGB(:,:,3));
   49 case 'mean'
   50   r = mean(RGB(:,:,1));
   51   g = mean(RGB(:,:,2));
   52   b = mean(RGB(:,:,3));
   53 case 'histogram'
   54 case 'ransac'
   55   error('not yet implemented');
   56 else
   57   error('invalid method');
   58 end
   59 
   60 // TODO instead of median can use a histogram-style result,
   61 // or, if too slow, a RANSAC-style approximation to it
   62 
   63 [label, certainty_level, confidence, secondary_label] = ...
   64   color_classify_single([r g b], method);
   65 
   66 
   67 endfunction
   68 //
   69 // -------------------------------------------------------------------------
   70 // SIP - Scilab Image Processing toolbox
   71 // Copyright (C) 2002-2009  Ricardo Fabbri
   72 //
   73 // This program is free software; you can redistribute it and/or modify
   74 // it under the terms of the GNU General Public License as published by
   75 // the Free Software Foundation; either version 2 of the License, or
   76 // (at your option) any later version.
   77 //
   78 // This program is distributed in the hope that it will be useful,
   79 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   80 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   81 // GNU General Public License for more details.
   82 //
   83 // You should have received a copy of the GNU General Public License
   84 // along with this program; if not, write to the Free Software
   85 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   86 // -------------------------------------------------------------------------
   87 //