scale_for_display

PURPOSE ^

[elem_data,ref_lev,max_scale] = scale_for_display( elem_data, pp)

SYNOPSIS ^

function [elem_data,ref_lev,max_scale] = scale_for_display( elem_data, pp)

DESCRIPTION ^

 [elem_data,ref_lev,max_scale] = scale_for_display( elem_data, pp)

 PARAMETERS: elem_data
  elem_data: data for fem elements or image pixels

 PARAMETERS: ref_lev
  ref_lev:   if param provided, use it,
               otherwise use the global value
             Can be numeric or 'auto' or 'use_global' 

 PARAMETERS: clim
    clim - colour limit. Colours more different from ref_level are cropped.
         - if not specified or scale==[] => no limit

 OUTPUT: 
    ref_lev, max_scale - the centre and max of the colour scale
    elem_data - data scaled in the range [-1 .. 1]

 $Id: scale_for_display.m 5112 2015-06-14 13:00:41Z aadler $
 (C) 2006 Andy Adler. Licensed under GPL v2

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [elem_data,ref_lev,max_scale] = scale_for_display( elem_data, pp)
0002 % [elem_data,ref_lev,max_scale] = scale_for_display( elem_data, pp)
0003 %
0004 % PARAMETERS: elem_data
0005 %  elem_data: data for fem elements or image pixels
0006 %
0007 % PARAMETERS: ref_lev
0008 %  ref_lev:   if param provided, use it,
0009 %               otherwise use the global value
0010 %             Can be numeric or 'auto' or 'use_global'
0011 %
0012 % PARAMETERS: clim
0013 %    clim - colour limit. Colours more different from ref_level are cropped.
0014 %         - if not specified or scale==[] => no limit
0015 %
0016 % OUTPUT:
0017 %    ref_lev, max_scale - the centre and max of the colour scale
0018 %    elem_data - data scaled in the range [-1 .. 1]
0019 %
0020 % $Id: scale_for_display.m 5112 2015-06-14 13:00:41Z aadler $
0021 % (C) 2006 Andy Adler. Licensed under GPL v2
0022 
0023 %FIXME - set to use the colours in the img.calc_colours fields
0024 
0025    global eidors_colours;
0026    clim = [];
0027    if nargin <=1
0028       ref_lev = eidors_colours.ref_level;
0029       component = 'real';
0030    elseif ischar(pp)  && strcmp(pp, 'use_global' );
0031       ref_lev = eidors_colours.ref_level;
0032       component = 'real';
0033    else
0034       ref_lev = pp.ref_level;
0035       clim    = pp.clim;
0036       component = pp.component;
0037    end
0038 
0039    if ~isnumeric(ref_lev)
0040       if ~strcmp(ref_lev, 'auto')
0041           error('ref_level parameter must be "auto" or numeric');
0042       end
0043       s_ed= elem_data(:);
0044       s_ed(isnan(s_ed)) = [];
0045       s_ed= sort(s_ed);
0046       e= length(s_ed);
0047       if e==0;
0048          error('Can''t display. All values NaN. Is raw data 0?')
0049       end
0050       % ensure symmetric rejection of data for small data sets
0051       % This means that 1-2*.35 = .3 of the data will be used
0052       %  to take the mean. It should make for better centring
0053       %  of reconstructions - AA may2015
0054       rej_vals = floor(.35*e);
0055       ref_lev = mean(s_ed( (rej_vals+1):(end-rej_vals) ));
0056    end
0057 
0058    elem_data = elem_data - ref_lev;
0059 
0060    max_scale = max(abs(elem_data(:))) + eps;
0061 
0062    switch component;
0063       case 'real'; elem_data = real(elem_data);
0064       case 'imag'; elem_data = imag(elem_data);
0065       otherwise;   error('specified component not real or imag');
0066    end
0067 
0068    % Crop output to the colour limit
0069    if ~isempty(clim)
0070       elem_data( elem_data> clim)=  clim;
0071       elem_data( elem_data<-clim)= -clim;
0072       max_scale = clim;
0073    end
0074 
0075    if isfield(eidors_colours,'image_field')
0076       elem_data(eidors_colours.image_field_idx) = eidors_colours.image_field_val;
0077    end
0078 
0079    elem_data = elem_data/max_scale;

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005