[Zooimage-commits] r156 - in pkg/zooimage: R inst/gui

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 27 11:24:40 CEST 2009


Author: kevin
Date: 2009-05-27 11:24:40 +0200 (Wed, 27 May 2009)
New Revision: 156

Modified:
   pkg/zooimage/R/gui.r
   pkg/zooimage/R/zid.r
   pkg/zooimage/inst/gui/MenusZIDlgWin.txt
Log:
Add functions and option to classify vignettes from zid files according to their automatic classification

Modified: pkg/zooimage/R/gui.r
===================================================================
--- pkg/zooimage/R/gui.r	2009-05-27 08:14:31 UTC (rev 155)
+++ pkg/zooimage/R/gui.r	2009-05-27 09:24:40 UTC (rev 156)
@@ -1467,3 +1467,21 @@
   # Extract vignettes in the training set in New_Vign_X directory
   Add.Vign(zidfiles = zid, train = dir)  
 }
+
+ClassifVigns <- function(){
+  # Extract on zid to respective directories
+  zid <- selectFile(type = "Zid", multi = TRUE, quote = FALSE) # select zid you want to recognize and classify
+  # Look if we have a classifier object defined
+  ZIC <- getTemp("ZI.ClassName")
+  if (is.null(ZIC)) ZIC <- ""
+  ZIC <- getVar("ZIClass", multi = FALSE, default = ZIC,
+    title = "Choose a classifier (ZIClass object):", warn.only = FALSE)
+  if (length(ZIC) == 0 || (length(ZIC) == 1 && ZIC == "")) return(invisible())
+  ZICobj <- get(ZIC, envir = .GlobalEnv)
+  # Classify vignettes  
+  if(length(zid) > 1) {
+    classifVign.all(zidfiles = zid, Zic = ZICobj)
+  } else {
+    classifVign(zidfile = zid, Zic = ZICobj)
+  }
+}

Modified: pkg/zooimage/R/zid.r
===================================================================
--- pkg/zooimage/R/zid.r	2009-05-27 08:14:31 UTC (rev 155)
+++ pkg/zooimage/R/zid.r	2009-05-27 09:24:40 UTC (rev 156)
@@ -614,3 +614,49 @@
 
 # :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1:
 
+# Functions to classify vignettes according to automatic classification
+classifVign <- function(zidfile, Zic, log = TRUE){
+  Zid <- read.zid(zidfile)
+  # Recognition of the zid file
+  Rec <- predict(Zic, Zid)
+  Gp <- unique(Rec$Ident)
+  # Create path for new directories
+  if(!is.null(attr(Zic, "path"))){
+    # There is a 'path' attribute associated with the classifer
+    GpDir <- file.path(dirname(zidfile), "Auto_Classification", attr(Zic, "path"))
+  } else {
+    # only create classifier without taxonomic relationship
+    GpDir <- file.path(dirname(zidfile), "Auto_Classification", unique(Rec$Ident))
+  }
+  # Create directories for new groups on harddisk
+  for(i in 1 : length(GpDir)){
+    if(!file.exists(GpDir)[i]){
+      dir.create(GpDir[i], showWarnings = TRUE, recursive = TRUE)
+    }
+  }
+  # Extract Vignettes
+  uncompress.zid(zidfile)
+  # Copy vignettes from zidfile directory to group directories
+  Rec$Vign <- make.Id(Rec)
+  for(i in 1:nrow(Rec)){
+     From <- file.path(file.path(dirname(zidfile), noext(zidfile)), paste(Rec$Vign[i], "jpg", sep = "."))
+     To <- file.path(GpDir[grep(as.character(Rec$Ident[i]), GpDir)], paste(Rec$Vign[i], "jpg", sep = "."))
+     file.copy(from = From, to = To, overwrite = FALSE)
+     file.remove(From)
+  }
+  # Remove directory
+  unlink(file.path(dirname(zidfile), noext(zidfile)), recursive = TRUE)
+  if(log){
+    print("Your vignettes have been exported into groups in the zid directory")
+  }
+}
+
+classifVign.all <- function(zidfiles, Zic, log = TRUE){
+  for(i in 1 : length(zidfiles)){
+    classifVign(zidfile = zidfiles[i], Zic = Zic, log = FALSE)  
+    if(log){
+      print(paste("zid file", i, "has been extracted" , sep = " "))
+    }
+  }
+  print(paste("Your", length(zidfiles), "zid files", "have been exported into groups in the zid directory" , sep = " "))
+}

Modified: pkg/zooimage/inst/gui/MenusZIDlgWin.txt
===================================================================
--- pkg/zooimage/inst/gui/MenusZIDlgWin.txt	2009-05-27 08:14:31 UTC (rev 155)
+++ pkg/zooimage/inst/gui/MenusZIDlgWin.txt	2009-05-27 09:24:40 UTC (rev 156)
@@ -109,6 +109,7 @@
 ||Calibrate grayscale (16bit)			~~ calib()
 ||Biomass conversion specification      ~~ startPgm("ZIEditor", cmdline = file.path(getTemp("ZIetc"), "Conversion.txt"))
 ||Add new vignettes to training set         ~~ AddVignToTrain()
+||Automatic classification of vignettes     ~~ ClassifVigns()
 ||-
 ||$R Graphs
 |||&New									~~ windows()



More information about the Zooimage-commits mailing list