forked from NHotaling/DiameterJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiameterJ_Segment.ijm
2821 lines (2476 loc) · 90.3 KB
/
DiameterJ_Segment.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Define Crop size of all images to be analyzed and define which segmentation algorithms to use
Dialog.create("Location of Cropping Field");
Dialog.setInsets(0, 80, 0);
Dialog.addMessage("Basic Image Information");
image_width = 1280;
image_height = 960;
Dialog.addNumber("Image Width (Uncropped)", image_width, 0, 7, "Pixels");
Dialog.addNumber("Image Height (Uncropped)", image_height, 0 , 7, "Pixels");
Dialog.setInsets(25, 98, 0);
Dialog.addMessage("Cropping Location");
crop_items = newArray("Yes", "No");
Dialog.addChoice("Do you want to crop your image?", crop_items, "Yes");
Dialog.addNumber("Top Left - X coordinate", 0);
Dialog.addNumber("Top Left - Y coordinate", 0);
Dialog.addNumber("Bottom Right - X coordinate", 1280);
Dialog.addNumber("Bottom Right - Y coordinate", 880);
Dialog.setInsets(25, 58, 0);
Dialog.addMessage("Segmentation Algorithms to Use");
Seg_labels = newArray("None", "Traditional", "Stat. Region Merged", "Mixed");
Seg_defaults = newArray(false, false, true, true);
Dialog.addCheckboxGroup(2, 2, Seg_labels, Seg_defaults)
Dialog.setInsets(25, 98, 0);
Dialog.addMessage("Batch Processing");
radio_items = newArray("Yes", "No");
Dialog.addRadioButtonGroup("Do you want to analyze more than one image?", radio_items, 1, 2, "Yes")
Dialog.show;
crop_outcome = Dialog.getChoice();
if (crop_outcome == "Yes"){
iw = Dialog.getNumber();
ih = Dialog.getNumber();
crop_tlx = Dialog.getNumber();
crop_tly = Dialog.getNumber();
crop_brx = Dialog.getNumber();
crop_bry = Dialog.getNumber();
};
if (crop_outcome == "No"){
image_width1 = Dialog.getNumber();
image_height1 = Dialog.getNumber();
crop_tlx = 0;
crop_tly = 0;
crop_brx = image_width1;
crop_bry = image_height1;
};
TLCB_None = Dialog.getCheckbox();
TRCB_Trad = Dialog.getCheckbox();
BLCB_SRM = Dialog.getCheckbox();
BRCB_Mix = Dialog.getCheckbox();
Batch_analysis = Dialog.getRadioButton();
// Checks to see if user is using ImageJ or FIJI and corrects the thresholding variable accordingly
IJorFIJI = getVersion();
if (startsWith(IJorFIJI, 1)){
thresh_dots = "Auto Threshold...";
};
if (startsWith(IJorFIJI, 2)){
thresh_dots = "Auto Threshold";
};
if(Batch_analysis == "Yes") {
// Asks for a directory where Tif files are stored that you wish to analyze
dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);
setBatchMode(true);
T1 = getTime();
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
filename = dir1 + list[i];
if (endsWith(filename, "tif") || endsWith(filename, "tiff") || endsWith(filename, "Tif") || endsWith(filename, "Tiff") || endsWith(filename, "TIF") || endsWith(filename, "TIFF") ||
endsWith(filename, "jpg") || endsWith(filename, "JPG") || endsWith(filename, "jpeg") || endsWith(filename, "JPEG") || endsWith(filename, "Jpeg") || endsWith(filename, "Jpg") ||
endsWith(filename, "gif") || endsWith(filename, "GIF") || endsWith(filename, "Gif") || endsWith(filename, "Giff") || endsWith(filename, "giff") || endsWith(filename, "GIFF") ||
endsWith(filename, "bmp") || endsWith(filename, "BMP") || endsWith(filename, "Bmp") ||
endsWith(filename, "png") || endsWith(filename, "PNG") || endsWith(filename, "Png")) {
print("Analyzing image: ",list[i]);
open(filename);
// Create an empty folder with nothing in it
myDir1 = dir1+"Best Segmentation"+File.separator;
File.makeDirectory(myDir1);
if (!File.exists(myDir1))
exit("Unable to create directory");
// Save SRM images that have been segmented into a folder called Segmented Images
myDir = dir1+"Segmented Images"+File.separator;
File.makeDirectory(myDir);
if (!File.exists(myDir))
exit("Unable to create directory");
print("");
// Save Statistical Region Merged Images into a Folder called SRM
myDir2 = dir1+"Montage Images"+File.separator;
File.makeDirectory(myDir2);
if (!File.exists(myDir2))
exit("Unable to create directory");
// Sets Scale of picture to pixels
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
// Creates custom file names for use later
var name0=getTitle;
name = newArray(name0, getTitle+"_SRM", getTitle+"_M1", getTitle+"_M2", getTitle+"_M3",
getTitle+"_M4", getTitle+"_M5", getTitle+"_M6", getTitle+"_M7", getTitle+"_M8",
getTitle+"_Mix Montage", getTitle+"_SRM100", getTitle+"_SRM50", getTitle+"_S1",
getTitle+"_S2", getTitle+"_S3", getTitle+"_S4", getTitle+"_S5", getTitle+"_S6",
getTitle+"_S7", getTitle+"_S8", getTitle+"_SRM Montage", "image22", getTitle+"_T1",
getTitle+"_T2", getTitle+"_T3", getTitle+"_T4", getTitle+"_T5", getTitle+"_T6",
getTitle+"_T7", getTitle+"_T8", getTitle+"_Trad Montage", getTitle+"_Trad&SRM Montage",
getTitle+"_Trad&Mix Montage", getTitle+"_Mix&SRM Montage", getTitle+"_Trad&Mix&SRM Montage");
for (n = 0; n <36; n++) {
name[n]= replace(name[n],".tiff","");
name[n]= replace(name[n],".Tiff","");
name[n]= replace(name[n],".TIFF","");
name[n]= replace(name[n],".tif","");
name[n]= replace(name[n],".Tif","");
name[n]= replace(name[n],".TIF","");
name[n]= replace(name[n],".giff","");
name[n]= replace(name[n],".Giff","");
name[n]= replace(name[n],".GIFF","");
name[n]= replace(name[n],".gif","");
name[n]= replace(name[n],".Gif","");
name[n]= replace(name[n],".GIF","");
name[n]= replace(name[n],".jpg","");
name[n]= replace(name[n],".jpeg","");
name[n]= replace(name[n],".Jpg","");
name[n]= replace(name[n],".Jpeg","");
name[n]= replace(name[n],".JPG","");
name[n]= replace(name[n],".JPEG","");
name[n]= replace(name[n],".bmp","");
name[n]= replace(name[n],".Bmp","");
name[n]= replace(name[n],".BMP","");
name[n]= replace(name[n],".png","");
name[n]= replace(name[n],".Png","");
name[n]= replace(name[n],".PNG","");
};
// Creates custom file paths for use later
var path0 = myDir1+name[0];
var path1 = myDir+name[2];
var path3 = myDir+name[3];
var path4 = myDir+name[4];
var path5 = myDir+name[5];
var path6 = myDir+name[6];
var path7 = myDir+name[7];
var path8 = myDir+name[8];
var path9 = myDir+name[9];
var path10 = myDir2+name[10];
var path11 = myDir+name[11];
var path12 = myDir+name[12];
var path13 = myDir+name[13];
var path14 = myDir+name[14];
var path15 = myDir+name[15];
var path16 = myDir+name[16];
var path17 = myDir+name[17];
var path18 = myDir+name[18];
var path19 = myDir+name[19];
var path20 = myDir+name[20];
var path21 = myDir2+name[21];
var path23 = myDir+name[23];
var path24 = myDir+name[24];
var path25 = myDir+name[25];
var path26 = myDir+name[26];
var path27 = myDir+name[27];
var path28 = myDir+name[28];
var path29 = myDir+name[29];
var path30 = myDir+name[30];
var path31 = myDir2+name[31];
var path32 = myDir2+name[32];
var path33 = myDir2+name[33];
var path34 = myDir2+name[34];
var path35 = myDir2+name[35];
// Runs all traditional segmentation algorithms
if (TRCB_Trad == 1 && TLCB_None == 0){
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Runs Huang thresholding on the image
run(thresh_dots, "method=Huang ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path23);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Percentile thresholding on the mage
run(thresh_dots, "method=Percentile ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path24);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Runs MinError(I) thresholding on the image
run(thresh_dots, "method=MinError(I) ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path25);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Runs Triangle thresholding on the image
run(thresh_dots, "method=Triangle ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path26);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Li thresholding without ignoring white pixels on the image
run(thresh_dots, "method=Li ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path27);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs an Otsu thresholding on the image
run(thresh_dots, "method=Otsu ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path28);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs an MaxEntropy thresholding on the image
run(thresh_dots, "method=MaxEntropy ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path29);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs an RenyiEntropy thresholding on the image
run(thresh_dots, "method=RenyiEntropy ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
run("Fill Holes");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path30);
run("Close All");
};
// Runs Mixed Segmentation Algorithms
if (BRCB_Mix == 1 && TLCB_None == 0){
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Statistical Region Merging (SRM) Segmentation technique with 25 grey scale values and converts picture to an 8-bit image
run("Statistical Region Merging", "q=25 showaverages");
run("8-bit");
// Runs a Runs Huang thresholding on the SRM 8-bit image
run(thresh_dots, "method=Huang ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path1);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Statistical Region Merging (SRM) Segmentation technique with 25 grey scale values and converts picture to an 8-bit image then segments via MinError() method
run("Statistical Region Merging", "q=25 showaverages");
run("8-bit");
run(thresh_dots, "method=MinError(I) ignore_white white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path3);
run("Close");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Statistical Region Merging (SRM) Segmentation technique with 25 grey scale values and converts picture to an 8-bit image then segments via Percentile method
run("Statistical Region Merging", "q=25 showaverages");
run("8-bit");
run(thresh_dots, "method=Percentile white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path4);
run("Close");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Statistical Region Merging (SRM) Segmentation technique with 25 grey scale values and converts picture to an 8-bit image then segments via Triangle method
run("Statistical Region Merging", "q=25 showaverages");
run("8-bit");
run(thresh_dots, "method=Triangle white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path5);
run("Close");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a segmentation via Huang's method and saves the result after processing.
run(thresh_dots, "method=Huang ignore_white white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path6);
run("Close");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a segmentation via MinError's method and saves the result after processing.
run(thresh_dots, "method=MinError(I) white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path7);
run("Close");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a segmentation via Percentile's method and saves the result after processing.
run(thresh_dots, "method=Percentile white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path8);
run("Close");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a segmentation via Triangle's method and saves the result after processing.
run(thresh_dots, "method=Triangle white");
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path9);
setForegroundColor(0,0,0);
run("Close All");
}
// Runs Statistical Region Merging Segmentation Techniques on all of the images
if(BLCB_SRM == 1 && TLCB_None == 0){
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
// Runs a Statistical Region Merging (SRM) Segmentation technique with 25 grey scale values and converts picture to an 8-bit image
run("Statistical Region Merging", "q=100 showaverages");
run("8-bit");
saveAs("Tiff", path11);
open(path11+".tif");
run("Statistical Region Merging", "q=50 showaverages");
run("8-bit");
saveAs("Tiff", path11);
open(path11+".tif");
run("Statistical Region Merging", "q=25 showaverages");
run("8-bit");
saveAs("Tiff", path11);
run("Close");
open(path11+".tif");
run("Statistical Region Merging", "q=12 showaverages");
run("8-bit");
saveAs("Tiff", path11);
run("Close All");
open(name0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit= pixels");
makeRectangle(crop_tlx, crop_tly, crop_brx, crop_bry);
run("Crop");
run("Statistical Region Merging", "q=50 showaverages");
run("8-bit");
saveAs("Tiff", path12);
open(path12+".tif");
run("Statistical Region Merging", "q=10 showaverages");
run("8-bit");
saveAs("Tiff", path12);
run("Close");
open(path11+".tif");
// Runs a Runs Huang thresholding on the SRM 8-bit image
run(thresh_dots, "method=Huang ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path13);
run("Close");
open(path11+".tif");
// Runs a Min Error thresholding on the SRM 8-bit image
run(thresh_dots, "method=MinError(I) ignore_white white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){
run("Invert");};
// Saves B&W picture for analysis
saveAs("Tiff", path14);
run("Close");
open(path11+".tif");
// Runs a Percentile thresholding on the SRM 8-bit image
run(thresh_dots, "method=Percentile white");
//Cleans up noise in image by filling in dark regions, despeckling in a loop until no noise (5px or less) groups remain, removes outliers and diates/erodes surfaces to remove surface morphological features.
run("Fill Holes");
getHistogram(values, counts, 256);
Black_Pixels = counts[255];
e= Black_Pixels;
do {
f=e;
run("Despeckle");
getHistogram(values, counts, 256);
white_area1= counts[255];
e = white_area1;
} while(e != f);
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
run("Remove Outliers...", "radius=3 threshold=50 which=Bright");
run("Erode");
run("Dilate");
black1=0;
black2=0;
getHistogram(values, counts, 256);
black1= counts[255];
run("Make Binary");
getHistogram(values, counts, 256);
black2= counts[255];
if(black1 == black2 ){