sal2edge.py: 将显著性检测的 salient maps 转换为 salient edge maps (对EGNet里面代码的解读)

 将显著性检测的 salient maps 转换为 salient edge maps

src_root = 'H:\matlab\Az_Docter_Project\MB';
dst_root = 'H:\matlab\Az_Docter_Project\MB_edge';
lst_set = 'H:\matlab\Az_Docter_Project\MB';
lst_set = [lst_set '.lst'];  % lst_set -> 'H:\matlab\Az_Docter_Project\MB.lst'
index_file = fullfile(lst_set);  % index_file ->  H:\matlab\Az_Docter_Project\MB.lst.lst

%open
fileID = fopen(index_file);  % disp(fileID) -> 3 表示有三个参数吗
im_ids = textscan(fileID, '%s'); 
% disp(im_ids)  -> {31x1 cell} 31表示.lst文件有多少行
im_ids = im_ids{1};
% disp(im_ids) 
%im_ids:
%    'COCO_train2014_000000004823'
%                ...
%    'COCO_train2014_000000014502'
fclose(fileID);  
% close

num_images = length(im_ids);  % 31
for im_id = 1:num_images  

    id = im_ids{im_id};  % 从1到31, 1为例 'COCO_train2014_000000004823'
    id = id(1:end-0);  % 原版是end-4,这是因为要减去'.png', 因为我们的MB.lst已经去掉后缀了这里不需要
    
%     img_path = fullfile(data_root, [id '.jpg']);
%     image = imread(img_path);
   
    gt = imread(fullfile(src_root, [id '.png']));  
    % fullfile加,会自动补充分割符号 -> 'H:\matlab\Az_Docter_Project\MB' + 'COCO_train2014_000000004823.png'
    % 'H:\matlab\Az_Docter_Project\MB\COCO_train2014_000000004823.png'
    
    %计算edge
    gt = (gt > 128);  % 只选取亮度到达一定程度的,在这里都一样
    gt = double(gt);

    [gy, gx] = gradient(gt);  % 计算xy方向的梯度
    temp_edge = gy.*gy + gx.*gx;  % x^2 + y^2
    temp_edge(temp_edge~=0)=1;  % 只要不等于零,置1
    bound = uint8(temp_edge*255);  % x255

    save_path = fullfile(dst_root, [id '_edge.png']);
    % out_root -> 'H:\matlab\Az_Docter_Project\MB'; 
    % id -> 'COCO_train2014_000000004823'
    % '_edge.png'
    imwrite(bound, save_path);

end

 

 

你可能感兴趣的:(MyTool,显著性检测,EGNet)