Commit 72ed1cd935a530f47282b00692159d678a730ec0

Authored by Ben Klein
1 parent b205c6b6

move some of the detection and landmarking code to plot_utils

docs/docs/api_docs/c_api/functions.md
@@ -587,7 +587,7 @@ Returns names and parameters for the requested objects. Each object is newline s @@ -587,7 +587,7 @@ Returns names and parameters for the requested objects. Each object is newline s
587 587
588 --- 588 ---
589 589
590 -## I 590 +## br_plot
591 591
592 Renders recognition performance figures for a set of **.csv** files created by [br_eval](#br_eval). 592 Renders recognition performance figures for a set of **.csv** files created by [br_eval](#br_eval).
593 593
openbr/core/plot.cpp
@@ -232,8 +232,8 @@ bool Plot(const QStringList &files, const File &destination, bool show) @@ -232,8 +232,8 @@ bool Plot(const QStringList &files, const File &destination, bool show)
232 p.file.write(qPrintable(QString(plot).arg("CMC", toRList(optMap["cmcOptions"]), "FALSE"))); 232 p.file.write(qPrintable(QString(plot).arg("CMC", toRList(optMap["cmcOptions"]), "FALSE")));
233 p.file.write("plot <- plotSD(sdData=SD)\nplot\n"); 233 p.file.write("plot <- plotSD(sdData=SD)\nplot\n");
234 p.file.write("plot <- plotBC(bcData=BC)\nplot\n"); 234 p.file.write("plot <- plotBC(bcData=BC)\nplot\n");
235 - p.file.write("plot <- plotERR(errData=ERR)\nplot\n\n");  
236 - p.file.write("plotEERSamples(imData=IM, gmData=GM"); 235 + p.file.write("plot <- plotERR(errData=ERR)\nplot\n");
  236 + p.file.write("plotEERSamples(imData=IM, gmData=GM)\n\n");
237 237
238 return p.finalize(show); 238 return p.finalize(show);
239 } 239 }
@@ -295,23 +295,19 @@ bool PlotDetection(const QStringList &amp;files, const File &amp;destination, bool show) @@ -295,23 +295,19 @@ bool PlotDetection(const QStringList &amp;files, const File &amp;destination, bool show)
295 QString plot = "plot <- plotLine(lineData=%1, options=list(%2), flipY=%3, geometry=%4)\nplot\n"; 295 QString plot = "plot <- plotLine(lineData=%1, options=list(%2), flipY=%3, geometry=%4)\nplot\n";
296 foreach (const QString &type, QStringList() << "Discrete" << "Continuous") { 296 foreach (const QString &type, QStringList() << "Discrete" << "Continuous") {
297 optMap["rocOptions"].set("title", type); 297 optMap["rocOptions"].set("title", type);
298 - p.file.write(qPrintable(QString(plot).arg(type + "ROC", toRList(optMap["rocOptions"]), "FALSE", plotType))); 298 + p.file.write(qPrintable(QString(plot).arg(type + "ROC", toRList(optMap["rocOptions"]), "FALSE", "\"" + plotType + "\"")));
299 } 299 }
300 300
301 foreach (const QString &type, QStringList() << "Discrete" << "Continuous") { 301 foreach (const QString &type, QStringList() << "Discrete" << "Continuous") {
302 optMap["prOptions"].set("title", type); 302 optMap["prOptions"].set("title", type);
303 - p.file.write(qPrintable(QString(plot).arg(type + "PR", toRList(optMap["prOptions"]), "FALSE", plotType))); 303 + p.file.write(qPrintable(QString(plot).arg(type + "PR", toRList(optMap["prOptions"]), "FALSE", "\"" + plotType + "\"")));
304 } 304 }
305 -  
306 - p.file.write(qPrintable(QString("qplot(X, data=Overlap, geom=\"histogram\", position=\"identity\", xlab=\"Overlap\", ylab=\"Frequency\")") +  
307 - QString(" + theme_minimal() + scale_x_continuous(minor_breaks=NULL) + scale_y_continuous(minor_breaks=NULL) + theme(axis.text.y=element_blank(), axis.ticks=element_blank(), axis.text.x=element_text(angle=-90, hjust=0))") +  
308 - (p.major.size > 1 ? (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ %1, scales=\"free\")").arg(p.minor.header, p.major.header) : QString(" + facet_wrap(~ %1, scales = \"free\")").arg(p.major.header)) : QString()) +  
309 - QString(" + theme(aspect.ratio=1, legend.position=\"bottom\")\n\n"))); 305 + p.file.write("plot <- plotOverlap(overlapData=Overlap)\nplot\n");
310 306
311 p.file.write(qPrintable(QString("ggplot(AverageOverlap, aes(x=%1, y=%2, label=round(X,3)), main=\"Average Overlap\") + geom_text() + theme_minimal()").arg(p.minor.size > 1 ? p.minor.header : "'X'", p.major.size > 1 ? p.major.header : "'Y'") + 307 p.file.write(qPrintable(QString("ggplot(AverageOverlap, aes(x=%1, y=%2, label=round(X,3)), main=\"Average Overlap\") + geom_text() + theme_minimal()").arg(p.minor.size > 1 ? p.minor.header : "'X'", p.major.size > 1 ? p.major.header : "'Y'") +
312 QString("%1%2\n\n").arg(p.minor.size > 1 ? "" : " + xlab(NULL)", p.major.size > 1 ? "" : " + ylab(NULL)"))); 308 QString("%1%2\n\n").arg(p.minor.size > 1 ? "" : " + xlab(NULL)", p.major.size > 1 ? "" : " + ylab(NULL)")));
313 309
314 - p.file.write(qPrintable(QString("ggplot(AverageOverlap, aes(x=%1, y=%2, fill=X)) + geom_tile() + scale_fill_continuous(\"Average Overlap\") + theme_minimal()").arg(p.minor.size > 1 ? p.minor.header : "'X'", p.major.size > 1 ? p.major.header : "'Y'") + 310 + p.file.write(qPrintable(QString("ggplot(AverageOverlap, aes(x=%1, y=%2, fill=X)) + geom_tile() + scale_fill_continuous(\"Average Overlap\", guide=FALSE) + theme_minimal()").arg(p.minor.size > 1 ? p.minor.header : "'X'", p.major.size > 1 ? p.major.header : "'Y'") +
315 QString("%1%2\n\n").arg(p.minor.size > 1 ? "" : " + xlab(NULL)", p.major.size > 1 ? "" : " + ylab(NULL)"))); 311 QString("%1%2\n\n").arg(p.minor.size > 1 ? "" : " + xlab(NULL)", p.major.size > 1 ? "" : " + ylab(NULL)")));
316 312
317 return p.finalize(show); 313 return p.finalize(show);
@@ -322,66 +318,10 @@ bool PlotLandmarking(const QStringList &amp;files, const File &amp;destination, bool sho @@ -322,66 +318,10 @@ bool PlotLandmarking(const QStringList &amp;files, const File &amp;destination, bool sho
322 qDebug("Plotting %d landmarking file(s) to %s", files.size(), qPrintable(destination)); 318 qDebug("Plotting %d landmarking file(s) to %s", files.size(), qPrintable(destination));
323 RPlot p(files, destination); 319 RPlot p(files, destination);
324 p.file.write("\nformatData(type=\"landmarking\")\n\n"); 320 p.file.write("\nformatData(type=\"landmarking\")\n\n");
325 -  
326 - p.file.write(qPrintable(QString("\nreadData <- function(data) {\n\texamples <- list()\n"  
327 - "\tfor (i in 1:nrow(data)) {\n"  
328 - "\t\tpath <- data[i,1]\n"  
329 - "\t\tvalue <- data[i,2]\n"  
330 - "\t\tfile <- unlist(strsplit(path, \"[.]\"))[1]\n"  
331 - "\t\text <- unlist(strsplit(path, \"[.]\"))[2]\n"  
332 - "\t\tif (ext == \"jpg\" || ext == \"JPEG\" || ext == \"jpeg\" || ext == \"JPG\") {\n"  
333 - "\t\t\timg <- readJPEG(path)\n"  
334 - "\t\t} else if (ext == \"PNG\" || ext == \"png\") {\n"  
335 - "\t\t\timg <- readPNG(path)\n"  
336 - "\t\t} else if (ext == \"TIFF\" || ext == \"tiff\" || ext == \"TIF\" || ext == \"tif\") { \n"  
337 - "\t\t\timg <- readTIFF(path)\n"  
338 - "}else {\n"  
339 - "\t\t\tnext\n"  
340 - "\t\t}\n"  
341 - "\t\texample <- list(file = file, value = value, image = img)\n"  
342 - "\t\texamples[[i]] <- example\n"  
343 - "\t}\n"  
344 - "\treturn(examples)\n"  
345 - "}\n")));  
346 -  
347 - p.file.write(qPrintable(QString("\nlibrary(jpeg)\n"  
348 - "library(png)\n"  
349 - "library(grid)\n")));  
350 -  
351 - p.file.write(qPrintable(QString("\nplotImage <- function(image, title=NULL, label=NULL) { \n"  
352 - "\tp <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(rasterGrob(image$image), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.title.y=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), line=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=title) + xlab(label)\n"  
353 - "\treturn(p)"  
354 - "}\n")));  
355 -  
356 - p.file.write(qPrintable(QString("\nsample <- readData(Sample) \n"  
357 - "rows <- sample[[1]]$value\n"  
358 - "algs <- unique(Box$%1)\n"  
359 - "algs <- algs[!duplicated(algs)]\n"  
360 - "print(plotImage(sample[[1]],\"Sample Landmarks\",sprintf(\"Total Landmarks: %s\",sample[[1]]$value))) \n"  
361 - "if (nrow(EXT) != 0 && nrow(EXP)) {\n"  
362 - "\tfor (j in 1:length(algs)) {\n"  
363 - "\ttruthSample <- readData(EXT[EXT$. == algs[[j]],])\n"  
364 - "\tpredictedSample <- readData(EXP[EXP$. == algs[[j]],])\n"  
365 - "\t\tfor (i in 1:length(predictedSample)) {\n"  
366 - "\t\t\tmultiplot(plotImage(predictedSample[[i]],sprintf(\"%s\\nPredicted Landmarks\",algs[[j]]),sprintf(\"Average Landmark Error: %.3f\",predictedSample[[i]]$value)),plotImage(truthSample[[i]],\"Ground Truth\\nLandmarks\",\"\"),cols=2)\n"  
367 - "\t\t}\n"  
368 - "\t}\n"  
369 - "}\n").arg(p.major.size > 1 ? p.major.header : (p.minor.header.isEmpty() ? p.major.header : p.minor.header))));  
370 -  
371 - p.file.write(qPrintable(QString("\n"  
372 - "# Code to format error table\n"  
373 - "StatBox <- summarySE(Box, measurevar=\"Y\", groupvars=c(\"%1\",\"X\"))\n"  
374 - "OverallStatBox <- summarySE(Box, measurevar=\"Y\", groupvars=c(\"%1\"))\n"  
375 - "mat <- matrix(paste(as.character(round(StatBox$Y, 3)), round(StatBox$ci, 3), sep=\" \\u00b1 \"),nrow=rows,ncol=length(algs),byrow=FALSE)\n"  
376 - "mat <- rbind(mat, paste(as.character(round(OverallStatBox$Y, 3)), round(OverallStatBox$ci, 3), sep=\" \\u00b1 \"))\n"  
377 - "mat <- rbind(mat, as.character(round(NormLength$Y, 3)))\n"  
378 - "colnames(mat) <- algs\n"  
379 - "rownames(mat) <- c(seq(0,rows-1),\"Aggregate\",\"Average IPD\")\n"  
380 - "ETable <- as.table(mat)\n").arg(p.major.size > 1 ? p.major.header : (p.minor.header.isEmpty() ? p.major.header : p.minor.header))));  
381 -  
382 - p.file.write(qPrintable(QString("\n"  
383 - "print(textplot(ETable))\n"  
384 - "print(title(\"Landmarking Error Rates\"))\n"))); 321 + p.file.write(qPrintable(QString("algs <- uniqueBox$%1)\n").arg(p.major.size > 1 ? p.major.header : (p.minor.header.isEmpty() ? p.major.header : p.minor.header))));
  322 + p.file.write("algs <- algs[!duplicated(algs)]\n");
  323 + p.file.write("plotLandmarkSamples(samples=sample, expData=EXP, extData=EXT)\n");
  324 + p.file.write("plotLandmarkTables(tableData=Box)\n");
385 325
386 p.file.write(qPrintable(QString("ggplot(Box, aes(Y,%1%2))").arg(p.major.size > 1 ? QString(", colour=%1").arg(p.major.header) : QString(), 326 p.file.write(qPrintable(QString("ggplot(Box, aes(Y,%1%2))").arg(p.major.size > 1 ? QString(", colour=%1").arg(p.major.header) : QString(),
387 p.minor.size > 1 ? QString(", linetype=%1").arg(p.minor.header) : QString()) + 327 p.minor.size > 1 ? QString(", linetype=%1").arg(p.minor.header) : QString()) +
share/openbr/plotting/plot_utils.R
@@ -3,6 +3,9 @@ library(&quot;ggplot2&quot;) @@ -3,6 +3,9 @@ library(&quot;ggplot2&quot;)
3 library("gplots") 3 library("gplots")
4 library("reshape") 4 library("reshape")
5 library("scales") 5 library("scales")
  6 +library("jpeg")
  7 +library("png")
  8 +library("grid")
6 9
7 # Code to format FAR values 10 # Code to format FAR values
8 far_names <- list('0.001'="FAR = 0.1%", '0.01'="FAR = 1%") 11 far_names <- list('0.001'="FAR = 0.1%", '0.01'="FAR = 1%")
@@ -53,6 +56,24 @@ plotTable &lt;- function(tableData=NULL, name=NULL, labels=NULL) { @@ -53,6 +56,24 @@ plotTable &lt;- function(tableData=NULL, name=NULL, labels=NULL) {
53 } 56 }
54 } 57 }
55 58
  59 +plotLandmarkTables <- function(tableData=NULL) {
  60 + if(majorSize > 1) {
  61 + var <- majorHeader
  62 + } else {
  63 + if(minorHeader == "") var <- majorHeader else var <- minorHeader
  64 + }
  65 + StatBox <- summarySE(tableData, measurevar="Y", groupvars=c(var,"X"))
  66 + OverallStatBox <- summarySE(tableData, measurevar="Y", groupvars=c(var))
  67 + mat <- matrix(paste(as.character(round(StatBox$Y, 3)), round(StatBox$ci, 3), sep=" \u00b1 "), nrow=rows, ncol=length(algs), byrow=FALSE)
  68 + mat <- rbind(mat, paste(as.character(round(OverallStatBox$Y, 3)), round(OverallStatBox$ci, 3), sep=" \u00b1 "))
  69 + mat <- rbind(mat, as.character(round(NormLength$Y, 3)))
  70 + colnames(mat) <- algs
  71 + rownames(mat) <- c(seq(0, rows-1), "Aggregate","Average IPD")
  72 + ETable <- as.table(mat)
  73 + print(textplot(ETable))
  74 + print(title("Landmarking Error Rates"))
  75 +}
  76 +
56 plotLine <- function(lineData=NULL, options=NULL, flipY=FALSE, geometry="line") { 77 plotLine <- function(lineData=NULL, options=NULL, flipY=FALSE, geometry="line") {
57 textSize <- if("textSize" %in% names(options)) as.numeric(options$textSize) else 12 78 textSize <- if("textSize" %in% names(options)) as.numeric(options$textSize) else 12
58 p <- qplot(X, if(flipY) 1-Y else Y, data=lineData, main=options$title, geom=geometry, size=if("size" %in% names(options)) I(as.numeric(options$size)) else I(.5), colour=if(majorSize > 1) factor(eval(parse(text=majorHeader))) else NULL, linetype=if(minorSize > 1) factor(eval(parse(text=minorHeader))) else NULL, xlab=options$xTitle, ylab=options$yTitle) + theme_minimal() 79 p <- qplot(X, if(flipY) 1-Y else Y, data=lineData, main=options$title, geom=geometry, size=if("size" %in% names(options)) I(as.numeric(options$size)) else I(.5), colour=if(majorSize > 1) factor(eval(parse(text=majorHeader))) else NULL, linetype=if(minorSize > 1) factor(eval(parse(text=minorHeader))) else NULL, xlab=options$xTitle, ylab=options$yTitle) + theme_minimal()
@@ -138,6 +159,20 @@ plotERR &lt;- function(errData=NULL) { @@ -138,6 +159,20 @@ plotERR &lt;- function(errData=NULL) {
138 return(p) 159 return(p)
139 } 160 }
140 161
  162 +plotOverlap <- function(overlapData=NULL) {
  163 + p <- qplot(X, data=overlapData, geom="histogram", position="identity", xlab="Overlap", ylab="Frequency")
  164 + p <- p + theme_minimal() + scale_x_continuous(minor_breaks=NULL) + scale_y_continuous(minor_breaks=NULL) + theme(axis.text.y=element_blank(), axis.ticks=element_blank(), axis.text.x=element_text(angle=-90, hjust=0))
  165 + if(majorSize > 1) {
  166 + if(minorSize) {
  167 + p <- p + facet_grid(facets=as.formula(paste(minorHeader, "~", majorHeader)), scales="free")
  168 + } else {
  169 + p <- p + facet_wrap(facets=as.formula(paste("~", majorHeader)), scales="free")
  170 + }
  171 + }
  172 + p <- p + theme(aspect.ratio=1, legend.position="bottom")
  173 + return(p)
  174 +}
  175 +
141 formatData <- function(type="eval") { 176 formatData <- function(type="eval") {
142 if (type == "eval") { 177 if (type == "eval") {
143 # Split data into individual plots 178 # Split data into individual plots
@@ -182,7 +217,6 @@ formatData &lt;- function(type=&quot;eval&quot;) { @@ -182,7 +217,6 @@ formatData &lt;- function(type=&quot;eval&quot;) {
182 ContinuousPR <<- data[grep("ContinuousPR",data$Plot),-c(1)] 217 ContinuousPR <<- data[grep("ContinuousPR",data$Plot),-c(1)]
183 Overlap <<- data[grep("Overlap",data$Plot),-c(1)] 218 Overlap <<- data[grep("Overlap",data$Plot),-c(1)]
184 AverageOverlap <<- data[grep("AverageOverlap",data$Plot),-c(1)] 219 AverageOverlap <<- data[grep("AverageOverlap",data$Plot),-c(1)]
185 -  
186 } else if (type == "landmarking") { 220 } else if (type == "landmarking") {
187 # Split data into individual plots 221 # Split data into individual plots
188 Box <<- data[grep("Box",data$Plot),-c(1)] 222 Box <<- data[grep("Box",data$Plot),-c(1)]
@@ -194,10 +228,13 @@ formatData &lt;- function(type=&quot;eval&quot;) { @@ -194,10 +228,13 @@ formatData &lt;- function(type=&quot;eval&quot;) {
194 EXP <<- data[grep("EXP",data$Plot),-c(1)] 228 EXP <<- data[grep("EXP",data$Plot),-c(1)]
195 EXP$X <<- as.character(EXP$X) 229 EXP$X <<- as.character(EXP$X)
196 NormLength <<- data[grep("NormLength",data$Plot),-c(1)] 230 NormLength <<- data[grep("NormLength",data$Plot),-c(1)]
  231 + sample <<- readImageData(Sample)
  232 + rows <<- sample[[1]]$value
197 } 233 }
198 } 234 }
199 235
200 summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE, conf.interval=0.95, .drop=TRUE) { 236 summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE, conf.interval=0.95, .drop=TRUE) {
  237 + # derived from http://www.cookbook-r.com/Manipulating_data/Summarizing_data/
201 require(plyr) 238 require(plyr)
202 239
203 length2 <- function (x, na.rm=FALSE) { 240 length2 <- function (x, na.rm=FALSE) {
@@ -246,85 +283,88 @@ multiplot &lt;- function(..., plotlist=NULL, cols) { @@ -246,85 +283,88 @@ multiplot &lt;- function(..., plotlist=NULL, cols) {
246 plotEERSamples <- function(imData=NULL, gmData=NULL) { 283 plotEERSamples <- function(imData=NULL, gmData=NULL) {
247 if(nrow(imData) == 0) return() 284 if(nrow(imData) == 0) return()
248 285
249 - library(jpeg)  
250 - library(png)  
251 - library(grid)  
252 -  
253 - for (i in 1:nrow(imData)) {  
254 - score <- imData[i,1]  
255 - files <- imData[i,2]  
256 - alg <- imData[i,3]  
257 - files <- unlist(strsplit(files, "[:]"))  
258 -  
259 - ext1 <- unlist(strsplit(files[2], "[.]"))[2]  
260 - ext2 <- unlist(strsplit(files[4], "[.]"))[2]  
261 - if (ext1 == "jpg" || ext1 == "JPEG" || ext1 == "jpeg" || ext1 == "JPG") {  
262 - img1 <- readJPEG(files[2])  
263 - } else if (ext1 == "PNG" || ext1 == "png") {  
264 - img1 <- readPNG(files[2])  
265 - } else if (ext1 == "TIFF" || ext1 == "tiff" || ext1 == "TIF" || ext1 == "tif") {  
266 - img1 <- readTIFF(files[2])  
267 - } else {  
268 - next  
269 - }  
270 - if (ext2 == "jpg" || ext2 == "JPEG" || ext2 == "jpeg" || ext2 == "JPG") {  
271 - img2 <- readJPEG(files[4])  
272 - } else if (ext2 == "PNG" || ext2 == "png") {  
273 - img2 <- readPNG(files[4])  
274 - } else if (ext2 == "TIFF" || ext2 == "tiff" || ext2 == "TIF" || ext2 == "tif") {  
275 - img2 <- readTIFF(files[4])  
276 - } else {  
277 - next  
278 - }  
279 - name1 <- files[1]  
280 - name2 <- files[3] 286 + printImages <- function(images, label) {
  287 + for (i in 1:nrow(images)) {
  288 + score <- images[i,1]
  289 + files <- images[i,2]
  290 + alg <- images[i,3]
  291 + files <- unlist(strsplit(files, "[:]"))
  292 +
  293 + ext1 <- unlist(strsplit(files[2], "[.]"))[2]
  294 + ext2 <- unlist(strsplit(files[4], "[.]"))[2]
  295 + if (ext1 == "jpg" || ext1 == "JPEG" || ext1 == "jpeg" || ext1 == "JPG") {
  296 + img1 <- readJPEG(files[2])
  297 + } else if (ext1 == "PNG" || ext1 == "png") {
  298 + img1 <- readPNG(files[2])
  299 + } else if (ext1 == "TIFF" || ext1 == "tiff" || ext1 == "TIF" || ext1 == "tif") {
  300 + img1 <- readTIFF(files[2])
  301 + } else {
  302 + next
  303 + }
  304 + if (ext2 == "jpg" || ext2 == "JPEG" || ext2 == "jpeg" || ext2 == "JPG") {
  305 + img2 <- readJPEG(files[4])
  306 + } else if (ext2 == "PNG" || ext2 == "png") {
  307 + img2 <- readPNG(files[4])
  308 + } else if (ext2 == "TIFF" || ext2 == "tiff" || ext2 == "TIF" || ext2 == "tif") {
  309 + img2 <- readTIFF(files[4])
  310 + } else {
  311 + next
  312 + }
  313 + name1 <- files[1]
  314 + name2 <- files[3]
281 315
282 - g1 <- rasterGrob(img1, interpolate=TRUE)  
283 - g2 <- rasterGrob(img2, interpolate=TRUE) 316 + g1 <- rasterGrob(img1, interpolate=TRUE)
  317 + g2 <- rasterGrob(img2, interpolate=TRUE)
284 318
285 - plot1 <- qplot(1:10, 1:10, geom="blank") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(unlist(strsplit(files[2], "[/]"))[length(unlist(strsplit(files[2], "[/]")))]) + xlab(name1)  
286 - plot2 <- qplot(1:10, 1:10, geom="blank") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste("Impostor score =", score)) + ylab(unlist(strsplit(files[4], "[/]"))[length(unlist(strsplit(files[4], "[/]")))]) + xlab(name2) 319 + plot1 <- qplot(1:10, 1:10, geom="blank") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(unlist(strsplit(files[2], "[/]"))[length(unlist(strsplit(files[2], "[/]")))]) + xlab(name1)
  320 + plot2 <- qplot(1:10, 1:10, geom="blank") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste(label, " score =", score)) + ylab(unlist(strsplit(files[4], "[/]"))[length(unlist(strsplit(files[4], "[/]")))]) + xlab(name2)
287 321
288 - multiplot(plot1, plot2, cols=2) 322 + multiplot(plot1, plot2, cols=2)
  323 + }
289 } 324 }
  325 + printImages(imData, "Impostor")
  326 + printImages(gmData, "Genuine")
  327 +}
290 328
291 - # Print genuine matches below the EER  
292 - for (i in 1:nrow(gmData)) {  
293 - score <- gmData[i,1]  
294 - files <- gmData[i,2]  
295 - alg <- gmData[i,3]  
296 - files <- unlist(strsplit(files, "[:]"))  
297 -  
298 - ext1 <- unlist(strsplit(files[2], "[.]"))[2]  
299 - ext2 <- unlist(strsplit(files[4], "[.]"))[2]  
300 - if (ext1 == "jpg" || ext1 == "JPEG" || ext1 == "jpeg" || ext1 == "JPG") {  
301 - img1 <- readJPEG(files[2])  
302 - } else if (ext1 == "PNG" || ext1 == "png") {  
303 - img1 <- readPNG(files[2])  
304 - } else if (ext1 == "TIFF" || ext1 == "tiff" || ext1 == "TIF" || ext1 == "tif") {  
305 - img1 <- readTIFF(files[2])  
306 - } else {  
307 - next 329 +plotLandmarkSamples <- function(samples=NULL, expData=NULL, extData=NULL) {
  330 + print(plotImage(samples[[1]], "Sample Landmarks", sprintf("Total Landmarks: %s", samples[[1]]$value)))
  331 + if (nrow(EXT) != 0 && nrow(EXP)) {
  332 + for (j in 1:length(algs)) {
  333 + truthSample <- readData(EXT[EXT$. == algs[[j]],])
  334 + predictedSample <- readData(EXP[EXP$. == algs[[j]],])
  335 + for (i in 1:length(predictedSample)) {
  336 + multiplot(plotImage(predictedSample[[i]], sprintf("%s\nPredicted Landmarks", algs[[j]]), sprintf("Average Landmark Error: %.3f", predictedSample[[i]]$value)), plotImage(truthSample[[i]], "Ground Truth\nLandmarks", ""), cols=2)
  337 + }
308 } 338 }
309 - if (ext2 == "jpg" || ext2 == "JPEG" || ext2 == "jpeg" || ext2 == "JPG") {  
310 - img2 <- readJPEG(files[4])  
311 - } else if (ext2 == "PNG" || ext2 == "png") {  
312 - img2 <- readPNG(files[4])  
313 - } else if (ext2 == "TIFF" || ext2 == "tiff" || ext2 == "TIF" || ext2 == "tif") {  
314 - img2 <- readTIFF(files[4])  
315 - } else { 339 + }
  340 +}
  341 +
  342 +readImageData <- function(data) {
  343 + examples <- list()
  344 + for (i in 1:nrow(data)) {
  345 + path <- data[i,1]
  346 + value <- data[i,2]
  347 + file <- unlist(strsplit(path, "[.]"))[1]
  348 + ext <- unlist(strsplit(path, "[.]"))[2]
  349 + if (ext == "jpg" || ext == "JPEG" || ext == "jpeg" || ext == "JPG") {
  350 + img <- readJPEG(path)
  351 + } else if (ext == "PNG" || ext == "png") {
  352 + img <- readPNG(path)
  353 + } else if (ext == "TIFF" || ext == "tiff" || ext == "TIF" || ext == "tif") {
  354 + img <- readTIFF(path)
  355 + }else {
316 next 356 next
317 } 357 }
318 - name1 <- files[1]  
319 - name2 <- files[3]  
320 -  
321 - g1 <- rasterGrob(img1, interpolate=TRUE)  
322 - g2 <- rasterGrob(img2, interpolate=TRUE)  
323 -  
324 - plot1 <- qplot(1:10, 1:10, geom="blank") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(unlist(strsplit(files[2], "[/]"))[length(unlist(strsplit(files[2], "[/]")))]) + xlab(name1)  
325 - plot2 <- qplot(1:10, 1:10, geom="blank") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste("Genuine score =", score)) + ylab(unlist(strsplit(files[4], "[/]"))[length(unlist(strsplit(files[4], "[/]")))]) + xlab(name2)  
326 -  
327 - multiplot(plot1, plot2, cols=2) 358 + example <- list(file = file, value = value, image = img)
  359 + examples[[i]] <- example
328 } 360 }
  361 + return(examples)
  362 +}
329 363
  364 +plotImage <- function(image, title=NULL, label=NULL) {
  365 + p <- qplot(1:10, 1:10, geom="blank") + annotation_custom(rasterGrob(image$image), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
  366 + p <- p + theme(axis.line=element_blank(), axis.title.y=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), line=element_blank(), axis.ticks=element_blank(), panel.background=element_blank())
  367 + p <- p + labs(title=title) + xlab(label)
  368 + return(p)
330 } 369 }
  370 +