[GRASS-SVN] r67505 - grass-addons/grass7/imagery/i.spec.sam

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 6 11:37:57 PST 2016


Author: ychemin
Date: 2016-01-06 11:37:57 -0800 (Wed, 06 Jan 2016)
New Revision: 67505

Modified:
   grass-addons/grass7/imagery/i.spec.sam/main.c
   grass-addons/grass7/imagery/i.spec.sam/open.c
Log:
modifying for non-square input matrix

Modified: grass-addons/grass7/imagery/i.spec.sam/main.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.sam/main.c	2016-01-06 18:28:08 UTC (rev 67504)
+++ grass-addons/grass7/imagery/i.spec.sam/main.c	2016-01-06 19:37:57 UTC (rev 67505)
@@ -67,7 +67,7 @@
     int row, col;
     int band;
     int i, j, error=0;
-    /*char command[80]; rm by Yann temporarily see grayscale palette*/
+    /*Assumes max 255 spectral signatures in input matrix*/
     float anglefield[255][255];
     struct
     {
@@ -111,9 +111,9 @@
     A = open_files(parm.matrixfile->answer, parm.group->answer);
     /* Spectral Matrix is stored in A now */
     G_message("Your incoming spectral signature matrix");
-    for (i=0; i<A->rows; i++)
+    for (i=0; i<A->cols; i++)
     {
-        for (j=0; j<A->cols; j++)
+        for (j=0; j<A->rows; j++)
         {
             G_message("%f ", A->vals[i*A->rows+j]);
         }
@@ -124,32 +124,31 @@
    *          using spectral unmixing and modeling spectral mixtrues with 
    *          TM data. Photogrammetric Engineering & Remote Sensing, Vol.63, No6.
    */
-    AT = open_files(parm.matrixfile->answer, parm.group->answer);
     G_message("/* Check matrix orthogonality*/"); 
-    for (i = 0; i < Ref.nfiles; i++) /* Ref.nfiles = matrixsize*/
+    for (i = 0; i < A->cols; i++) /* Number of spectral signatures in matrix input file*/
     {
-     Avector = G_matvect_get_column(AT, i);  /* go columnwise through matrix*/
+     Avector = G_matvect_get_column(A, i);  /* go columnwise through matrix*/
      G_message("Avector rows:%d cols:%d, vals %f %f %f %f",Avector->rows,Avector->cols, Avector->vals[0], Avector->vals[1],Avector->vals[2],Avector->vals[3]);
-     for (j = 0; j < Ref.nfiles ; j++)
-	{
-	 if (j !=i)
-	    {
-	     b = G_matvect_get_column(AT, j);      /* compare with next col in A */
+     for (j = 0; j < A->cols ; j++)/* Number of spectral signatures in matrix input file*/
+     {
+     if (j !=i)
+      {
+	     b = G_matvect_get_column(A, j);      /* compare with next col in A */
              G_message("b rows:%d cols:%d, vals %f %f %f %f",b->rows,b->cols,b->vals[0],b->vals[1],b->vals[2],b->vals[3]);
              G_message("process spectangle %d %d %d",i,j, Ref.nfiles);
 	     spectangle = spectral_angle(Avector, b, RVEC);
              G_message("processed spectangle");
 	     anglefield[i][j]= spectangle;
 	     G_vector_free(b);
-	    }
-	}
+      }
+     }
      G_vector_free(Avector);
     }
 
     /* print out the result */
-    G_message("Orthogonality check of Matrix A:\n");
-    for (i = 0; i < Ref.nfiles ; i++)
-      for (j = 0; j < Ref.nfiles ; j++)
+    G_message("Orthogonality check of input Matrix A:\n");
+    for (i = 0; i < A->cols ; i++)
+      for (j = 0; j < A->cols ; j++)
 	{
          if (j !=i)
          	G_message("  Angle between row %i and row %i: %g\n", (i+1), (j+1), anglefield[i][j]);
@@ -157,8 +156,8 @@
     G_message("\n");
     
    /* check it */
-   for (i = 0; i < Ref.nfiles ; i++)
-     for (j = 0; j < Ref.nfiles ; j++)
+   for (i = 0; i < A->cols ; i++)
+     for (j = 0; j < A->cols ; j++)
        if (j !=i)
          if (anglefield[i][j] < 10.0)
          {

Modified: grass-addons/grass7/imagery/i.spec.sam/open.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.sam/open.c	2016-01-06 18:28:08 UTC (rev 67504)
+++ grass-addons/grass7/imagery/i.spec.sam/open.c	2016-01-06 19:37:57 UTC (rev 67505)
@@ -36,26 +36,28 @@
     if (A == NULL)
         G_fatal_error(_("Unable to allocate memory for matrix"));
     A = G_matrix_transpose(&A_input);/*transposed for spec angle process*/
-    /*if(type==1){
-        A = G_matrix_copy(&A_input);*//*for matrix orthogonality check*/
-       /*return A;*/
-    /*}*/
-/*    if(A->rows < A->cols)
+    
+    /*A = G_matrix_copy(&A_input);*//*for matrix orthogonality check*/
+   
+    /*if(A->rows < A->cols)
 	G_fatal_error("Need m (rows) >= n (cols) to obtain least squares fit\n");*/
-    G_message("Your spectral matrix");
+    G_message("Your spectral matrix has %i rows and %i cols",A->rows,A->cols);
     int j;
-    for (i=0; i<A->rows; i++)
+    /*For each spectral signature*/
+    for (i=0; i<A->cols; i++)
     {
-        for (j=0; j<A->cols; j++)
+        G_message("Col #%i",i);
+        /*Display each value*/
+        for (j=0; j<A->rows; j++)
         {
-            G_message("%f ", A->vals[i*A->rows+j]);
+            G_message("Col #%i Row #%i %f",i,j,A->vals[i*A->cols+j]);
         }
         G_message("\n");
     }
     matrixsize=A->rows;
 
     G_message("/* open input files from group */");
-/* open input files from group */
+    /* open input files from group */
     if (!I_find_group(img_grp))
     {
 	G_fatal_error("group=%s - not found\n", img_grp);
@@ -70,15 +72,15 @@
 	    G_message("only has 1 file\n");
 	G_fatal_error("The group must have at least 2 files\n");
     }
-   /* Error check: input file number must be equal to matrix size */
+    /* Error check: input file number must be equal to matrix size */
     if (Ref.nfiles != matrixsize) 
     {
 	G_message("Error: Number of %i input files in group <%s>\n", Ref.nfiles, img_grp);
  	G_fatal_error("       does not match matrix size (%i cols).\n", A->cols);
     }
 
-   G_message("/* get memory for input files */");
-   /* get memory for input files */
+    G_message("/* get memory for input files */");
+    /* get memory for input files */
     cell = (DCELL **) G_malloc (Ref.nfiles * sizeof (DCELL *));
     cellfd = (int *) G_malloc (Ref.nfiles * sizeof (int));
     for (i=0; i < Ref.nfiles; i++)
@@ -92,7 +94,7 @@
     }
 
     G_message("/* open files for results*/");
-  /* open files for results*/
+    /* open files for results*/
     result_cell = (DCELL **) G_malloc (Ref.nfiles * sizeof (DCELL *));
     resultfd = (int *) G_malloc (Ref.nfiles * sizeof (int));
     for (i=0; i < Ref.nfiles; i++)



More information about the grass-commit mailing list