Matlab 批处理图像的索引不匹配

Matlab 批处理图像的索引不匹配,matlab,image-processing,Matlab,Image Processing,为了计算一组图像的精确召回率,我得到了一个。但是我在定制它时遇到了一些问题。由于程序文件中没有任何图像,我无法实现原始的命名模式。在我的例子中,Method_Path和GT_Path中的图像的名称从1到N(例如500) 运行代码时,我得到以下错误 使用比连接部分文件名更好的做法 使用类似于[imName(1:end-4)、resultpath(end-3:end)]的代码是不可靠的,因为它对扩展长度的假设太多 我对您的代码做了一些修改: %% initialization clear all c

为了计算一组图像的精确召回率,我得到了一个。但是我在定制它时遇到了一些问题。由于程序文件中没有任何图像,我无法实现原始的命名模式。在我的例子中,Method_Path和GT_Path中的图像的名称从1到N(例如500)

运行代码时,我得到以下错误

使用比连接部分文件名更好的做法

使用类似于
[imName(1:end-4)、resultpath(end-3:end)]
的代码是不可靠的,因为它对扩展长度的假设太多

我对您的代码做了一些修改:

%% initialization
clear all
close all;clc;
method = 'mine'; % name of the salient object method you want to evaluate, you need to change it
dataset = 'Pascal'; % name of dataset, you need to change this
method_path='./AMC_AE_Pascal/';
GT_path='./Pascal_GT/';
im_pattern = '*.png'; %Image pattern (all PNG file in the folder).
resultpath = method_path;%resultpath = [method_path '*' '.png']; % path to saliency maps, you need to change this
truthpath = GT_path;%truthpath = [GT_path '*' '.png']; % path to ground-truth masks, yoiu need to change this
savepath = './result/PRcurve/'; % save path of the 256 combinations of precision-recall values
if ~exist(savepath,'dir')
    mkdir(savepath);
end
dir_im = dir(fullfile(resultpath, im_pattern));%dir_im = dir(resultpath);
assert(~isempty(dir_im),'No saliency map found, please check the path!');
dir_tr= dir(fullfile(truthpath, im_pattern));%dir_tr= dir(truthpath);
assert(~isempty(dir_tr),'No ground-truth image found, please check the path!');
assert(length(dir_im)==length(dir_tr),'The number of saliency maps and ground-truth images are not equal!')
imNum = length(dir_tr);
precision = zeros(256,1);
recall = zeros(256,1);
%% compute pr curve
for i = 1:imNum
    imName = dir_tr(i).name;
    input_im = imread(fullfile(resultpath, imName));%input_im = imread([imName(1:end-4),resultpath(end-3:end)]);
    truth_im = imread(fullfile(truthpath, imName));%truth_im = imread([truthpath(1:end-5),imName]);%truth_im = imread([truthpath(1:end-4),imName]);
    truth_im = truth_im(:,:,1);
    input_im = input_im(:,:,1);
    if max(max(truth_im))==255
        truth_im = truth_im./255;
    end
    for threshold = 0:255
        index1 = (input_im>=threshold);
        truePositive = length(find(index1 & truth_im));
        groundTruth = length(find(truth_im));
        detected = length(find(index1));
        if truePositive~=0
            precision(threshold+1) = precision(threshold+1)+truePositive/detected;
            recall(threshold+1) = recall(threshold+1)+truePositive/groundTruth;
        end
    end
    display(num2str(i));
end
precision = precision./imNum;
recall = recall./imNum;
pr = [precision'; recall'];
fid = fopen([savepath dataset, '_', method, '_PRCurve.txt'],'at');
fprintf(fid,'%f %f\n',pr);
fclose(fid);
disp('Done!');
如果在发布时遇到更多问题,只需使用调试器


我看不到任何文件名敏感性。
我尝试了以下PNG文件列表:

1.png
12345.png
12346.png
2.png
3 - Copy (2).png
3 - Copy (3).png
3 - Copy (4).png
3 - Copy (5).png
3 - Copy (6).png
3 - Copy (7).png
3 - Copy (8).png
3 - Copy (9).png
3 - Copy.png
3.png

谢谢你的回答,当N小于10时,一切正常。我认为处理两位或三位数字有一些问题。我搞不懂的事情!在我发布的代码中,当
imNum
大于10且不在任何文件名中时,我看不到任何问题。我用我测试过的文件名编辑了我的帖子。。。
1.png
12345.png
12346.png
2.png
3 - Copy (2).png
3 - Copy (3).png
3 - Copy (4).png
3 - Copy (5).png
3 - Copy (6).png
3 - Copy (7).png
3 - Copy (8).png
3 - Copy (9).png
3 - Copy.png
3.png