function boundaryBenchHtml(baseDir) % function boundaryBenchHtml(baseDir) % % See also boundaryBench, boundaryBenchGraphs. % % David Martin % May 2003 bsdsURL = 'http://www.cs.berkeley.edu/projects/vision/grouping/segbench/BSDS300'; presentations = {'gray','color'}; presNames = {'Grayscale','Color'}; iidsTest = imgList('test'); % Infer list of algorithms from directories present. for k = 1:length(presentations), pres = presentations{k}; dirlist = dir(fullfile(baseDir,pres)); algs{k} = {}; for i = 1:length(dirlist), alg = dirlist(i).name; if alg(1)=='.', continue; end if strcmp(alg,'human'), continue; end if ~isdir(fullfile(baseDir,pres,alg)), continue; end if length(dir(fullfile(baseDir,pres,alg,'name.txt')))~=1, continue; end if length(dir(fullfile(baseDir,pres,alg,'score.txt')))~=1, continue; end fname = fullfile(baseDir,pres,alg,'scores.txt'); if length(dir(fname))~=1, continue; end tmp = dlmread(fname); % iid,thresh,r,p,f if size(tmp,1)~=numel(iidsTest), continue; end algs{k}{1+numel(algs{k})} = alg; end end % Read in all the scores. for k = 1:length(presentations), pres = presentations{k}; for i = 1:numel(algs{k}), alg = algs{k}{i}; fprintf(2,'Processing directory %s/%s...\n',pres,alg); fname = fullfile(baseDir,pres,alg,'scores.txt'); iscores{k}{i} = dlmread(fname); % iid,thresh,r,p,f fname = fullfile(baseDir,pres,alg,'score.txt'); ascores{k}{i} = dlmread(fname); % thresh,r,p,f fname = fullfile(baseDir,pres,alg,'name.txt'); fp = fopen(fname,'r'); names{k}{i} = fgetl(fp); fclose(fp); end fname = fullfile(baseDir,pres,'human','scores.txt'); if numel(dir(fname))>0, hiscores{k} = dlmread(fname); % iid,r,p,f else hiscores{k} = zeros(10000,4); end fname = fullfile(baseDir,pres,'human','score.txt'); if numel(dir(fname))>0, hscore{k} = dlmread(fname); % r,p,f else hscore{k} = zeros(3,1); end end % Sort algorithms by overall F measure. fprintf(2,'Sorting algorithms...\n'); for k = 1:length(presentations), pres = presentations{k}; f = []; for i = 1:numel(algs{k}), f = [f ascores{k}{i}(4)]; end [unused,aperm{k}] = sort(f); aperm{k} = aperm{k}(end:-1:1); end % Create algorithms page. fprintf(2,'Creating algorithms page...\n'); [u1,u2,u3] = mkdir(baseDir,'html'); mainPage = fullfile(baseDir,'html','algorithms.html'); fp = fopen(mainPage,'w'); title = 'Boundary Detection Benchmark: Algorithm Ranking'; fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'%s\n',title); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'

Go to Main Page.\n'); fprintf(fp,'

Go to Image Ranking.\n'); fprintf(fp,'

%s

\n',title); fprintf(fp,'

Summary Tables

\n',presNames{k}); fprintf(fp,'

\n'); fprintf(fp,'\n'); for k = 1:length(presentations), pres = presentations{k}; fprintf(fp,'\n',presNames{k}); end fprintf(fp,'\n'); fprintf(fp,'\n'); for k = 1:length(presentations), fprintf(fp,'\n'); end fprintf(fp,'\n'); fprintf(fp,'
%s
\n'); pres = presentations{k}; fprintf(fp,'

\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n',hscore{k}(3)); fprintf(fp,'\n'); fprintf(fp,'\n'); for i = 1:numel(algs{k}), alg = algs{k}{aperm{k}(i)}; name = names{k}{aperm{k}(i)}; score = ascores{k}{aperm{k}(i)}(4); fprintf(fp,'\n'); fprintf(fp,'\n',i); fprintf(fp,'\n',score); fprintf(fp,'\n',pres,alg,name); fprintf(fp,'\n'); end fprintf(fp,'
RankScoreAlgorithm
0%4.2fHumans
%d%4.2f%s
\n'); fprintf(fp,'

\n'); fprintf(fp,'

Comparison Graphs

\n',presNames{k}); fprintf(fp,'

\n'); fprintf(fp,'\n'); for k = 1:length(presentations), pres = presentations{k}; fprintf(fp,'\n',presNames{k}); end fprintf(fp,'\n'); fprintf(fp,'\n'); for k = 1:length(presentations), fprintf(fp,'\n'); end fprintf(fp,'\n'); fprintf(fp,'
%s
\n'); fprintf(fp,'
    \n'); pres = presentations{k}; for i = 1:numel(algs{k}), for j = i+1:numel(algs{k}), ii = aperm{k}(i); jj = aperm{k}(j); fprintf(fp,'
  • %s vs. %s\n',pres,i,j,names{k}{ii},names{k}{jj}); end end fprintf(fp,'
