Skip to content

Commit be59dee

Browse files
committed
New way combine pre and postChl
1 parent 4e21453 commit be59dee

28 files changed

+218
-128
lines changed

.classpath

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
<attribute name="test" value="true"/>
1919
</attributes>
2020
</classpathentry>
21-
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
22-
<attributes>
23-
<attribute name="maven.pomderived" value="true"/>
24-
<attribute name="test" value="true"/>
25-
</attributes>
26-
</classpathentry>
2721
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
2822
<attributes>
2923
<attribute name="maven.pomderived" value="true"/>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

.settings/org.eclipse.jdt.core.prefs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
33
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
45
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
57
org.eclipse.jdt.core.compiler.release=disabled
68
org.eclipse.jdt.core.compiler.source=1.5

src/main/java/SynQuantVid_.java

Lines changed: 116 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ public class SynQuantVid_ implements PlugIn, DialogListener{
4545
protected double minFill, maxWHRatio;
4646
protected int NumSynSite=0;
4747
protected ImagePlus outputImp=null; // detection results output
48-
int[][][][] synIdx;
49-
double[][][][] synZscore;
48+
int [][][][] synIdx;
49+
double [][][][] synZscore;
5050
double slideThrZ;
5151
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
5253

5354

5455
boolean fastflag = true; //true: no use because we only use fast version
@@ -85,6 +86,8 @@ public boolean showDialog()
8586
openData[activeImageIDs.length] = "Null";
8687
gd.addChoice("Post-synapse:", openData, openData[0]);
8788
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]);
8891
gd.addChoice("Dendrite channel", openData, openData[activeImageIDs.length]);
8992
gd.showDialog();
9093
if (gd.wasCanceled()){
@@ -102,6 +105,9 @@ public boolean showDialog()
102105
}
103106
int post_chl = gd.getNextChoiceIndex();
104107
int pre_chl = gd.getNextChoiceIndex();
108+
way2combinePostPre = gd.getNextChoiceIndex();
109+
if (way2combinePostPre>1) //user forget to set or single channel
110+
way2combinePostPre = 1;
105111
int den_chl = gd.getNextChoiceIndex();
106112

