[Camino-users] Connectivity Mapping with Camino

Ian Malone i.malone at ucl.ac.uk
Tue Oct 11 03:20:41 PDT 2011


Hi,

Two people asking about this on the same day? I came up with a patch for 
it recently, but haven't tested it thoroughly enough yet, principally in 
case it breaks anything else. The problem is that the ROI handling the 
connectivity mapping uses does not deal with non-sequential region 
numbering, I'm attaching my patch, but perhaps one of the Camino authors 
could look over it to see whether it's likely to break anything.

It also adds the following options:
-nopng : don't bother doing png output/displaying map
-outmat : out text matrix name
-outpng : out png name

Gavin Winston wrote:
> I am trying to use Camino release 1011 to produce connectivity maps as 
> per the tutorial.  However the conmap stage crashes with the following 
> error message:
>
> > conmap -inputfile probab/track.Bdouble -roifile dti/dti_wmparc.nii.gz
>
> (I have changed to code so the boolean silent is false to give more 
> output)
>
> 11-Oct-2011 10:48:54 apps.ConnectivityMapping main
> INFO: yay! Found Seed file
> regions:177
>  3011,  1011,  4025,  2025,  2029,  4029,  5002,  5001,  3004,  251, 
> 4004,  3025,  3021,  1025,  2005,  4005,  4021,  4011,  4013,  43, 
> 1021,  47,  8,  7,  16,  46,  15,  14,  49,  63,  60,  4031,  4022, 
> 4024,  4018,  4003,  54,  4030,  4007,  4009,  28,  12,  13,  10,  17, 
> 1016,  85,  2024,  52,  2017,  4017,  4028,  1024,  3024,  24,  1000, 
> 3034,  51,  4027,  4020,  2027,  2020,  1012,  1030,  1033,  3033, 
> 3007,  3030,  3017,  3028,  1028,  1017,  3010,  1010,  2010,  1013, 
> 1007,  1009,  4015,  2015,  1015,  2007,  2006,  4006,  2009,  2033, 
> 4033,  18,  26,  1014,  2000,  3029,  1029,  50,  4012,  3006,  2013, 
> 3023,  4008,  53,  3009,  3008,  2011,  31,  5,  11,  3016,  3012, 
> 3020,  3027,  1020,  3015,  2030,  2019,  3013,  3001,  4010,  3005, 
> 1027,  3019,  1019,  4016,  4,  1006,  1022,  3022,  2028,  2022,  
> 2018,  44,  2012,  1005,  2021,  4032,  2032,  3014,  3032,  1032,  
> 3031, 2003,  2016,  4034,  2008,  4023,  253,  3002,  4002,  2002,  
> 254, 3018,  2014,  4014,  58,  2031,  4019,  3003,  252,  1023,  
> 4026,  255,  3026,  1034,  1004,  1008,  2026,  4001,  1002,  2004,  
> 2023,  1031, 1001,  1026,  1018,  2001,  1003,  2034,  72, Total no of 
> tracts: 664234 connected tracts:5867811
> Exception in thread "main" java.lang.IllegalArgumentException: ROI 
> index out of bounds. This ROI contains 177 regions
>         at tractography.FreeFormROI.getRegion(FreeFormROI.java:345)
>         at apps.ConnectivityMapping.main(ConnectivityMapping.java:239)
>
>
> At line 239 of ConnectivityMapping (FreeFormROI)allROIs.getRegion is 
> called with the parameter 3007 which is greater than numberOfRegions 
> which is 177, hence the error
>
> Line 239
> > FreeFormROI fr = 
> (FreeFormROI)allROIs.getRegion(roiIntensities.get(i)- 
> allRoiIntensities.get(0));
>
> When i = 0, roiIntensities.get(i) returns 3011, 
> allRoiIntensities.get(0) returns 4
>
> Is there a bug here or am I doing something wrong?
>
>
> Many thanks
>
> Gavin
>
> P.S. The conmap wrapper has hard-coded paths unlike the other wrappers
> _______________________________________________
> Camino-users mailing list
> Camino-users at www.nitrc.org
> http://www.nitrc.org/mailman/listinfo/camino-users
>

-------------- next part --------------
Index: apps/ConnectivityMapping.java
===================================================================
--- apps/ConnectivityMapping.java	(revision 1011)
+++ apps/ConnectivityMapping.java	(working copy)
@@ -65,6 +65,9 @@
     	String indexLabelFile = null;
     	String indexFile = null;
     	String threshold = null;
+	boolean doPng = true;
+	String matrixName="ConnectionMatrix.txt";
+	String pngName="Connectivity.png";
     	
     	for (int i = 0; i < args.length; i++) {
 
@@ -84,6 +87,18 @@
     	    	threshold = args[i + 1];
             	CL_Initializer.markAsParsed(i, 2);
     	    }
+    	    if (args[i].equals("-outmat")) { 
+    	    	matrixName = args[i + 1];
+            	CL_Initializer.markAsParsed(i, 2);
+    	    }
+    	    if (args[i].equals("-outpng")) { 
+    	    	pngName = args[i + 1];
+            	CL_Initializer.markAsParsed(i, 2);
+    	    }
+    	    if (args[i].equals("-nopng")) { 
+    	    	doPng = false;
+            	CL_Initializer.markAsParsed(i, 1);
+    	    }
     	}
     	
     	CL_Initializer.checkParsing(args);
