在做老师的一个科研项目时接触到这个数据集,我搜集到的网上的资料较少,所以简单记录一下如何处理这个数据集。

 

BSDS500数据集下载地址:点这里

数据集的制作过程参考论文:A Database of Human Segmented Natural Images and its Application to Evaluating Segmentation Algorithms and Measuring Ecological Statistics,在此不详细阐述。

 

Matlab处理脚本

生成可视化轮廓图:

% make_gt_bondary_image.m
% bsdsRoot 变量的值为包含train、test、val文件夹的地址
%在处理时应当提前在train、test、和val下新建文件夹bon,bon里需要新建train、test、val两个子文件夹
state = 'test';%修改为test或train或val,分别处理两个文件夹 
file_list = dir(fullfile(bsdsRoot,state,'*.mat'));%获取该文件夹中所有jpg格式的图像
for i=1:length(file_list)
    mat = load(file_list(i).name);
    [~,image_name,~] = fileparts(file_list(i).name);
    gt = mat.groundTruth;
    for gtid=1:length(gt)
        bmap = gt{gtid}.Boundaries;
        if gtid==1
            image = bmap;
        else
            image(bmap==true)=true;
        end
 
    end
    %黑底白边
    imwrite(double(image),fullfile(bsdsRoot,'bon',state,[image_name '.jpg']));
    %白底黑边
    %imwrite(1-double(image),fullfile(bsdsRoot,'bon',state,[image_name '.jpg']));
 
end

如果处理的时train,则此脚本需要在train文件夹内运行。下同。

效果图

生成分块可视化图:

% make_gt_seg_image.m
% bsdsRoot 变量的值为包含train、test、val文件夹的地址
%在处理时应当提前在train、test、和val下新建文件夹bon,bon里需要新建train、test、val两个子文件夹
state = 'test';%修改为test或train或val,分别处理两个文件夹 
file_list = dir(fullfile(bsdsRoot,state,'*.mat'));%获取该文件夹中所有jpg格式的图像
for i=1:length(file_list)
    mat = load(file_list(i).name);
    [~,image_name,~] = fileparts(file_list(i).name);
    gt = mat.groundTruth;
    for gtid=1:length(gt)
        seg = double(gt{gtid}.Segmentation);
        seg = seg/max(max(seg));
        if gtid == 1
            image = seg;
        else
            image = image+seg;
        end
    end
    image = image/length(gt);
    imwrite(double(image),fullfile(bsdsRoot,'seg',state,[image_name '.jpg']));
 
end

效果图

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