\n'); fprintf(fp,'
\n'); fprintf(fp,'

Detail Tables

\n',presNames{k}); for k = 1:length(presentations), pres = presentations{k}; fprintf(fp,'

%s

\n',presNames{k}); fprintf(fp,'

\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n',hscore{k}(3)); fprintf(fp,'\n'); fprintf(fp,'\n',pres); fprintf(fp,'\n'); for i = 1:numel(algs{k}), alg = algs{k}{aperm{k}(i)}; name = names{k}{aperm{k}(i)}; score = ascores{k}{aperm{k}(i)}(4); fprintf(fp,'\n'); fprintf(fp,'\n',i); fprintf(fp,'\n',score); fprintf(fp,'\n',pres,alg,name); fprintf(fp,'\n',pres,alg); fprintf(fp,'\n'); end fprintf(fp,'
RankScoreAlgorithmPR Curve
0%4.2fHumans
%d%4.2f%s
\n'); end fprintf(fp,'

Page generated on %s.\n',datestr(now)); fprintf(fp,'\n'); fprintf(fp,'\n'); fclose(fp); % Create algorithm pages. for k = 1:length(presentations), pres = presentations{k}; for i = 1:numel(algs{k}), alg = algs{k}{i}; fprintf(2,'Creating page for ''%s''...\n',alg); fname = fullfile(baseDir,pres,alg,'main.html'); fp = fopen(fname,'w'); title = sprintf('[%s] Boundary Detection Benchmark: Algorithm "%s"',presNames{k},names{k}{i}); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'%s\n',title); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'

Back to Algorithm Ranking.\n'); fprintf(fp,'

%s

\n',title); fname2 = fullfile(baseDir,pres,alg,'about.html'); if length(dir(fname2))==1, fprintf(fp,'