107113
numChannels = 2; // we only care two channels: post- and pre-synaptic channel
@@ -153,13 +159,9 @@ public boolean showDialog()
153159
* ***/
154160
public void synQuant3D_real() {
155161
//// parameter initialization
156-
paraQ3D q = new paraQ3D(numChannels, 0.8);
162+
paraQ3D q = new paraQ3D(numChannels, way2combinePostPre, 0.8);
157163
BasicMath bm = new BasicMath();
158164
//// 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];
163165
slideThrZ = 1000;
164166
ppsd3D particle3D_det = null;
165167
//short[][] Arr3D = null;
@@ -178,9 +180,7 @@ public void synQuant3D_real() {
178180
synIdx = new int [timePts][zSlice][height][width];
179181
synZscore = new double [timePts][zSlice][height][width];
180182
}
181-
//if (q._NumChannel == q.NumChannelProcessed + 1 ) {
182-
183-
//}
183+
184184
double vox_x = imp.getCalibration().pixelWidth;
185185
if(vox_x==1)//simulated data
186186
vox_x = 2.0757e-7;
@@ -191,33 +191,28 @@ public void synQuant3D_real() {
191191

192192
long startTime1=System.nanoTime();
193193
////particle detection
194-
for (int i=1; i <= timePts; i++){
194+
for (int i=1; i <= timePts; i++)
195+
{
195196
q.curTps = i-1;
196197
short[][] Arr3D = stack2array(type, stack, i); // #zstack*#pixels in one slice
197198
paraP3D p = new paraP3D(fdr, zscore_thres,(int)bm.matrix2DMin(Arr3D),(int)bm.matrix2DMax(Arr3D),MinSize, MaxSize, minFill, maxWHRatio);
198199
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
203204
synIdx[i-1] = particle3D_det.ppsd_main.kMap;
204205
synZscore[i-1] = particle3D_det.ppsd_main.zMap;
205206
double tmpThrZ = particle3D_det.ppsd_main.thrZ;
206207
if (slideThrZ > tmpThrZ)
207208
slideThrZ = tmpThrZ;
208-
}else {// not last one
209+
}else
210+
{// pre-channel
209211
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-
// }
215212
}
216213
}
217214
long endTime1=System.nanoTime();
218215
System.out.println("Finished. Data size: "+zSlice+" * "+height+" * "+width+" * "+timePts+" Total running time: "+(endTime1-startTime1)/1e9);
219-
//// results display
220-
221216
q.NumChannelProcessed ++;
222217
q.var = 0; // reset variance, preparing for new channel
223218
}
@@ -261,28 +256,39 @@ public void synQuant3D_real() {
261256

262257
// display the results of puncta detection results
263258
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
265261
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+
{
270270
synMap2dBin[i][j] = true;
271271
}
272-
else {
272+
else
273+
{
273274
synMap2dBin[i][j] = false;
274275
}
275276
}
276277
}
277278
}
278-
else {
279+
else
280+
{
279281
//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+
{
283288
synMap2dBin[i][j] = true;
284289
}
285-
else {
290+
else
291+
{
286292
synMap2dBin[i][j] = false;
287293
}
288294
}
@@ -295,30 +301,43 @@ public void synQuant3D_real() {
295301
ROIImp.show();
296302
IH.DisplayROI(IH.NextLabel,height,width,synMap2d, ROIImp,"Synapse detection results");
297303
}
298-
else {//for 3d data use table to display statistics results
304+
else
305+
{//for 3d data use table to display statistics results
299306
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+
{
305317
synMap3dBin[k][i][j] = true;
306318
}
307-
else {
319+
else
320+
{
308321
synMap3dBin[k][i][j] = false;
309322
}
310323
}
311324
}
312325
}
313326
}
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+
{
319337
synMap3dBin[k][i][j] = true;
320338
}
321-
else {
339+
else
340+
{
322341
synMap3dBin[k][i][j] = false;
323342
}
324343
}
@@ -327,19 +346,24 @@ public void synQuant3D_real() {
327346
}
328347
int[][][] synMap3d = IH.bwlabel3D(synMap3dBin,26);
329348
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+
{
331351
puncta_feats[i][0] = 0;
332352
puncta_feats[i][1] = 0;
333353
puncta_feats[i][2] = 0;
334354
puncta_feats[i][3] = 65536;
335355
}
336356
double[][] ArrDouble3D = stack2DoubleArray(imp.getType(), imp.getStack(), 1);
337357
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+
{
341364
int punctum_id = synMap3d[k][i][j]-1;
342-
if (punctum_id >= 0) {
365+
if (punctum_id >= 0)
366+
{
343367
if (punctum_id >= puncta_feats.length)
344368
System.out.print(true);
345369
puncta_feats[punctum_id][0] += 1;
@@ -368,21 +392,27 @@ public void synQuant3D_real() {
368392
det_ft_table.showRowNumbers(false);
369393
det_ft_table.show("Puncta statistics on 3D data");
370394
}
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
373399
boolean [][] kSynR1 = new boolean [synZscore[0][0].length][synZscore[0][0][0].length];
374-
if (sliderSynMap == null) {
400+
if (sliderSynMap == null)
401+
{
375402
for (int i=0; i<kSynR1.length; i++)
376403
{
377-
for(int j=0; j<kSynR1[0].length;j++) {
404+
for(int j=0; j<kSynR1[0].length;j++)
405+
{
378406
kSynR1[i][j] = synZscore[0][0][i][j]>zscore_thres;
379407
}
380408
}
381409
}
382-
else {
410+
else
411+
{
383412
for (int i=0; i<kSynR1.length; i++)
384413
{
385-
for(int j=0; j<kSynR1[0].length;j++) {
414+
for(int j=0; j<kSynR1[0].length;j++)
415+
{
386416
kSynR1[i][j] = sliderSynMap[0][i][j] > 0;
387417
}
388418
}
@@ -391,7 +421,8 @@ public void synQuant3D_real() {
391421
//show features
392422
ResultsTable Ft_table = new ResultsTable();
393423
int DenCnt = 0;
394-
for (int i=0;i<den_det.CurNum;i++) {
424+
for (int i=0;i<den_det.CurNum;i++)
425+
{
395426
Ft_table.incrementCounter();
396427
DenCnt = DenCnt+1;
397428
Ft_table.addLabel("Dendrite piece #"+DenCnt);
@@ -444,12 +475,17 @@ public boolean dialogItemChanged (GenericDialog gd, AWTEvent e) {
444475
//System.out.println("-th Frame SynNum: " + zscore_thres);
445476
//outputImp = IJ.createHyperStack("Found Particles", width, height, 1, zSlice, timePts,16/*bitdepth*/);
446477
outputImp.show();
447-
for (int i=1; i <= timePts; i++){
478+
for (int i=1; i <= timePts; i++)
479+
{
448480
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+
{
453489
sliderSynMap[zz][yy][xx] = 1;//synZscore[i-1][zz][yy][xx];
454490
}
455491
}
@@ -585,21 +621,28 @@ public void SynapticDisplay(int [][][] kSynR1, int curTimePt){
585621
// }
586622
// }
587623
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+
{
590628
double tmp_max = curInStack.getProcessor(stackNum).getStatistics().max;
591-
if (max_intensity < tmp_max) {
629+
if (max_intensity < tmp_max)
630+
{
592631
max_intensity = tmp_max;
593632
}
594633
}
595634
}
596-
for(int stackNum=1; stackNum<=curStack.getSize(); stackNum++) {
635+
for(int stackNum=1; stackNum<=curStack.getSize(); stackNum++)
636+
{
597637
outIP = curStack.getProcessor(stackNum);
598638
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+
{
601643
// put channel values in an integer
602-
if(imp.getType() == ImagePlus.GRAY8) {
644+
if(imp.getType() == ImagePlus.GRAY8)
645+
{
603646
int tmp_val = (int)inIP.get(i, j) & 0xff;
604647
if(kSynR1[stackNum-1][j][i]>0)
605648
outIP.set(i, j, (((int)200 & 0xff) << 16)
@@ -609,7 +652,8 @@ public void SynapticDisplay(int [][][] kSynR1, int curTimePt){
609652
outIP.set(i, j, (((int)0 & 0xff) << 16)
610653
+ (tmp_val << 8)
611654
+ ((int)0 & 0xff));
612-
}else {
655+
}else
656+
{
613657
// if(inIP.get(i, j)>255*10)
614658
// System.out.println(" "+inIP.get(i, j));
615659
byte tmp_float_val = (byte) ((((double)inIP.get(i, j))/max_intensity)*255);

0 commit comments

Comments
 (0)