function []=detection_cfar_gaussian(sar_data,clutter_win,protect_win,times)
%function []=detection_cfar_gaussian(sar_data)
% =============================================== %
% 基于高斯分布的CFAR检测算法(双参数CFAR检测)
% ----------------------------------------------- %
% 输入参数
% clutter_win 背景窗口半长
% protect_win 保护窗口半长
% times 求解检测阈值时,均值加上标准差的倍数
% two_stage_flag 是否进行两阶段处理
% 输出参数
% data_out 检测后的二值图像
% =============================================== %
% global sar_data_backup
tic;
disp(['CFAR检测开始']);
%F1=uint8(F1);
%sar_data=sar_data.*F1;
%clutter_win=12;
%protect_win=8;
%times=5;
two_stage_flag=0;
%sar_data=imread('2.tif');
%sar_data=rgb2gray(sar_data);
%imshow(sar_data);
sar_data=double(sar_data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%对提取的数据进行处理%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[r,c] = size(sar_data);
sar_data_backup=sar_data;
sar_data_backup = zeros(r+2*clutter_win,c+2*clutter_win); % SAR 数据边缘补充
sar_data_backup(1:clutter_win,1+clutter_win:c+clutter_win) = repmat(sar_data(1,:),clutter_win,1);
sar_data_backup(1+r+clutter_win:end,1+clutter_win:c+clutter_win) = repmat(sar_data(r,:),clutter_win,1);
sar_data_backup(1+clutter_win:clutter_win+r,1+clutter_win:c+clutter_win) = sar_data(:,:);
sar_data_backup(:,1:clutter_win) = repmat(sar_data_backup(:,1+clutter_win),1,clutter_win);
sar_data_backup(:,1+clutter_win+c:end) = repmat(sar_data_backup(:,clutter_win+c),1,clutter_win);
[row,col]=size(sar_data_backup);
data_out=zeros(row,col);
if two_stage_flag == 0; % 正常CFAR
for x=1+clutter_win:row-clutter_win
for y=1+clutter_win:col-clutter_win
clutter_data = detection_get_clutter(sar_data_backup,clutter_win,protect_win,x,y); % 获取杂波
threshold = detection_count_th_gaussian(clutter_data,times); % 计算阈值
if (sar_data_backup(x,y)>threshold)
data_out(x,y)=1;% 检测结果(二值)
else
data_out(x,y)=0;% 检测结果(二值)
end
end
end
else % 两阶段快速CFAR
flag_data = detection_select_big(sar_data_backup,0.0037);% 检测出回波较强的点,只对这些点检测,使用输出参数记录flag_data记录回波较亮的点的位置,亮点处的值为1
for x=1+clutter_win:row-clutter_win
for y=1+clutter_win:col-clutter_win
if flag_data(x,y)==1% 只处理亮点,使运算速度快。
clutter_data = detection_get_clutter(sar_data_backup,clutter_win,protect_win,x,y); % 获取杂波
threshold = detection_count_th_gaussian(clutter_data,times); % 计算阈值
if (sar_data_backup(x,y)>threshold)
data_out(x,y)=1;% 检测结果(二值)
else
data_out(x,y)=0;
end
end
end
end
end
data_out=data_out(clutter_win+1:r+clutter_win,clutter_win+1:c+clutter_win);
figure(5),imshow(data_out),title('cfar检测后的二值图像');
imwrite(data_out,'cfar检测后的二值图像.tif','tif');
toc;
disp(['CFAR检测完成']);
评论6