function out =data_normalize(in, min_percent, max_percent)%{
in:输入数据
min_percent:最小百分比0~100
max_percent:最大百分比0~100
out:归一化后数据
%}
in =double(in);
out = in;
tmp = in;
nan_ind =isnan(tmp);tmp(nan_ind)=[];ifisempty(tmp)return;
end
tmp =tmp(:);
min_data =prctile(tmp, min_percent);
max_data =prctile(tmp, max_percent);if max_data == min_data
out(~nan_ind)=0.0;return;
end
out =(in-min_data)/(max_data-min_data);out(out<0.0)=0.0;out(out>1.0)=1.0;
均衡化
function out =histogramEqualization(in, scale)%{
in:输入数据
scale:直方图格子数,256,4096,65536等
out:直方图均衡化后数据
%}
in =double(in);
nan_ind =isnan(in);
out = in;
min_value =min(in(:));
max_value =max(in(:));if max_value == min_value
out(~nan_ind)=0.0;return;
end
in =(in-min_value)/(max_value-min_value);
in =round(in*(scale-1))+1;
tmp = in;tmp(nan_ind)=[];
len_tmp =numel(tmp);
cnt =zeros(scale,1);for i =1: len_tmp
ind =tmp(i);cnt(ind)=cnt(ind)+1;
end
for i =2: scale
cnt(i)=cnt(i-1)+cnt(i);
end
f = cnt / len_tmp;
out = in;in(nan_ind)=1;out(:)=f(in(:));out(nan_ind)= nan;
网格化
function out =data_grid(in, lon, lat, width, height)%{
in:散点数据
lon:散点经度
lat:散点纬度
width:宽度(~180°~180°划分格子数)
height:高度(90°~-90°划分格子数)
out:全球网格化数据
输入的散点in,lon,lat,需自行预处理剔除无效值。
网格化的区域数据,需自行计算起始行列号后裁剪out。
%}%分配网格
cell_data =cell(height, width);%默认nan值
out =nan(height, width);%经纬度计算格子行列号
row =round((height-1)*(90.0-lat)/180.0)+1;
col =round((width-1)*(lon+180.0)/360.0)+1;%遍历散点数据,并将序号放入对应格子中
for i =1:length(in)
cur_row =row(i);
cur_col =col(i);
cell_data{cur_row, cur_col}=[cell_data{cur_row, cur_col}, i];
end
%遍历格子,并计算最终格子数据
for cur_row =1: height
for cur_col =1: width
if~isempty(cell_data{cur_row, cur_col})
ind = cell_data{cur_row, cur_col};%out(cur_row, cur_col)=mean(in(ind));%平均值
out(cur_row, cur_col)=median(in(ind));%中位数
end
end
end