Home > SuperSegger > viz > comp.m

comp

PURPOSE ^

comp : creates composite image

SYNOPSIS ^

function [ varargout ] = comp( varargin )

DESCRIPTION ^

 comp  : creates composite image

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ varargout ] = comp( varargin )
0002 % comp  : creates composite image
0003 
0004 label_flag = false;
0005 
0006 im_comp = [];
0007 
0008 for ii = 1:nargin
0009     
0010     data = varargin{ii};
0011 
0012     im   = [];
0013     del  = [];
0014     cc   = [];
0015     com  = [];
0016     com2 = [];
0017     
0018     
0019     if iscell( data )
0020         numin = numel( data );
0021         
0022 
0023         
0024         if numin == 0
0025             
0026         else
0027             im = data{1};
0028             
0029             jj = 2;
0030             
0031             while jj<=numin
0032                 
0033                 if ischar(data{jj})
0034                     if numel( data{jj} ) == 1
0035                         cc = data{jj};
0036                     else
0037                         com =  data{jj};
0038                         
0039                         if jj+1 > numin
0040                             com2 = 'ID';
0041                         else
0042                             com2 = data{jj+1};
0043                         end
0044                         
0045                         jj = jj + 1;
0046                         
0047                     end
0048                 elseif all(isnumeric( data{jj} ))
0049                     if numel(data{jj}) == 1
0050                         del = data{jj};
0051                     else
0052                         cc = data{jj};
0053                     end
0054                 end
0055                 
0056                 jj = jj + 1;
0057                 
0058             end
0059         end
0060     else
0061         im = data;
0062         del = [];
0063         cc = [];
0064     end
0065     
0066     if isempty( cc )
0067         if ii == 1
0068             cc = [1,1,1];
0069         else
0070             cc = [0,0,0];
0071             
0072             ind = mod(ii-2,3)+1;
0073             
0074             cc( ind ) = 1;
0075         end
0076     elseif ischar( cc)
0077         cc = convert_color( cc );
0078     end
0079     
0080     if isempty( del )
0081         
0082         if ~isempty( im ) && islogical( im )
0083             del = 0.2;
0084         else
0085             del = 1;
0086         end
0087         
0088     end
0089     
0090     if ~isempty( im )
0091         
0092         
0093         if ~isempty( com )
0094             
0095             if strcmp( com, 'label' )
0096                label_flag = true;
0097 
0098                 
0099                 if ischar( com2 )
0100                     com2_ = com2;
0101                 else
0102                     com2_ = '';
0103                 end
0104                 
0105                 ID_flag = false;
0106                 if strcmp( com2_, 'ID' )
0107                     com2_ = '';
0108                     ID_flag = true;
0109                 end
0110                 
0111                 
0112                 if isempty( com2_ )
0113                     str = {'Centroid'};
0114                 else
0115                     str = {'Centroid',com2_};
0116                 end
0117                 
0118                 props = regionprops( im, str );
0119                 
0120                 
0121                 if ID_flag
0122                     vec = 1:numel(props);
0123                     
0124                 elseif ischar( com2 )
0125                     vec = drill( props, ['.',com2_] );
0126                 else
0127                     vec = com2;
0128                 end
0129             end
0130         end
0131 
0132         if strcmp( com,'log' )
0133             if isempty( com2 ) || strcmp( com2, 'ID' )
0134                com2 = 0;
0135             end
0136             
0137             backer = double(ag( log(double(im+com2)) ));
0138             
0139         elseif strcmp( com,'pow' )
0140             backer = double(ag( (double(im).^com2) ));
0141         else
0142             backer = double(ag( im ));
0143         end
0144         
0145         if numel(cc)>3
0146             im_tmp = (255*(doColorMap( backer, cc )));
0147         else
0148             im_tmp = cat(3, backer*del*cc(1), backer*del*cc(2), backer*del*cc(3) );
0149         end
0150         
0151         if isempty( im_comp )
0152             im_comp = im_tmp;
0153         else
0154             im_comp = im_comp + im_tmp;
0155         end
0156         
0157             
0158         
0159     end
0160 end
0161 
0162 im_comp = uint8(im_comp);
0163 
0164 if nargout == 0
0165     imshow( im_comp );
0166     varargout = {};
0167     
0168     if label_flag 
0169         hold on;
0170         x = drill( props, '.Centroid(1)' );
0171         y = drill( props, '.Centroid(2)' );
0172         
0173         vec = reshape( vec, size(x) );
0174         text( x, y, num2str( vec, '%2.2g' ) );
0175         
0176     end
0177 else
0178     varargout{1} = im_comp;
0179 end
0180 
0181 end
0182 
0183 
0184 %% From the internet
0185 % by Ben Mitch
0186 % 06 Jun 2002 (Updated 07 Jun 2002)
0187 % Convert colour names (blue,teal,pale green) into RGB triplets.
0188 
0189 function outColor = convert_color(inColor)
0190 
0191   charValues = 'rgbcmywk'.';  %#'
0192   rgbValues = [eye(3); 1-eye(3); 1 1 1; 0 0 0];
0193   assert(~isempty(inColor),'convert_color:badInputSize',...
0194          'Input argument must not be empty.');
0195 
0196   if ischar(inColor)  %# Input is a character string
0197 
0198     [isColor,colorIndex] = ismember(inColor(:),charValues);
0199     assert(all(isColor),'convert_color:badInputContents',...
0200            'String input can only contain the characters ''rgbcmywk''.');
0201     outColor = rgbValues(colorIndex,:);
0202 
0203   elseif isnumeric(inColor) || islogical(inColor)  %# Input is a numeric or
0204                                                    %#   logical array
0205     assert(size(inColor,2) == 3,'convert_color:badInputSize',...
0206            'Numeric input must be an N-by-3 matrix');
0207     inColor = double(inColor);           %# Convert input to type double
0208     scaleIndex = max(inColor,[],2) > 1;  %# Find rows with values > 1
0209     inColor(scaleIndex,:) = inColor(scaleIndex,:)./255;  %# Scale by 255
0210     [isColor,colorIndex] = ismember(inColor,rgbValues,'rows');
0211     assert(all(isColor),'convert_color:badInputContents',...
0212            'RGB input must define one of the colors ''rgbcmywk''.');
0213     outColor = charValues(colorIndex(:));
0214 
0215   else  %# Input is an invalid type
0216 
0217     error('convert_color:badInputType',...
0218           'Input must be a character or numeric array.');
0219 
0220   end
0221   
0222   
0223 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005