评估二值化的数据集指标,白色像素占整个图像的区域面积

最近项目组搭了一个二值化的数据集,因此也需要对比一些相关的数据指标,其中一个就是 衡量foreground map(白色区域)所占整个图像的面积比例,即obj.area,因此自己写了一个matlab脚本,希望会对别人有好处吧。

废话不多说,直接贴代码:

直接将你需要测试的数据集,放在根目录下,然后再脚本中修改下你的文件名称即可。

clc
clear
close all

% Evaluation Dataset metric
% For binary image dataset, this .m file compute the mean ratio of the foreground map into entire map on dataset. 


dataset_path = ['./dataset/']; % put your dataset_path into this path, then run this .m file.
imgFiles = dir(dataset_path); 
imgNUM = length(imgFiles)-2;

tic;
total_ratio = 0;

for i = 1:imgNUM

    name =  imgFiles(i+2).name;
    Pic = imread([dataset_path name]);
    Level = 0.1;
    Pic = im2bw(Pic, Level);    % binary image
    A = Pic;
    S = numel(A);               % total number of pixel in entire image
    s = sum(sum(A));            % total number of pixel in the foreground 
    ratio = s/S;
    total_ratio = total_ratio + ratio;
    fprintf('The %d image ratio is: %d/%d\n',i,ratio,imgNUM);
   end

fprintf('The mean ratio is: %d\n',rem(total_ratio/imgNUM,1));

版权声明:本文为qq_19329785原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。