@@ -45,10 +45,11 @@ public class SynQuantVid_ implements PlugIn, DialogListener{
45
45
protected double minFill , maxWHRatio ;
46
46
protected int NumSynSite =0 ;
47
47
protected ImagePlus outputImp =null ; // detection results output
48
- int [][][][] synIdx ;
49
- double [][][][] synZscore ;
48
+ int [][][][] synIdx ;
49
+ double [][][][] synZscore ;
50
50
double slideThrZ ;
51
51
int [][][] sliderSynMap ; // synapse map after post-processing
52
+ int way2combinePostPre = 1 ; // the way to combine pre- and post-channel, 0:intersect, 1: add pre-zscore to post-zscore
52
53
53
54
54
55
boolean fastflag = true ; //true: no use because we only use fast version
@@ -85,6 +86,8 @@ public boolean showDialog()
85
86
openData [activeImageIDs .length ] = "Null" ;
86
87
gd .addChoice ("Post-synapse:" , openData , openData [0 ]);
87
88
gd .addChoice ("Pre-synapse:" , openData , openData [activeImageIDs .length ]);
89
+ String [] combinePrePostChl = {"intersect" , "post_channel_mainly" ,"Null" };
90
+ gd .addChoice ("Way to combine:" , combinePrePostChl , combinePrePostChl [combinePrePostChl .length -1 ]);
88
91
gd .addChoice ("Dendrite channel" , openData , openData [activeImageIDs .length ]);
89
92
gd .showDialog ();
90
93
if (gd .wasCanceled ()){
@@ -102,6 +105,9 @@ public boolean showDialog()
102
105
}
103
106
int post_chl = gd .getNextChoiceIndex ();
104
107
int pre_chl = gd .getNextChoiceIndex ();
108
+ way2combinePostPre = gd .getNextChoiceIndex ();
109
+ if (way2combinePostPre >1 ) //user forget to set or single channel
110
+ way2combinePostPre = 1 ;
105
111
int den_chl = gd .getNextChoiceIndex ();
106
112
107
113
numChannels = 2 ; // we only care two channels: post- and pre-synaptic channel
@@ -153,13 +159,9 @@ public boolean showDialog()
153
159
* ***/
154
160
public void synQuant3D_real () {
155
161
//// parameter initialization
156
- paraQ3D q = new paraQ3D (numChannels , 0.8 );
162
+ paraQ3D q = new paraQ3D (numChannels , way2combinePostPre , 0.8 );
157
163
BasicMath bm = new BasicMath ();
158
164
//// data saving final results
159
- // timePts = imp.getNFrames();
160
- // synIdx = new int [timePts][zSlice][height][width];
161
- // synZscore = new double [timePts][zSlice][height][width];
162
- // q.synZscore = new double [timePts][zSlice][height][width];
163
165
slideThrZ = 1000 ;
164
166
ppsd3D particle3D_det = null ;
165
167
//short[][] Arr3D = null;
@@ -178,9 +180,7 @@ public void synQuant3D_real() {
178
180
synIdx = new int [timePts ][zSlice ][height ][width ];
179
181
synZscore = new double [timePts ][zSlice ][height ][width ];
180
182
}
181
- //if (q._NumChannel == q.NumChannelProcessed + 1 ) {
182
-
183
- //}
183
+
184
184
double vox_x = imp .getCalibration ().pixelWidth ;
185
185
if (vox_x ==1 )//simulated data
186
186
vox_x = 2.0757e-7 ;
@@ -191,33 +191,28 @@ public void synQuant3D_real() {
191
191
192
192
long startTime1 =System .nanoTime ();
193
193
////particle detection
194
- for (int i =1 ; i <= timePts ; i ++){
194
+ for (int i =1 ; i <= timePts ; i ++)
195
+ {
195
196
q .curTps = i -1 ;
196
197
short [][] Arr3D = stack2array (type , stack , i ); // #zstack*#pixels in one slice
197
198
paraP3D p = new paraP3D (fdr , zscore_thres ,(int )bm .matrix2DMin (Arr3D ),(int )bm .matrix2DMax (Arr3D ),MinSize , MaxSize , minFill , maxWHRatio );
198
199
particle3D_det = new ppsd3D (Arr3D , width , height , vox_x , p ,q );
199
- // synIdx[i-1] = particle3D_det.ppsd_main.kMap;
200
- // synZscore[i-1] = particle3D_det.ppsd_main.zMap;
201
- // for the final channel, we save the output results
202
- if ( q . _NumChannel == q . NumChannelProcessed + 1 ) { // last one
200
+
201
+ // for the post channel, we save the output results
202
+ if ( q . _NumChannel == q . NumChannelProcessed + 1 )
203
+ { // last one
203
204
synIdx [i -1 ] = particle3D_det .ppsd_main .kMap ;
204
205
synZscore [i -1 ] = particle3D_det .ppsd_main .zMap ;
205
206
double tmpThrZ = particle3D_det .ppsd_main .thrZ ;
206
207
if (slideThrZ > tmpThrZ )
207
208
slideThrZ = tmpThrZ ;
208
- }else {// not last one
209
+ }else
210
+ {// pre-channel
209
211
q .synZscore [q .curTps ] = particle3D_det .ppsd_main .zMap ;
210
- // if (q.NumChannelProcessed == 0) { // first one
211
- // q.synZscore[q.curTps] = particle3D_det.ppsd_main.zMap;
212
- // }else { //not first, not last
213
- // q.synZscore[q.curTps] = bm.matrix3DAdd(q.synZscore[q.curTps], particle3D_det.ppsd_main.zMap);
214
- // }
215
212
}
216
213
}
217
214
long endTime1 =System .nanoTime ();
218
215
System .out .println ("Finished. Data size: " +zSlice +" * " +height +" * " +width +" * " +timePts +" Total running time: " +(endTime1 -startTime1 )/1e9 );
219
- //// results display
220
-
221
216
q .NumChannelProcessed ++;
222
217
q .var = 0 ; // reset variance, preparing for new channel
223
218
}
@@ -261,28 +256,39 @@ public void synQuant3D_real() {
261
256
262
257
// display the results of puncta detection results
263
258
ImageHandling IH = new ImageHandling ();
264
- if (imp .getNSlices () == 1 ) { //for 2d data use ROI manager to display results
259
+ if (imp .getNSlices () == 1 )
260
+ { //for 2d data use ROI manager to display results
265
261
boolean [][] synMap2dBin = new boolean [synZscore [0 ][0 ].length ][synZscore [0 ][0 ][0 ].length ];
266
- if (sliderSynMap == null ) {
267
- for (int i =0 ; i <synZscore [0 ][0 ].length ; i ++) {
268
- for (int j =0 ; j <synZscore [0 ][0 ][0 ].length ;j ++) {
269
- if (synZscore [0 ][0 ][i ][j ]>=zscore_thres ) {
262
+ if (sliderSynMap == null )
263
+ {
264
+ for (int i =0 ; i <synZscore [0 ][0 ].length ; i ++)
265
+ {
266
+ for (int j =0 ; j <synZscore [0 ][0 ][0 ].length ;j ++)
267
+ {
268
+ if (synZscore [0 ][0 ][i ][j ]>=zscore_thres )
269
+ {
270
270
synMap2dBin [i ][j ] = true ;
271
271
}
272
- else {
272
+ else
273
+ {
273
274
synMap2dBin [i ][j ] = false ;
274
275
}
275
276
}
276
277
}
277
278
}
278
- else {
279
+ else
280
+ {
279
281
//boolean [][] synMap2dBin = new boolean[sliderSynMap[0].length][sliderSynMap[0][0].length];
280
- for (int i =0 ; i <sliderSynMap [0 ].length ; i ++) {
281
- for (int j =0 ; j <sliderSynMap [0 ][0 ].length ;j ++) {
282
- if (sliderSynMap [0 ][i ][j ]>0 ) {
282
+ for (int i =0 ; i <sliderSynMap [0 ].length ; i ++)
283
+ {
284
+ for (int j =0 ; j <sliderSynMap [0 ][0 ].length ;j ++)
285
+ {
286
+ if (sliderSynMap [0 ][i ][j ]>0 )
287
+ {
283
288
synMap2dBin [i ][j ] = true ;
284
289
}
285
- else {
290
+ else
291
+ {
286
292
synMap2dBin [i ][j ] = false ;
287
293
}
288
294
}
@@ -295,30 +301,43 @@ public void synQuant3D_real() {
295
301
ROIImp .show ();
296
302
IH .DisplayROI (IH .NextLabel ,height ,width ,synMap2d , ROIImp ,"Synapse detection results" );
297
303
}
298
- else {//for 3d data use table to display statistics results
304
+ else
305
+ {//for 3d data use table to display statistics results
299
306
boolean [][][] synMap3dBin = new boolean [synZscore [0 ].length ][synZscore [0 ][0 ].length ][synZscore [0 ][0 ][0 ].length ];
300
- if (sliderSynMap == null ) {
301
- for (int k = 0 ; k <synZscore [0 ].length ; k ++) {
302
- for (int i =0 ; i <synZscore [0 ][0 ].length ; i ++) {
303
- for (int j =0 ; j <synZscore [0 ][0 ][0 ].length ;j ++) {
304
- if (synZscore [0 ][k ][i ][j ]>=zscore_thres ) {
307
+ if (sliderSynMap == null )
308
+ {
309
+ for (int k = 0 ; k <synZscore [0 ].length ; k ++)
310
+ {
311
+ for (int i =0 ; i <synZscore [0 ][0 ].length ; i ++)
312
+ {
313
+ for (int j =0 ; j <synZscore [0 ][0 ][0 ].length ;j ++)
314
+ {
315
+ if (synZscore [0 ][k ][i ][j ]>=zscore_thres )
316
+ {
305
317
synMap3dBin [k ][i ][j ] = true ;
306
318
}
307
- else {
319
+ else
320
+ {
308
321
synMap3dBin [k ][i ][j ] = false ;
309
322
}
310
323
}
311
324
}
312
325
}
313
326
}
314
- else {
315
- for (int k = 0 ; k <sliderSynMap .length ; k ++) {
316
- for (int i =0 ; i <sliderSynMap [0 ].length ; i ++) {
317
- for (int j =0 ; j <sliderSynMap [0 ][0 ].length ;j ++) {
318
- if (sliderSynMap [k ][i ][j ]>0 ) {
327
+ else
328
+ {
329
+ for (int k = 0 ; k <sliderSynMap .length ; k ++)
330
+ {
331
+ for (int i =0 ; i <sliderSynMap [0 ].length ; i ++)
332
+ {
333
+ for (int j =0 ; j <sliderSynMap [0 ][0 ].length ;j ++)
334
+ {
335
+ if (sliderSynMap [k ][i ][j ]>0 )
336
+ {
319
337
synMap3dBin [k ][i ][j ] = true ;
320
338
}
321
- else {
339
+ else
340
+ {
322
341
synMap3dBin [k ][i ][j ] = false ;
323
342
}
324
343
}
@@ -327,19 +346,24 @@ public void synQuant3D_real() {
327
346
}
328
347
int [][][] synMap3d = IH .bwlabel3D (synMap3dBin ,26 );
329
348
double [][] puncta_feats = new double [IH .NextLabel ][4 ]; // volume, Mean, Max, Min intensity
330
- for (int i =0 ; i < IH .NextLabel ; i ++) {
349
+ for (int i =0 ; i < IH .NextLabel ; i ++)
350
+ {
331
351
puncta_feats [i ][0 ] = 0 ;
332
352
puncta_feats [i ][1 ] = 0 ;
333
353
puncta_feats [i ][2 ] = 0 ;
334
354
puncta_feats [i ][3 ] = 65536 ;
335
355
}
336
356
double [][] ArrDouble3D = stack2DoubleArray (imp .getType (), imp .getStack (), 1 );
337
357
System .out .println (bm .matrix2DMax (ArrDouble3D ));
338
- for (int k = 0 ; k <synMap3d .length ; k ++) {
339
- for (int i =0 ; i <synMap3d [0 ].length ; i ++) {
340
- for (int j =0 ; j <synMap3d [0 ][0 ].length ;j ++) {
358
+ for (int k = 0 ; k <synMap3d .length ; k ++)
359
+ {
360
+ for (int i =0 ; i <synMap3d [0 ].length ; i ++)
361
+ {
362
+ for (int j =0 ; j <synMap3d [0 ][0 ].length ;j ++)
363
+ {
341
364
int punctum_id = synMap3d [k ][i ][j ]-1 ;
342
- if (punctum_id >= 0 ) {
365
+ if (punctum_id >= 0 )
366
+ {
343
367
if (punctum_id >= puncta_feats .length )
344
368
System .out .print (true );
345
369
puncta_feats [punctum_id ][0 ] += 1 ;
@@ -368,21 +392,27 @@ public void synQuant3D_real() {
368
392
det_ft_table .showRowNumbers (false );
369
393
det_ft_table .show ("Puncta statistics on 3D data" );
370
394
}
371
- if (den_imp != null ) {
372
- if (den_imp .getNSlices () == 1 & imp .getNSlices () == 1 ) { //do quantification
395
+ if (den_imp != null )
396
+ {
397
+ if (den_imp .getNSlices () == 1 & imp .getNSlices () == 1 )
398
+ { //do quantification
373
399
boolean [][] kSynR1 = new boolean [synZscore [0 ][0 ].length ][synZscore [0 ][0 ][0 ].length ];
374
- if (sliderSynMap == null ) {
400
+ if (sliderSynMap == null )
401
+ {
375
402
for (int i =0 ; i <kSynR1 .length ; i ++)
376
403
{
377
- for (int j =0 ; j <kSynR1 [0 ].length ;j ++) {
404
+ for (int j =0 ; j <kSynR1 [0 ].length ;j ++)
405
+ {
378
406
kSynR1 [i ][j ] = synZscore [0 ][0 ][i ][j ]>zscore_thres ;
379
407
}
380
408
}
381
409
}
382
- else {
410
+ else
411
+ {
383
412
for (int i =0 ; i <kSynR1 .length ; i ++)
384
413
{
385
- for (int j =0 ; j <kSynR1 [0 ].length ;j ++) {
414
+ for (int j =0 ; j <kSynR1 [0 ].length ;j ++)
415
+ {
386
416
kSynR1 [i ][j ] = sliderSynMap [0 ][i ][j ] > 0 ;
387
417
}
388
418
}
@@ -391,7 +421,8 @@ public void synQuant3D_real() {
391
421
//show features
392
422
ResultsTable Ft_table = new ResultsTable ();
393
423
int DenCnt = 0 ;
394
- for (int i =0 ;i <den_det .CurNum ;i ++) {
424
+ for (int i =0 ;i <den_det .CurNum ;i ++)
425
+ {
395
426
Ft_table .incrementCounter ();
396
427
DenCnt = DenCnt +1 ;
397
428
Ft_table .addLabel ("Dendrite piece #" +DenCnt );
@@ -444,12 +475,17 @@ public boolean dialogItemChanged (GenericDialog gd, AWTEvent e) {
444
475
//System.out.println("-th Frame SynNum: " + zscore_thres);
445
476
//outputImp = IJ.createHyperStack("Found Particles", width, height, 1, zSlice, timePts,16/*bitdepth*/);
446
477
outputImp .show ();
447
- for (int i =1 ; i <= timePts ; i ++){
478
+ for (int i =1 ; i <= timePts ; i ++)
479
+ {
448
480
sliderSynMap = new int [zSlice ][height ][width ];
449
- for (int zz =0 ;zz <zSlice ; zz ++) {
450
- for (int yy =0 ;yy <height ; yy ++) {
451
- for (int xx =0 ;xx <width ; xx ++) {
452
- if (synZscore [i -1 ][zz ][yy ][xx ] >= zscore_thres ) {
481
+ for (int zz =0 ;zz <zSlice ; zz ++)
482
+ {
483
+ for (int yy =0 ;yy <height ; yy ++)
484
+ {
485
+ for (int xx =0 ;xx <width ; xx ++)
486
+ {
487
+ if (synZscore [i -1 ][zz ][yy ][xx ] >= zscore_thres )
488
+ {
453
489
sliderSynMap [zz ][yy ][xx ] = 1 ;//synZscore[i-1][zz][yy][xx];
454
490
}
455
491
}
@@ -585,21 +621,28 @@ public void SynapticDisplay(int [][][] kSynR1, int curTimePt){
585
621
// }
586
622
// }
587
623
double max_intensity = 0 ;
588
- if (imp .getType () == ImagePlus .GRAY16 ) {
589
- for (int stackNum =1 ; stackNum <=curStack .getSize (); stackNum ++) {
624
+ if (imp .getType () == ImagePlus .GRAY16 )
625
+ {
626
+ for (int stackNum =1 ; stackNum <=curStack .getSize (); stackNum ++)
627
+ {
590
628
double tmp_max = curInStack .getProcessor (stackNum ).getStatistics ().max ;
591
- if (max_intensity < tmp_max ) {
629
+ if (max_intensity < tmp_max )
630
+ {
592
631
max_intensity = tmp_max ;
593
632
}
594
633
}
595
634
}
596
- for (int stackNum =1 ; stackNum <=curStack .getSize (); stackNum ++) {
635
+ for (int stackNum =1 ; stackNum <=curStack .getSize (); stackNum ++)
636
+ {
597
637
outIP = curStack .getProcessor (stackNum );
598
638
inIP = curInStack .getProcessor (stackNum );
599
- for (int i = 0 ; i < width ; i ++) {
600
- for (int j = 0 ;j <height ;j ++){
639
+ for (int i = 0 ; i < width ; i ++)
640
+ {
641
+ for (int j = 0 ;j <height ;j ++)
642
+ {
601
643
// put channel values in an integer
602
- if (imp .getType () == ImagePlus .GRAY8 ) {
644
+ if (imp .getType () == ImagePlus .GRAY8 )
645
+ {
603
646
int tmp_val = (int )inIP .get (i , j ) & 0xff ;
604
647
if (kSynR1 [stackNum -1 ][j ][i ]>0 )
605
648
outIP .set (i , j , (((int )200 & 0xff ) << 16 )
@@ -609,7 +652,8 @@ public void SynapticDisplay(int [][][] kSynR1, int curTimePt){
609
652
outIP .set (i , j , (((int )0 & 0xff ) << 16 )
610
653
+ (tmp_val << 8 )
611
654
+ ((int )0 & 0xff ));
612
- }else {
655
+ }else
656
+ {
613
657
// if(inIP.get(i, j)>255*10)
614
658
// System.out.println(" "+inIP.get(i, j));
615
659
byte tmp_float_val = (byte ) ((((double )inIP .get (i , j ))/max_intensity )*255 );
0 commit comments