0001 function out = subtract_rank(in, ranklim)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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);