Skip to content

Commit

Permalink
roc: Tools for ROC analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
j0sh committed Jun 25, 2013
1 parent a179bdc commit ef1f70d
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 0 deletions.
2 changes: 2 additions & 0 deletions roc-res/driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
matlab -nojvm -nodisplay -nosplash -r "$1;quit"
stty echo
13 changes: 13 additions & 0 deletions roc-res/itti.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function itti()
addpath(genpath('/home/josh/Desktop/simpsal'));
prefix='/media/Grains/saliency/learning/achanta-dataset/';
dirp=strcat(prefix, 'images/*.jpg');
files=dir(dirp);
for j = 1:length(files)
fname = files(j).name;
disp(strcat('Processing ', fname));
img = imread(strcat(prefix, 'images/', fname));
map = simpsal(img);
bigmap = mat2gray(imresize(map, [size(img, 1) size(img, 2)]));
imwrite(bigmap, strcat(prefix, 'results-imap/', fname), 'jpg');
end
102 changes: 102 additions & 0 deletions roc-res/process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

our_files=`ls dataset1/ours_*`
ftsrd_files=`ls dataset1/ftsrd_*`
smap_files=`ls dataset1/smap_*`
imap_files=`ls dataset1/imap_*`

function precision {
count=$#
for i in $(seq 2 255);
do
bar=0
for g in $@
do
foo=`sed -n "${i}p" $g | grep -Eo "precision [0-9].[0-9]+|precision -?nan" | grep -Eo "[0-9].[0-9]+|-?nan"`
bar=`echo "$foo + $bar" | bc`
done
echo "$bar / $count" | bc -l
done

}

function recall {
count=$#
for i in $(seq 2 255);
do
bar=0
for g in $@
do
foo=`sed -n "${i}p" $g | grep -Eo "recall [0-9].[0-9]+|recall -?nan" | grep -Eo "[0-9].[0-9]+|-?nan"`
bar=`echo "$foo + $bar" | bc`
done
echo "$bar / $count" | bc -l
done
}

function fpr {
count=$#
for i in $(seq 2 255);
do
bar=0
for g in $@
do
foo=`sed -n "${i}p" $g | grep -Eo "fpr [0-9].[0-9]+|fpr -?nan" | grep -Eo "[0-9].[0-9]+|-?nan"`
bar=`echo "$foo + $bar" | bc`
done
echo "$bar / $count" | bc -l
done
}

#recall $our_files | tee dataset1/ours.recall
#recall $ftsrd_files |tee dataset1/ftsrd.recall
#recall $smap_files | tee dataset1/smap.recall
#recall $imap_files | tee dataset1/imap.recall
#precision $our_files | tee dataset1/ours.precision
#precision $ftsrd_files | tee dataset1/ftsrd.precision
#precision $smap_files | tee dataset1/smap.precision
#precision $imap_files | tee dataset1/imap.precision
#fpr $our_files | tee dataset1/ours.fpr
#fpr $ftsrd_files | tee dataset1/ftsrd.fpr
#fpr $smap_files | tee dataset1/smap.fpr
#fpr $imap_files | tee dataset1/imap.fpr

#imap_files2=`ls dataset2/imap_*`
#precision $imap_files2 | tee dataset2/imap.precision
#recall $imap_files2 | tee dataset2/imap.recall
#fpr $imap_files2 | tee dataset2/imap.fpr

#kmap_files2=`ls dataset2/kmap_*`
#precision $kmap_files2 | tee dataset2/kmap.precision
#recall $kmap_files2 | tee dataset2/kmap.recall
#fpr $kmap_files2 | tee dataset2/kmap.fpr

#smap_files2=`ls dataset2/smap_*`
#precision $smap_files2 | tee dataset2/smap.precision
#recall $smap_files2 | tee dataset2/smap.recall
#fpr $smap_files2 | tee dataset2/smap.fpr

our_files10=`ls dataset-1.00/ours_*`
#precision $our_files10 | tee dataset-0.10/ours.precision
recall $our_files10 | tee dataset-1.00/ours.recall
fpr $our_files10 | tee dataset-1.00/ours.fpr

