subtract_rank

PURPOSE ^

SUBTRACK_RANK: subtract a ranked level from data

SYNOPSIS ^

function out = subtract_rank(in, ranklim)

DESCRIPTION ^

 SUBTRACK_RANK: subtract a ranked level from data

  imgout = subtract_rank(imgin, 0.3)
    subtract the 30% percentile from imgr.elem_data
  imgout = subtract_rank(imgin, [0.1,0.3])
    subtract an average of 10-30% percentile from imgr.elem_data

 if input is a 'image' object, then operate on elem_data. Otherwise operate on value

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out = subtract_rank(in, ranklim)
0002 % SUBTRACK_RANK: subtract a ranked level from data
0003 %
0004 %  imgout = subtract_rank(imgin, 0.3)
0005 %    subtract the 30% percentile from imgr.elem_data
0006 %  imgout = subtract_rank(imgin, [0.1,0.3])
0007 %    subtract an average of 10-30% percentile from imgr.elem_data
0008 %
0009 % if input is a 'image' object, then operate on elem_data. Otherwise operate on value
0010 
0011 % (C) 2024 Andy Adler. Licence GPL v2 or v3
0012 % $Id: subtract_rank.m 7124 2024-12-29 15:18:32Z aadler $
0013 
0014 if ischar(in) && strcmp(in,'UNIT_TEST'); do_unit_test; return; end
0015 
0016 if isstruct(in) && strcmp(in.type, 'image') 
0017    use_elem_data = true;
0018    out = in;
0019    in = in.elem_data;
0020 elseif isnumeric(in)
0021    use_elem_data = false;
0022 else
0023    error('Unknown type for subtract_rank');
0024 end
0025 
0026 [~,idx] = sort(sum(in,1));
0027 ll = length(idx);
0028 lim= round(ranklim([1,end])*ll);
0029 idx_= idx(lim(1):lim(2));
0030 
0031 sub= in - mean(in(:,idx_),2);
0032 if use_elem_data
0033   out.elem_data = sub;
0034 else
0035   out  = sub;
0036 end
0037 
0038 function do_unit_test
0039   ed = [1:10] + [0;3];
0040   x = subtract_rank(ed,.3);
0041   expect = [0;0] + [-2:7];
0042   unit_test_cmp('subtract_rank1',x,expect);
0043   x = subtract_rank(ed,[.1,.3]);
0044   expect = [0;0] + [-1:8];
0045   unit_test_cmp('subtract_rank2',x,expect);
0046 
0047   img = eidors_obj('image','','elem_data',ed);
0048   iout = subtract_rank(img,[.1,.3]);
0049   unit_test_cmp('subtract_rank3',iout.elem_data,expect);

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005