\n'); fp2 = fopen(fname2,'r'); fwrite(fp,char(fread(fp2)')); fclose(fp2); end fprintf(fp,'

\n'); fprintf(fp,'

Click on an image for additional details.\n'); %fprintf(fp,'

Test Images

\n'); fprintf(fp,'

\n'); nper = 5; for j = 1:numel(iidsTest), iid = iidsTest(j); score = iscores{k}{i}(j,5); if iid~=iscores{k}{i}(j,1), error('bug'); end if mod(j,nper)==1, fprintf(fp,'\n'); end fprintf(fp,'\n'); if mod(j,nper)==0 | j==numel(iidsTest), fprintf(fp,'\n'); end end fprintf(fp,'
\n'); fprintf(fp,'
\n'); fprintf(fp,'#%d (%d) F=%4.2f
',j,iid,score); %fprintf(fp,'#%d (%d)
\n',j,iid); fprintf(fp,'\n',iid); fprintf(fp,'\n',bsdsURL,pres,iid); fprintf(fp,'\n'); fprintf(fp,'
\n'); fprintf(fp,'
\n'); fprintf(fp,'

Page generated on %s.\n',datestr(now)); fprintf(fp,'\n'); fprintf(fp,'\n'); fclose(fp); % Create image pages for this algorithm. for j = 1:numel(iidsTest), iid = iidsTest(j); score = iscores{k}{i}(j,5); fname = fullfile(baseDir,pres,alg,sprintf('%d.html',iid)); fp = fopen(fname,'w'); title = sprintf(... '[%s] Boundary Detection Benchmark: Algorithm "%s" Image #%d (%d)',presNames{k},names{k}{i},j,iid); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'%s\n',title); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'

Back to Algorithm "%s" page.\n',names{k}{i}); fprintf(fp,'

%s

\n',title); %fprintf(fp,'

F=%4.2f',score); fprintf(fp,'

\n',bsdsURL,pres,iid); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'>\n',iid); fprintf(fp,'\n',iid); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'>\n',iid); fprintf(fp,'\n',iid); fprintf(fp,'\n'); fprintf(fp,'
Machine
Human
\n'); fprintf(fp,'

Page generated on %s.\n',datestr(now)); fprintf(fp,'\n'); fprintf(fp,'\n'); fclose(fp); end end end % Sort the images by best F measure across all algorithms. % Remember which algorithm had the best score for each image. fprintf(2,'Sorting images...\n'); for k = 1:length(presentations), if numel(algs{k})==0, continue; end bestf{k} = zeros(numel(iidsTest),1); bestalg{k} = zeros(numel(iidsTest),1); for j = 1:numel(iidsTest), f = zeros(numel(algs{k}),1); for i = 1:numel(algs{k}), f(i) = iscores{k}{i}(j,5); end [bestf{k}(j),bestalg{k}(j)] = max(f); end [unused,iperm{k}] = sort(bestf{k}); iperm{k} = iperm{k}(end:-1:1); end % Create images page. fprintf(2,'Creating images page...\n'); mainPage = fullfile(baseDir,'html','images.html'); fp = fopen(mainPage,'w'); title = 'Boundary Detection Benchmark: Image Ranking'; fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'%s\n',title); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'

Go to Main Page.\n'); fprintf(fp,'

Go to Algorithm Ranking.\n'); fprintf(fp,'

%s

\n',title); fprintf(fp,'

Click on an image for additional details.\n'); fprintf(fp,'

\n'); fprintf(fp,'\n'); for k = 1:length(presentations), fprintf(fp,'\n',presNames{k}); end fprintf(fp,'\n'); fprintf(fp,'\n'); for k = 1:length(presentations), fprintf(fp,'\n'); end fprintf(fp,'\n'); for j = 1:numel(iidsTest), fprintf(fp,'\n'); fprintf(fp,'\n',j); for k = 1:length(presentations), if numel(algs{k})==0, fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); continue; end pres = presentations{k}; iid = iidsTest(iperm{k}(j)); f = bestf{k}(iperm{k}(j)); maxf = hiscores{k}(iperm{k}(j),4); alg = algs{k}{bestalg{k}(iperm{k}(j))}; name = names{k}{bestalg{k}(iperm{k}(j))}; fprintf(fp,'\n',iperm{k}(j),iid); fprintf(fp,'\n'); fprintf(fp,'\n',pres,alg,name,f,maxf); end fprintf(fp,'\n'); end fprintf(fp,'
%s
RankIDImageBest Algorithm [Score]
%d#%d (%d)\n'); fprintf(fp,'\n',iid,pres); fprintf(fp,'\n',bsdsURL,pres,iid); fprintf(fp,'\n'); fprintf(fp,'%s
[ %4.2f / %4.2f ]
\n'); fprintf(fp,'

Page generated on %s.\n',datestr(now)); fprintf(fp,'\n'); fprintf(fp,'\n'); fclose(fp); % Create image pages. for j = 1:numel(iidsTest), iid = iidsTest(j); fprintf(2,'Creating pages for image #%d (%d)...\n',j,iid); for k = 1:length(presentations), if numel(algs{k})==0, continue; end pres = presentations{k}; fname = fullfile(baseDir,'html',sprintf('%d-%s.html',iid,pres)); fp = fopen(fname,'w'); title = sprintf('[%s] Boundary Detection Benchmark: Image #%d (%d) Rank=%d',presNames{k},j,iid,find(iperm{k}==j)); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'%s\n',title); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'

Back to Image Ranking.\n'); fprintf(fp,'

Go to %s page.\n',iid,presentations{3-k},presNames{3-k}); fprintf(fp,'

%s

\n',title); f = zeros(numel(algs{k}),1); for i = 1:numel(algs{k}), f(i) = iscores{k}{i}(j,5); end [unused,perm] = sort(f); perm = perm(end:-1:1); fprintf(fp,'

\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n',hiscores{k}(j,4)); fprintf(fp,'\n'); fprintf(fp,'\n'); for i = 1:numel(algs{k}), fprintf(fp,'\n'); fprintf(fp,'\n',i); fprintf(fp,'\n',f(perm(i))); fprintf(fp,'\n',names{k}{perm(i)}); fprintf(fp,'\n'); end fprintf(fp,'
RankScoreAlgorithm
0%4.2fHumans
%d%4.2f%s
\n'); fprintf(fp,'

\n'); fprintf(fp,'\n',bsdsURL,pres,iid); fprintf(fp,'\n',pres,iid); fprintf(fp,'

\n'); fprintf(fp,'\n'); fprintf(fp,'\n'); fprintf(fp,'\n',hiscores{k}(j,4)); fprintf(fp,'\n',pres,iid); fprintf(fp,'\n',pres,iid); fprintf(fp,'\n'); for i = 1:numel(algs{k}), fprintf(fp,'\n'); fprintf(fp,'\n',i,names{k}{perm(i)},f(perm(i))); fprintf(fp,'\n',pres,algs{k}{perm(i)},iid); fprintf(fp,'\n',pres,algs{k}{perm(i)},iid); fprintf(fp,'\n'); end fprintf(fp,'
Rank Algorithm (Score)PbPrecision/Recall
0
Humans
(%4.2f)
%d
%s
(%4.2f)
\n'); fprintf(fp,'

Page generated on %s.\n',datestr(now)); fprintf(fp,'\n'); fprintf(fp,'\n'); fclose(fp); end end