@@ -213,7 +228,7 @@
 	    		if (!silent)
 	    			System.err.println("Total no of tracts: "+ tc.numberOfTracts() +
 	    				" connected tracts:"+ edgeList.size());
-	    			    		    			
+			    		    			
     	    	//Calculate the length and weight of the edges
     	    	if (edgeList.size() > 0)
     	    	{
@@ -232,11 +247,14 @@
     				
     				Collections.sort(allRoiIntensities);
     				
+
+				System.out.println("all intensities size "+ allRoiIntensities.size() + " roiintensities size " + roiIntensities.size());
     				for(int i=0; i < roiIntensities.size(); i++)
     				{
     					//Subtract from minimum intensity. Refer FreeFormROI.java
-    					FreeFormROI fr = (FreeFormROI)allROIs.getRegion(
-    							roiIntensities.get(i)- allRoiIntensities.get(0));
+				    //    					FreeFormROI fr = (FreeFormROI)allROIs.getRegion(
+				    //    							roiIntensities.get(i)- allRoiIntensities.get(0));
+    					FreeFormROI fr = (FreeFormROI)allROIs.getRegion(roiIntensities.get(i));
     					
     					Voxel[] pts = fr.getVoxels();
     					if (pts.length > 0)
@@ -285,10 +303,10 @@
     					System.err.println("threshold:"+ thres);
     		    	Graph bg = new Graph(roiIntensities, verticesX, verticesY, 
     		    			computedEdges, indexLabelMap, nodeStrength, thres);
-    		    	bg.drawGraph();
+    		    	if (doPng) bg.drawGraph(pngName);
     		    	
     	    		writeConnectionMatrix(roiIntensities, computedEdges, 
-    	    				indexLabelMap);
+    	    				indexLabelMap, matrixName);
     	    	}
     	    	
     		}
@@ -474,10 +492,11 @@
      */
     public static void writeConnectionMatrix(ArrayList<Integer> roiIntensities, 
     		ArrayList<Edge> connectedEdges,
-    		HashMap<Integer, String> indexLabelMap)    	
+    		HashMap<Integer, String> indexLabelMap,
+					     String matrixName)    	
     throws IOException
     {	
-    	FileOutputStream fout = new FileOutputStream("ConnectionMatrix.txt");
+    	FileOutputStream fout = new FileOutputStream(matrixName);
     	DataOutputStream dout = new DataOutputStream
 	    	(new BufferedOutputStream(fout, 1024*1024*16));
     	
@@ -557,4 +576,4 @@
     } 
     
     
-}
\ No newline at end of file
+}
Index: tractography/Graph.java
===================================================================
--- tractography/Graph.java	(revision 1011)
+++ tractography/Graph.java	(working copy)
@@ -47,7 +47,7 @@
 		threshold = aThreshold;
 	}
 	
-	public void drawGraph()
+	public void drawGraph(String pngName)
 	{
 		BufferedImage image = new BufferedImage(FRAMEDIMENSION,FRAMEDIMENSION,BufferedImage.TYPE_INT_RGB);
 		
@@ -134,7 +134,7 @@
      	}
  		try {
  			System.err.println("Written");
-			ImageIO.write( image, "PNG", new File( "Connectivity.png" ));
+			ImageIO.write( image, "PNG", new File( pngName ));
 		} 
  		catch (IOException e) {
 			// TODO Auto-generated catch block
@@ -142,10 +142,10 @@
 		}
  		
  		JLabel jlabel=new JLabel(new ImageIcon(image));
- 		JFrame frame = new JFrame("Connectivity Mapping");
+ 		JFrame frame = new JFrame(pngName);
     	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     	frame.getContentPane().add(jlabel);
     	frame.pack();
     	frame.setVisible(true);
 	}
-}
\ No newline at end of file
+}
Index: tractography/FreeFormROI.java
===================================================================
--- tractography/FreeFormROI.java	(revision 1011)
+++ tractography/FreeFormROI.java	(working copy)
@@ -2,8 +2,9 @@
 
 import numerics.Point3D;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
-
 /**
  * A free form voxel-based ROI for tractography. The ROI consists of labelled regions.
  * The regions are labelled as integers from 1 upwards. 
@@ -338,9 +339,23 @@
      */
     public RegionOfInterest getRegion(int index) {
 	
-	if (index >= 0 && index < numberOfRegions) { 
-	    return new FreeFormROI(data, (short)(regionLabels[index]), xVoxelDim, yVoxelDim, zVoxelDim);
+	// No indexOf on arrays, no asList for primitives:
+	int regionindex=-1;
+	for (int ii=0 ; ii < regionLabels.length ; ii++){
+	    if (regionLabels[ii]==index) {
+		regionindex=ii;
+		break;
+	    }
 	}
+
+	if (regionindex < 0 ) {
+	    throw new IllegalArgumentException("ROI index not known ( " + 
+					       index + " )");
+	}
+
+	if (regionindex >= 0 && regionindex < numberOfRegions) { 
+	    return new FreeFormROI(data, (short)(regionLabels[regionindex]), xVoxelDim, yVoxelDim, zVoxelDim);
+	}
 	else {
 	    throw new IllegalArgumentException("ROI index out of bounds. This ROI contains " + 
 					       numberOfRegions() + " regions");


More information about the Camino-users mailing list