本文主要是介绍Matlab实现遥感图像2%线性拉伸,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
function outImg = GrayScaleTransform(img)[ylen, xlen] = size(img);bins = 0:65535;histcount = histc(img(:)', bins); %清除临时变量 clear bins max_val min_val; % 直方图裁剪,计算左值和右值[l_val, r_val] = calc_lr_val(histcount, xlen*ylen, 0.02); % 根据左值和右值,将图像由16位映射至8位 outImg = img_map(img, l_val, r_val);
endfunction [img_8bit] = img_map(img_16bit, l_val, r_val)[xlen, ylen, c] = size(img_16bit);img_8bit = zeros(xlen, ylen);% fprintf(' ... ... ... ... ... ... ... ... ...\n');
% fprintf(' ... IMG MAPPING FROM 16BIT TO 8BIT \n');
% fprintf(' ... Img mapping begin ... ... \n');% 按照左右值映射img_8bit = (img_16bit - l_val).*(255/(r_val-l_val));img_8bit = uint8(round(img_8bit));% fprintf(' ... Img mapping finshied !!! !!! \n\n');endfunction [l_val, r_val] = calc_lr_val(histcount, tt, per)% fprintf(' ... ... ... ... ... ... ... ... ...\n');
% fprintf(' ... CALC LEFT AND RIGHT VALUE \n');per_tt = tt*per; % 按百分比裁剪的像素个数 % 计算左值tmp = 0;for i = 1:length(histcount)tmp = tmp + histcount(i);if tmp >= per_ttl_val = i;break;endend% 计算右值tmp = 0;for i = 1:length(histcount)tmp = tmp + histcount(length(histcount)-i+1);if tmp >= per_ttr_val = length(histcount)-i+1;break;endend% fprintf(' ... Stretch Percentage is %d%%\n', per*100);
% fprintf(' ... Left Val is %d \n', l_val);
% fprintf(' ... Right Val is %d \n', r_val);
% fprintf(' ... ... ... ... ... ... ... ... ...\n\n');end
这篇关于Matlab实现遥感图像2%线性拉伸的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!