our_files75=`ls dataset-0.75/ours_*`
#precision $our_files75 | tee dataset-0.75/ours.precision
recall $our_files75 | tee dataset-0.75/ours.recall
fpr $our_files75 | tee dataset-0.75/ours.fpr

#our_files25=`ls dataset-0.25/ours_*`
#precision $our_files25 | tee dataset-0.25/ours.precision
#recall $our_files25 | tee dataset-0.25/ours.recall
#fpr $our_files25 | tee dataset-0.25/ours.fpr

#our_files2=`ls dataset2/ours_*`
#precision $our_files2 | tee dataset2/ours.precision
#recall $our_files2 | tee dataset2/ours.recall
#fpr $our_files2 | tee dataset2/ours.fpr

#ftsrd_files2=`ls dataset2/ftsrd_*`
#precision $ftsrd_files2 | tee dataset2/ftsrd.precision
#recall $ftsrd_files2 | tee dataset2/ftsrd.recall
#fpr $ftsrd_files2 | tee dataset2/ftsrd.fpr
14 changes: 14 additions & 0 deletions roc-res/walther.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function walther()
% saliency using walther and koch
addpath(genpath('/home/josh/Desktop/SaliencyToolbox'));
prefix='/media/Grains/saliency/learning/achanta-dataset/';
p=strcat(prefix, 'images');
salmaps = batchSaliency(p);
files=dir(strcat(p, '/*.jpg'));
for j = 1:length(salmaps)
fname = files(j).name;
disp(strcat('Processing ', fname));
img = imread(strcat(prefix, 'images/', fname));
bigmap = mat2gray(imresize(salmaps(j).data, [size(img, 1) size(img, 2)]));
imwrite(bigmap, strcat(prefix, 'results-kmap/', fname), 'jpg');
end
11 changes: 11 additions & 0 deletions roc-res/xhou.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function xhou()
% saliency using spectral residual
prefix='/media/Grains/saliency/learning/achanta-dataset/';
dirp=strcat(prefix, 'images/*.jpg');
files=dir(dirp);
for j = 1:length(files)
fname = files(j).name;
disp(strcat('Processing ', fname));
img = spectralresidual(strcat(prefix, '/images/', fname));
imwrite(img, strcat(prefix, 'results-smap/', fname), 'jpg');
end
77 changes: 77 additions & 0 deletions roc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <stdio.h>

#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc_c.h>

static void print_usage(char **argv)
{
printf("Usage: %s <file1> <file2> <file3>\n", argv[0]);
exit(1);
}

static int tp, fp, fn, tn;
static void cmp_thresh(IplImage *a, IplImage *gt, double thresh)
{
int w = gt->width, h = gt->height, x, y;
int stride = gt->widthStep;
uint8_t *tdata, *gdata;
IplImage *thr = cvCloneImage(a);
cvThreshold(a, thr, thresh, 0.0, CV_THRESH_TOZERO);
tp = 0, fp = 0, fn = 0, tn = 0;
for (y = 0; y < h; y++) {
tdata = (uint8_t*)thr->imageData + y*stride;
gdata = (uint8_t*)gt->imageData + y*stride;
for (x = 0; x < w; x++) {
if (*gdata && *tdata) tp++;
else if (*gdata) fn++;
else if (*tdata) fp++;
else tn++;
gdata++;
tdata++;
}
}
}

static IplImage* resize(IplImage *img, CvSize sz)
{
IplImage *ret = cvCreateImage(sz, img->depth, img->nChannels);
cvResize(img, ret, CV_INTER_CUBIC);
return ret;
}

static void find_roc(IplImage *a, IplImage *gt)
{
int i, r = 0;
if (gt->width != a->width || gt->height != a->height) {
gt = resize(gt, cvGetSize(a));
r = 1;
}
for (i = 1; i < 255; i++) {
cmp_thresh(a, gt, i);
printf("%d: tp %d fp %d fn %d tn %d precision %f recall %f fpr %f\n",
i, tp, fp, fn, tn,
tp/(double)(tp+fp), tp/(double)(tp+fn),
fp/(double)(fp+tn));
}
if (r) cvReleaseImage(&gt);
}

static void print_args(int argc, char **argv)
{
int i;
printf("roc: ");
for (i = 1; i < argc; i++) printf("%s ", argv[i]);
printf("\n");
}

