sal2edge.m:(含有实用代码,本代码是matlab) 将显著性检测的 salient maps 转换为 salient edge maps (对EGNet里面代码的解读)

1 源代码

将显著性检测的 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

2 实用代码

特别注意:对于有些数据是需使用
 gt = (gt > 0);才可以

data_root = '/home/nk/zjc/data/data-RGBD/train/NUK2K-NLPR-Train-2/X-edge/Mask';
out_root = '/home/nk/zjc/data/data-RGBD/train/NUK2K-NLPR-Train-2/X-edge/edge';
lst_set = '/home/nk/zjc/data/data-RGBD/train/NUK2K-NLPR-Train-2/X-edge/train';
index_file = fullfile([lst_set '.lst']);  % ./test.lst
disp(index_file)

fileID = fopen(index_file);
im_ids = textscan(fileID, '%s');
im_ids = im_ids{1};
fclose(fileID);


num_images = length(im_ids);

for im_id = 1:250

    id = im_ids{im_id};
    id = id(1:end-0);
    
%     img_path = fullfile(data_root, [id '.jpg']);
%     image = imread(img_path);
    disp('1')
    disp(fullfile(data_root, [id '.png']));
    gt = imread(fullfile(data_root, [id '.png']));

    
    
    gt = (gt > 0);
    gt = double(gt);

    [gy, gx] = gradient(gt);
    temp_edge = gy.*gy + gx.*gx;
    temp_edge(temp_edge~=0)=1;
    bound = uint8(temp_edge*255);
    %bound = uint8(temp_edge);

    save_path = fullfile(out_root, [id '.png']);
    disp('2')
    disp(save_path)
    imwrite(bound, save_path);
    %imwrite(gt, save_path);

end

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

计算机视觉-Archer

图像分割没有团队的同学可加群

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值