get_median_1d.m

来自「Adaptive median filter using Embedded MA」· M 代码 · 共 54 行

M
54
字号
%#emlfunction outbuf = get_median_1d(inbuf)numpixels = length(inbuf);tbuf = inbuf;for ii=eml.unroll(1:numpixels)    if bitand(ii,uint32(1)) == 1          tbuf = compare_stage1(tbuf);    else        tbuf = compare_stage2(tbuf);    endendoutbuf = tbuf;endfunction outbuf = compare_stage1(inbuf)numpixels = length(inbuf);tbuf = compare_stage(inbuf(1:numpixels-1));outbuf = [tbuf(:)' inbuf(numpixels)];endfunction outbuf = compare_stage2(inbuf)numpixels = length(inbuf);tbuf = compare_stage(inbuf(2:numpixels));outbuf = [inbuf(1) tbuf(:)'];endfunction [outbuf] = compare_stage(inbuf)step = 2;numpixels = length(inbuf);outbuf = inbuf;for ii=eml.unroll(1:step:numpixels)    t = compare_pixels([inbuf(ii), inbuf(ii+1)]);    outbuf(ii) = t(1);    outbuf(ii+1) = t(2);endendfunction outbuf = compare_pixels(inbuf)if (inbuf(1) > inbuf(2))    outbuf = [inbuf(1), inbuf(2)];else    outbuf = [inbuf(2), inbuf(1)];endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?