int main(int argc, char **argv)
{
if (argc < 3) print_usage(argv);
print_args(argc, argv);
IplImage *in = cvLoadImage(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
IplImage *gt = cvLoadImage(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
find_roc(in, gt);
cvReleaseImage(&in);
cvReleaseImage(&gt);
return 0;
}
63 changes: 63 additions & 0 deletions roc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function dataset1 {
prefix="/media/Grains/saliency/cvpr07supp"
imgp="$prefix/hMap/a1"
salp="$prefix/results-ftsrd"
imgs=`cd $imgp;ls *.jpg`
resp="$prefix/results"
smap="$prefix/sMap"
imap="$prefix/iMap"
for f in $imgs
do
i=`echo $f | grep -Eo "^\w+"`
#echo "ours $f"
#./a.out $imgp/$f $resp/$f > roc-res/dataset1/ours_$f.out
#echo "ftsrd $f"
#./a.out $imgp/$f $salp/$f > roc-res/dataset1/ftsrd_$f.out
#echo "sMap $f"
#./a.out $imgp/$f $smap/$f > roc-res/dataset1/smap_$f.out
echo "iMap $f"
./a.out $imgp/$f $imap/$f > roc-res/dataset1/imap_$f.out
done
}

function dataset2 {
prefix="/media/Grains/saliency/learning/achanta-dataset"
maskp="$prefix/binarymasks"
ftsrdp="$prefix/results-ftsrd"
imgs=`cd $maskp;ls *.bmp`
resp="$prefix/results-ours"
ours25="$prefix/results-ours-0.25"
ours75="$prefix/results-ours-0.75"
ours10="$prefix/results-ours-1.00"
smap="$prefix/results-smap"
imap="$prefix/results-imap"
kmap="$prefix/results-kmap"

imgs=`echo $imgs| sed 's/.bmp//g'`

for f in $imgs
do
i=`echo $f | grep -Eo "^\w+"`
#echo "ours-1.00 $f"
#./a.out $maskp/$f.bmp $ours10/$f.jpg > roc-res/dataset-1.00/ours_$f.out
echo "ours-0.75 $f"
./a.out $maskp/$f.bmp $ours75/$f.jpg > roc-res/dataset-0.75/ours_$f.out
#echo "ours-0.25 $f"
#./a.out $maskp/$f.bmp $ours25/$f.jpg > roc-res/dataset-0.25/ours_$f.out
#echo "ours $f"
#./a.out $maskp/$f.bmp $resp/$f.jpg > roc-res/dataset2/ours_$f.out
#echo "ftsrd $f"
#./a.out $maskp/$f.bmp $ftsrdp/$f.jpg > roc-res/dataset2/ftsrd_$f.out
#echo "sMap $f"
#./a.out $maskp/$f.bmp $smap/$f.jpg > roc-res/dataset2/smap_$f.out
#echo "kMap $f"
#./a.out $maskp/$f.bmp $kmap/$f.jpg > roc-res/dataset2/kmap_$f.out
#echo "iMap $f"
#./a.out $maskp/$f.bmp $imap/$f.jpg > roc-res/dataset2/imap_$f.out
done
}


#dataset1
dataset2
#`cd roc-res;./process.sh`
3 changes: 3 additions & 0 deletions sal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ r "6/6_187_187089.jpg" # shack
}

# from "saliency detection: a spectral residual approach", x. hou etal
#runsal "/media/Grains/saliency/learning/achanta-dataset/images" "/media/Grains/saliency/learning/achanta-dataset/results-ftsrd"
#runsal "/media/Grains/saliency/learning/achanta-dataset/images" "/media/Grains/saliency/learning/achanta-dataset/results-ours-1.00"
#runsal "/media/Grains/saliency/cvpr07supp/in" "/media/Grains/saliency/cvpr07supp/results"
#runsal "/media/Grains/saliency/cvpr07supp/in" "/media/Grains/saliency/cvpr07supp/results-ftsrd"
#runsal2 "/media/Grains/saliency/cvpr07supp/in"
#runsal2 "/media/Grains/saliency/learning/Image/6"
#runsal2 "/media/Grains/saliency/learning/Image/7"
Expand Down

0 comments on commit ef1f70d

Please sign in to comment.