-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMARTA_2.5.py
2482 lines (2147 loc) · 133 KB
/
MARTA_2.5.py
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
# coding: utf-8
import time as tm
import os
import sys
import cv2
import imutils
import numpy as np
import matplotlib.pyplot as plt
import warnings
import PIL
from datetime import datetime, timezone
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import ttk
from tkinter.font import BOLD
from tkinter import simpledialog
from PIL import ImageTk, Image
class ToolTip(object):
def __init__(self, widget):
self.widget = widget
self.tipwindow = None
self.id = None
self.x = self.y = 0
def showtip(self, text):
"Display text in tooltip window"
self.text = text
if self.tipwindow or not self.text:
return
x, y, cx, cy = self.widget.bbox("insert")
x = x + self.widget.winfo_rootx() + 57
y = y + cy + self.widget.winfo_rooty() +27
self.tipwindow = tw = Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
label = Label(tw, text=self.text, justify=LEFT,
background="#ffffe0", relief=SOLID, borderwidth=1,
font=("tahoma", "8", "normal"))
label.pack(ipadx=1)
def hidetip(self):
tw = self.tipwindow
self.tipwindow = None
if tw:
tw.destroy()
def CreateToolTip(widget, text):
toolTip = ToolTip(widget)
def enter(event):
toolTip.showtip(text)
def leave(event):
toolTip.hidetip()
widget.bind('<Enter>', enter)
widget.bind('<Leave>', leave)
class MyWindow:
def __init__(self, win):
self.master = win
self.lbl1=Label(win, text='Number of images \n(1 or 3)')
self.t1=Entry(win,textvariable=StringVar(window, value='3'), width=5, justify='center')
self.lbl1.grid(column=4,row=0, sticky=E)
self.t1.grid(column=5,row=0,sticky=W)
CreateToolTip(self.t1, text = 'One merged input file (1) or three input files (3)')
self.lbl2=Label(win, text='File label pattern \n(no ext)')
self.t2=Entry(window,textvariable=StringVar(window, value='a'), width=5, justify='center')
self.lbl2.grid(column=2,row=0, sticky=E)
self.t2.grid(column=3,row=0, sticky=W)
CreateToolTip(self.t2, text = 'Pattern filename with no extension.')
self.lb_33=Label(win, text='Input extension', justify= RIGHT)
self.t33=Entry(window,textvariable=StringVar(window, value='.tif'), width=5, justify='center')
self.lb_33.grid(column=6,row=0, sticky=E)
self.t33.grid(column=7,row=0, sticky=W)
self.lb_34=Label(win, text='Output extension')
self.t34=Entry(window,textvariable=StringVar(window, value='.tif'), width=5)
self.lb_34.grid(column=6,row=1, sticky=E)
self.t34.grid(column=7,row=1, sticky=W)
self.lbl4=Label(win, text='scaling (units/pixel)')
self.t4=Entry(window,textvariable=StringVar(window, value='0.21'), width=5, justify='center')
self.lbl4.grid(column=4,row=1, sticky=E)
self.t4.grid(column=5,row=1, sticky=W)
self.selected = StringVar()
rad1 = Radiobutton(window,text='Automatic', value='automatic', variable=self.selected)
rad2 = Radiobutton(window,text='Supervised', value='supervised', variable=self.selected)
self.selected.set("automatic")
CreateToolTip(rad1, text = 'Select for full automated processing')
CreateToolTip(rad2, text = 'Select for individual decision for all detections')
btn2 = Button(window, text="Generate Automatic mask", font= "bold", command=self.run, height=2, width=25)
btn3 = Button(window, text=" Generate Manual mask ", command=self.say_hi)
btn10 = Button(window, text=" Exit ", command=self.ex)
previewCM = Button(window, text="Preview \nCardiomyocytes", bg="#10FF10", command=self.sercaORG, width=15)
previewCx = Button(window, text="Preview \nConnexin 43", bg="#FFFFFF", command=self.cxORG, width=15)
previewWGA = Button(window, text="Preview \nWGA", bg="#F08080", command=self.wgaORG, width=15)
previewtres = Button(window, text="Preview cell masks", bg="#FFFFFF", command=self.sumar_canales, width=25)
rad1.grid(column=0, row=1)
rad2.grid(column=1, row=1)
btn2.grid(column=6, row=26, columnspan=2, rowspan=2)
btn3.grid(column=0,row=36, columnspan=2)
btn10.grid(column=4, row=27)
previewCM.grid(row=8, column=8)
previewCx.grid(row=9, column=8)
previewWGA.grid(row=10, column=8)
previewtres.grid(row=11, column=6, columnspan=2)
CreateToolTip(btn2, text = 'Click to run automated processing of input images with the parameter set.')
CreateToolTip(btn3, text = 'Click to create a manual delineated mask of the input images. \n Double click to generate vertices. \n Press ESC to go to next subimage in case of split. \n The output will be labeled as pattern_mM (i.e. a_mM).')
self.selcomb = StringVar()
rad21 = Radiobutton(window,text='Add', value='addch', variable=self.selcomb)
rad22 = Radiobutton(window,text='Independent', value='indepch', variable=self.selcomb)
self.selcomb.set("addch")
rad21.grid(column=0, row=2)
rad22.grid(column=1, row=2)
self.chk1_state = BooleanVar()
self.chk1_state.set(False)
chk1 = Checkbutton(window, text='Input Mask', var=self.chk1_state)
chk1.grid(column=0, row=3)
CreateToolTip(chk1, text = 'Check to process a provided input mask (i.e a_mM.tif)')
self.chk2_state = BooleanVar()
self.chk2_state.set(False)
chk2 = Checkbutton(window, text='Equalize', var=self.chk2_state)
chk2.grid(column=1, row=3)
CreateToolTip(chk2, text = 'Check to make equalization of input files before processing.')
self.chk3_state = BooleanVar()
self.chk3_state.set(False)
chk3 = Checkbutton(window, text='Evaluate', var=self.chk3_state)
chk3.grid(column=2, row=3)
CreateToolTip(chk3, text = 'Check to generate evaluation using manual delineated mask (i.e a_mM.tif) \n and input files (i.e. a_c1.tif, a_c2.tif, a_c3.tif).')
lbl5=Label(win, text='Equalized \nbinary threshold')
self.t5=Entry(window,textvariable=StringVar(window, value='70'), width=5)
lbl5.grid(column=0,row=7, sticky=E)
self.t5.grid(column=1,row=7, sticky=W)
CreateToolTip(self.t5, text = '8-bit binary value for thresholding when equalization is used for channels c1 (cell) and c3 (intersticium) ')
lbl5_2=Label(win, text='Binary threshold for c4')
self.t5_2=Entry(window,textvariable=StringVar(window, value='254'), width=5)
lbl5_2.grid(column=2,row=7, sticky=E)
self.t5_2.grid(column=3,row=7, sticky=W)
CreateToolTip(self.t5_2, text = '8-bit binary value for thresholding in c4 channel')
lbl6=Label(win, text='Binary threshold \nfor c1 (CM)', bg="#10FF10")
self.t6=Entry(window,textvariable=StringVar(window, value='7'), width=5)
lbl6.grid(column=0,row=8, sticky=E)
self.t6.grid(column=1,row=8, sticky=W)
CreateToolTip(self.t6, text = '8-bit binary value for thresholding in c1 channel (Myocite fill, i.e. SERCA, F-actin,...)')
lbl7=Label(win, text='Binary threshold \nfor c2 (CX)', bg="#FFFFFF")
self.t7=Entry(window,textvariable=StringVar(window, value='12'), width=5)
lbl7.grid(column=0,row=9, sticky=E)
self.t7.grid(column=1,row=9, sticky=W)
CreateToolTip(self.t7, text = '8-bit binary value for thresholding in c2 channel (CX43 for longitudinal CM delimitation)')
lbl8=Label(win, text='Binary threshold \nfor c3 (INT)', bg="#F08080")
self.t8=Entry(window,textvariable=StringVar(window, value='9'), width=5)
lbl8.grid(column=0,row=10, sticky=E)
self.t8.grid(column=1,row=10, sticky=W)
CreateToolTip(self.t8, text = '8-bit binary value for thresholding in c3 channel (Intersticium fill, i.e. WGA)')
lbl9=Label(win, text='Noise removal matrix rank \nin c1 (CM)', bg="#10FF10")
self.t9=Entry(window,textvariable=StringVar(window, value='3'), width=5)
lbl9.grid(column=2,row=8, sticky=E)
self.t9.grid(column=3,row=8, sticky=W)
lbl_10=Label(win, text='Noise removal matrix rank \nin c2 (CX)', bg="#FFFFFF")
self.t10=Entry(window,textvariable=StringVar(window, value='4'), width=5)
lbl_10.grid(column=2,row=9, sticky=E)
self.t10.grid(column=3,row=9, sticky=W)
lb_11=Label(win, text='Noise removal matrix rank \nin c3 (INT)', bg="#F08080")
self.t11=Entry(window,textvariable=StringVar(window, value='4'), width=5)
lb_11.grid(column=2,row=10, sticky=E)
self.t11.grid(column=3,row=10, sticky=W)
lb_12=Label(win, text='Dilation matrix rank \nin c1 (CM)', bg="#10FF10")
self.t12=Entry(window,textvariable=StringVar(window, value='5'), width=5)
lb_12.grid(column=4,row=8, sticky=E)
self.t12.grid(column=5,row=8, sticky=W)
lb_13=Label(win, text='Dilation matrix rank \nin c2 (CX)', bg="#FFFFFF")
self.t13=Entry(window,textvariable=StringVar(window, value='7'), width=5)
lb_13.grid(column=4,row=9, sticky=E)
self.t13.grid(column=5,row=9, sticky=W)
lb_14=Label(win, text='Dilation matrix rank \nin c3 (INT)', bg="#F08080")
self.t14=Entry(window,textvariable=StringVar(window, value='2'), width=5)
lb_14.grid(column=4,row=10, sticky=E)
self.t14.grid(column=5,row=10, sticky=W)
lb_15=Label(win, text='Dilation iterations \nin c1 (CM)', bg="#10FF10")
self.t15=Entry(window,textvariable=StringVar(window, value='3'), width=5)
lb_15.grid(column=6,row=8, sticky=E)
self.t15.grid(column=7,row=8, sticky=W)
lb_16=Label(win, text='Dilation iterations \nin c2 (CX)', bg="#FFFFFF")
self.t16=Entry(window,textvariable=StringVar(window, value='6'), width=5)
lb_16.grid(column=6,row=9, sticky=E)
self.t16.grid(column=7,row=9, sticky=W)
lb_17=Label(win, text='Dilation iterations \nin c3 (INT)', bg="#F08080")
self.t17=Entry(window,textvariable=StringVar(window, value='3'), width=5)
lb_17.grid(column=6,row=10, sticky=E)
self.t17.grid(column=7,row=10, sticky=W)
lb_21=Label(win, text='First Filter \nminimum area (um**2)')
self.t21=Entry(window,textvariable=StringVar(window, value='100'), width=5)
lb_21.grid(column=0,row=11, sticky=E)
self.t21.grid(column=1,row=11, sticky=W)
lb_22=Label(win, text='First Filter \nminimum perimeter (um)')
self.t22=Entry(window,textvariable=StringVar(window, value='40'), width=5)
lb_22.grid(column=0,row=12, sticky=E)
self.t22.grid(column=1,row=12, sticky=W)
lb_23=Label(win, text='Second Filter \nL min (um)')
self.t23=Entry(window,textvariable=StringVar(window, value='35'), width=5)
lb_23.grid(column=0,row=13, sticky=E)
self.t23.grid(column=1,row=13, sticky=W)
lb_24=Label(win, text='Second Filter \nL max (um)')
self.t24=Entry(window,textvariable=StringVar(window, value='200'), width=5)
lb_24.grid(column=2,row=13, sticky=E)
self.t24.grid(column=3,row=13, sticky=W)
lb_25=Label(win, text='Second Filter \nW min (um)')
self.t25=Entry(window,textvariable=StringVar(window, value='5'), width=5)
lb_25.grid(column=0,row=14, sticky=E)
self.t25.grid(column=1,row=14, sticky=W)
lb_26=Label(win, text='Second Filter \nW max (um)')
self.t26=Entry(window,textvariable=StringVar(window, value='50'), width=5)
lb_26.grid(column=2,row=14, sticky=E)
self.t26.grid(column=3,row=14, sticky=W)
lb_27=Label(win, text='Second Filter \nR min')
self.t27=Entry(window,textvariable=StringVar(window, value='1'), width=5)
lb_27.grid(column=0,row=15, sticky=E)
self.t27.grid(column=1,row=15, sticky=W)
lb_270=Label(win, text='Padding scale factor')
self.t270=Entry(window,textvariable=StringVar(window, value='1'), width=5)
lb_270.grid(column=2,row=11, sticky=E)
self.t270.grid(column=3,row=11, sticky=W)
CreateToolTip(self.t270, text = '0 for no padding, 1 or 2 are recommended to compensate noise removal effects in automated mask generation')
lb_28=Label(win, text='Gamma correction')
self.t28=Entry(window,textvariable=StringVar(window, value='0.5'), width=5)
lb_28.grid(column=0,row=16, sticky=E)
self.t28.grid(column=1,row=16, sticky=W)
CreateToolTip(self.t28, text = 'Set < 1 to obtain brighter merged output or > 1 to obtain darker merged image output')
lb_29=Label(win, text='Big scale \nbar lenght (um)')
self.t29=Entry(window,textvariable=StringVar(window, value='100'), width=5)
lb_29.grid(column=0,row=17, sticky=E)
self.t29.grid(column=1,row=17, sticky=W)
CreateToolTip(self.t29, text = 'Set the lenght of scale bar for full image')
lb_30=Label(win, text='Small scale \nbar lenght (um)')
self.t30=Entry(window,textvariable=StringVar(window, value='20'), width=5)
lb_30.grid(column=2,row=17, sticky=E)
self.t30.grid(column=3,row=17, sticky=W)
CreateToolTip(self.t30, text = 'Set the lenght of scale bar for individual retrieval images of detections')
lb_31=Label(win, text='Small window \nsize (um)')
self.t31=Entry(window,textvariable=StringVar(window, value='150'), width=5)
lb_31.grid(column=0,row=18, sticky=E)
self.t31.grid(column=1,row=18, sticky=W)
CreateToolTip(self.t31, text = 'Set the size of the window for individual retrievals')
lb_32=Label(win, text='Select \nCM ID plot')
self.t32=Entry(window,textvariable=StringVar(window, value='all'), width=5)
lb_32.grid(column=0,row=19, sticky=E)
self.t32.grid(column=1,row=19, sticky=W)
CreateToolTip(self.t32, text = 'Set a number to display only specific CM number on final output image. Set all to display all CMs')
self.bo1_state = BooleanVar()
self.bo1_state.set(False)
bo1 = Checkbutton(window, text='Plot \nID numbers', var=self.bo1_state)
bo1.grid(column=0, row=20)
CreateToolTip(bo1, text = 'Check to display ID numbers on final output')
self.bo2_state = BooleanVar()
self.bo2_state.set(True)
bo2 = Checkbutton(window, text='Histograms', var=self.bo2_state)
bo2.grid(column=1, row=20)
CreateToolTip(bo2, text = 'Check to generate histogram of detected CMs')
self.bo3_state = BooleanVar()
self.bo3_state.set(True)
bo3 = Checkbutton(window, text='Box Plots', var=self.bo3_state)
bo3.grid(column=2, row=20)
CreateToolTip(bo3, text = 'Check to generate Box Plots of detected CMs')
self.bo4_state = BooleanVar()
self.bo4_state.set(True)
bo4 = Checkbutton(window, text='Merge', var=self.bo4_state)
bo4.grid(column=3, row=20)
CreateToolTip(bo4, text = 'Check to generate the binary merged output in a subfolder. \n For instance: out_quantif_timestamp/a_timestamp_merged_binarized.tif')
self.bo5_state = BooleanVar()
self.bo5_state.set(True)
bo5 = Checkbutton(window, text='Binary Channels', var=self.bo5_state)
bo5.grid(column=2, row=22)
CreateToolTip(bo5, text = 'Check to generate binarized output channels in a subfolder. \n For instance: out_quantif_timestamp/a_timestamp_c1_binarized.tif')
self.bo6_state = BooleanVar()
self.bo6_state.set(True)
bo6 = Checkbutton(window, text='CM Mask (Ma)', var=self.bo6_state)
bo6.grid(column=0, row=21)
CreateToolTip(bo6, text = 'Check to generate cell mask in a subfolder. \n For instance: out_quantif_timestamp/a_timestamp_mask.tif')
self.bo7_state = BooleanVar()
self.bo7_state.set(True)
bo7 = Checkbutton(window, text='Retrievals \noverlapped', var=self.bo7_state)
bo7.grid(column=1, row=21)
CreateToolTip(bo7, text = 'Check to generate merged output with detections in a subfolder. \n For instance: out_quantif_timestamp/a_timestamp_combined_annotated.tif')
self.bo8_state = BooleanVar()
self.bo8_state.set(True)
bo8 = Checkbutton(window, text='Tissue Mask', var=self.bo8_state)
bo8.grid(column=2, row=21)
CreateToolTip(bo8, text = 'Check to generate tissue mask in a subfolder. \n For instance: out_quantif_timestamp/a_timestamp_tissue_mask.tif')
self.bo9_state = BooleanVar()
self.bo9_state.set(True)
bo9 = Checkbutton(window, text='Plot \nIndividual CMs', var=self.bo9_state)
bo9.grid(column=3, row=21)
CreateToolTip(bo9, text = 'Check to generate individual images for each detection in a subfolder inside main subfolder. \n For instance: out_quantif_timestamp/CMs/1.tif')
lbl520=Label(win, text=' ')
lbl520.grid(column=0,row=24)
lbl52=Label(win, text='Parameters for \nEVALUATION', bg="black", fg="white")
lbl52.grid(column=0,row=25)
# lbl521=Label(win, text=' ')
# lbl521.grid(column=0,row=26)
lbl53=Label(win, text='Minimum \nIntersection value')
self.t53=Entry(window,textvariable=StringVar(window, value='50'), width=5)
lbl53.grid(column=0,row=26, sticky=E)
self.t53.grid(column=1,row=26, sticky=W)
lbl54=Label(win, text='Intersection \nmode (max/ref)')
self.t54=Entry(window,textvariable=StringVar(window, value='ref'), width=5)
lbl54.grid(column=0,row=27, sticky=E)
self.t54.grid(column=1,row=27, sticky=W)
# lbl520=Label(win, text=' ')
# lbl520.grid(column=0,row=29)
lbl52=Label(win, text='Parameters for \nManual Mask Generation', bg="black", fg="white")
lbl52.grid(column=0,row=28)
# lbl521=Label(win, text=' ')
# lbl521.grid(column=0,row=29)
lbl530=Label(win, text='Number of vertices \nof polygon')
self.t530=Entry(window,textvariable=StringVar(window, value='8'), width=5)
lbl530.grid(column=0,row=29, sticky=E)
self.t530.grid(column=1,row=29, sticky=W)
CreateToolTip(self.t530, text = 'Number of vertices for each feature. High number will be more accurate but slower manual delineation')
lbl531=Label(win, text='X splits')
self.t531=Entry(window,textvariable=StringVar(window, value='1'), width=5)
lbl531.grid(column=0,row=30, sticky=E)
self.t531.grid(column=1,row=30, sticky=W)
CreateToolTip(self.t531, text = 'Number of splits in x direction to delineate CMs for big images. Press ESC to go to following split')
lbl532=Label(win, text='Y splits')
self.t532=Entry(window,textvariable=StringVar(window, value='1'), width=5)
lbl532.grid(column=0,row=31, sticky=E)
self.t532.grid(column=1,row=31, sticky=W)
CreateToolTip(self.t532, text = 'Number of splits in y direction CMs for big images. Press ESC to go to following split')
def ex(self):
sys.exit()
def sercaORG(self):
#serca = cv2.imread("a_c1.tif")
global fname_c1
idim=self.t2.get()
inpf=self.t33.get()
fname_c1=idim+'_c1'+inpf
serca = cv2.imread(fname_c1)
serca400 = imutils.resize(serca, width=285, height=280)
sercapreview = cv2.cvtColor(serca400, cv2.COLOR_BGR2RGB)
imserca= Image.fromarray(sercapreview)
imgserca=ImageTk.PhotoImage(image=imserca)
origserca = Label(window)
origserca.configure(image=imgserca)
origserca.image = imgserca
origserca.grid(column=9, row=0, rowspan=10)
imgc1 = cv2.imread(fname_c1, cv2.IMREAD_GRAYSCALE)
tresh_c1=int(self.t6.get())
dkremovec1=int(self.t9.get())
dkrgrowc1=int(self.t12.get())
iters_grow_c1=int(self.t15.get())
kernel_noise_remove_c1=np.ones((dkremovec1, dkremovec1),np.uint8)
kernel_grow_c1=np.ones((dkrgrowc1,dkrgrowc1),np.uint8)
thresh1serca = cv2.threshold(imgc1,tresh_c1,255,cv2.THRESH_BINARY)[1]
erserca=cv2.morphologyEx(thresh1serca, cv2.MORPH_OPEN, kernel_noise_remove_c1)
gimgserca=cv2.dilate(erserca,kernel_grow_c1,iterations = iters_grow_c1)
greyserca = np.copy(gimgserca)
greyserca400 = imutils.resize(greyserca, width=285, height=280)
gimserca= Image.fromarray(greyserca400)
gimgserca=ImageTk.PhotoImage(image=gimserca)
maskserca = Label(window)
maskserca.configure(image=gimgserca)
maskserca.image = gimgserca
maskserca.grid(column=10, row=0, rowspan=10)
def cxORG(self):
#serca = cv2.imread("a_c1.tif")
idim=self.t2.get()
inpf=self.t33.get()
fname_c2=idim+'_c2'+inpf
connexinorig = cv2.imread(fname_c2)
connexinorig400 = imutils.resize(connexinorig, width=285, height=280)
cxpreview = cv2.cvtColor(connexinorig400, cv2.COLOR_BGR2RGB)
imcx= Image.fromarray(cxpreview)
imgcx=ImageTk.PhotoImage(image=imcx)
origcx = Label(window)
origcx.configure(image=imgcx)
origcx.image = imgcx
origcx.grid(column=9, row=10, rowspan=10)
# Process channel 4 (Binarized Connexin for quantification)
imgc2=cv2.imread(fname_c2,0)
eqthrcx=int(self.t5_2.get())
tresh_c2=int(self.t7.get())
if(self.chk2_state.get()==True):
equalize='y'
else:
equalize='n'
if(equalize == 'y'):
equ=cv2.equalizeHist(imgc2)
ret,imgcxb2 = cv2.threshold(equ,eqthrcx,255,cv2.THRESH_BINARY)
ret,threshcx = cv2.threshold(equ,eqthrcx,255,cv2.THRESH_BINARY)
else:
ret,threshcx = cv2.threshold(imgc2,tresh_c2,255,cv2.THRESH_BINARY)
ret,imgcxb2 = cv2.threshold(cv2.equalizeHist(imgc2),eqthrcx,255,cv2.THRESH_BINARY)
gimgcx=np.copy(imgcxb2)
greycx = np.copy(gimgcx)
greycx400 = imutils.resize(greycx, width=285, height=280)
gimcx= Image.fromarray(greycx400)
gimgcx=ImageTk.PhotoImage(image=gimcx)
maskcx = Label(window)
maskcx.configure(image=gimgcx)
maskcx.image = gimgcx
maskcx.grid(column=10, row=10, rowspan=10)
def wgaORG(self):
#serca = cv2.imread("a_c1.tif")
idim=self.t2.get()
inpf=self.t33.get()
fname_c3=idim+'_c3'+inpf
wgaorig = cv2.imread(fname_c3)
wgaorig400 = imutils.resize(wgaorig, width=285, height=280)
wgapreview = cv2.cvtColor(wgaorig400, cv2.COLOR_BGR2RGB)
imwga= Image.fromarray(wgapreview)
imgwga=ImageTk.PhotoImage(image=imwga)
origwga = Label(window)
origwga.configure(image=imgwga)
origwga.image = imgwga
origwga.grid(column=9, row=20, rowspan=10)
# Para mostrar la previsualización del canal de wga
imgc3 = cv2.imread(fname_c3, cv2.IMREAD_GRAYSCALE)
tresh_c3=int(self.t8.get())
dkremovec3=int(self.t11.get())
dkrgrowc3=int(self.t14.get())
iters_grow_c3=int(self.t17.get())
kernel_noise_remove_c3=np.ones((dkremovec3, dkremovec3),np.uint8)
kernel_grow_c3=np.ones((dkrgrowc3,dkrgrowc3),np.uint8)
thresh1wga = cv2.threshold(imgc3,tresh_c3,255,cv2.THRESH_BINARY)[1]
erwga=cv2.morphologyEx(thresh1wga, cv2.MORPH_OPEN, kernel_noise_remove_c3)
gimgwga=cv2.dilate(erwga,kernel_grow_c3,iterations = iters_grow_c3)
greywga = np.copy(gimgwga)
greywga400 = imutils.resize(greywga, width=285, height=280)
gimwga= Image.fromarray(greywga400)
gimgwga=ImageTk.PhotoImage(image=gimwga)
maskwga = Label(window)
maskwga.configure(image=gimgwga)
maskwga.image = gimgwga
maskwga.grid(column=10, row=20, rowspan=10)
def sumar_canales(self):
idim=self.t2.get()
inpf=self.t33.get()
fname_c1=idim+'_c1'+inpf
imgc1 = cv2.imread(fname_c1, cv2.IMREAD_GRAYSCALE)
tresh_c1=int(self.t6.get())
dkremovec1=int(self.t9.get())
dkrgrowc1=int(self.t12.get())
iters_grow_c1=int(self.t15.get())
kernel_noise_remove_c1=np.ones((dkremovec1, dkremovec1),np.uint8)
kernel_grow_c1=np.ones((dkrgrowc1,dkrgrowc1),np.uint8)
thresh1serca = cv2.threshold(imgc1,tresh_c1,255,cv2.THRESH_BINARY)[1]
erserca=cv2.morphologyEx(thresh1serca, cv2.MORPH_OPEN, kernel_noise_remove_c1)
gimgserca=cv2.dilate(erserca,kernel_grow_c1,iterations = iters_grow_c1)
greyserca = np.copy(gimgserca)
# greyserca400 = imutils.resize(greyserca, width=285, height=280)
greenserca= cv2.cvtColor(greyserca, cv2.COLOR_GRAY2RGB)
idim=self.t2.get()
inpf=self.t33.get()
fname_c2=idim+'_c2'+inpf
imgc2 = cv2.imread(fname_c2, cv2.IMREAD_GRAYSCALE)
tresh_c2=int(self.t7.get())
dkremovec2=int(self.t10.get())
dkrgrowc2=int(self.t13.get())
iters_grow_c2=int(self.t16.get())
kernel_noise_remove_c2=np.ones((dkremovec2, dkremovec2),np.uint8)
kernel_grow_c2=np.ones((dkrgrowc2,dkrgrowc2),np.uint8)
thresh1cx = cv2.threshold(imgc2,tresh_c2,255,cv2.THRESH_BINARY)[1]
ercx=cv2.morphologyEx(thresh1cx, cv2.MORPH_OPEN, kernel_noise_remove_c2)
gimgcx=cv2.dilate(ercx,kernel_grow_c2,iterations = iters_grow_c2)
greycx = np.copy(gimgcx)
# greycx400 = imutils.resize(greycx, width=285, height=280)
idim=self.t2.get()
inpf=self.t33.get()
fname_c3=idim+'_c3'+inpf
imgc3 = cv2.imread(fname_c3, cv2.IMREAD_GRAYSCALE)
tresh_c3=int(self.t8.get())
dkremovec3=int(self.t11.get())
dkrgrowc3=int(self.t14.get())
iters_grow_c3=int(self.t17.get())
kernel_noise_remove_c3=np.ones((dkremovec3, dkremovec3),np.uint8)
kernel_grow_c3=np.ones((dkrgrowc3,dkrgrowc3),np.uint8)
thresh1wga = cv2.threshold(imgc3,tresh_c3,255,cv2.THRESH_BINARY)[1]
erwga=cv2.morphologyEx(thresh1wga, cv2.MORPH_OPEN, kernel_noise_remove_c3)
gimgwga=cv2.dilate(erwga,kernel_grow_c3,iterations = iters_grow_c3)
greywga = np.copy(gimgwga)
# greywga400 = imutils.resize(greywga, width=285, height=280)
# sumaSercaWGA = cv2.add(greyserca, greywga)
restarSercaWGA = cv2.subtract(greyserca, greywga)
# sumarlostres = cv2.add(sumaSercaWGA, greycx)
restarcx= cv2.subtract(restarSercaWGA, greycx)
# sumarlostres400 = imutils.resize(sumarlostres, width=285, height=280)
restarlostres400 = imutils.resize(restarcx, width=415, height=400)
lostres = np.copy(restarlostres400)
imlostres = Image.fromarray(lostres)
imgtres = ImageTk.PhotoImage(image=imlostres)
masktres = Label(window)
masktres.configure(image=imgtres)
masktres.image = imgtres
masktres.grid(column=5, row=12, rowspan=14, columnspan=4)
def say_hi(self):
global cnt,drect,boxvv,numboxes,nvect
cnt=0
drect=[]
box=[]
# mouse callback function
def draw_trpz(event,x,y,flags,param):
global cnt,drect,boxvv,numboxes,nvect
if event == cv2.EVENT_LBUTTONDBLCLK:
print(x,y)
drect.append([x,y])
cnt=cnt+1
vect=[]
cv2.circle(subpic,(x,y),5,(255,255,255),-1)
cv2.putText(subpic,str(cnt),(x+5,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
if(cnt==nvert):
cnt=0
numboxes=numboxes+1
for i in range(0,nvert,1):
vect.append(drect[i])
box.append([np.array([vect])])
cv2.drawContours(subpic,[np.array([vect])],-1,(255,255,255),3)
cv2.drawContours(sublack,[np.array([vect])],-1,(255,255,255),-1)
cv2.drawContours(sublack,[np.array([vect])],-1,(255,0,0),1)
print(drect)
drect=[]
print('---------------------------------------------------------------------------------------------------------------')
print('--------------------------- MANUAL MASK GENERATION --------------------------------------------------------')
print('---------------------------------------------------------------------------------------------------------------')
# Start counting time seconds to evaluate total time spent by running the program
t0= tm.localtime()
# Assign args to program variables
subdx=int(self.t531.get())
subdy=int(self.t532.get())
nvert=int(self.t530.get())
gamma=float(self.t28.get())
Nim=int(self.t1.get())
idim=self.t2.get()
scale=float(self.t4.get())
inpf=self.t33.get() #".tif"
outf=self.t34.get() #".png"
numboxes=0
# Read and merge channels
if(Nim==3):
fname_c3=idim+'_c3'+inpf
fname_c2=idim+'_c2'+inpf
fname_c1=idim+'_c1'+inpf
# Overlap image:
img1 = cv2.imread(fname_c1)
img3 = cv2.imread(fname_c3)
img2 = cv2.imread(fname_c2)
comb=cv2.add(img1,img3)
comb2=cv2.add(comb,img2)
# Apply a gamma correction here
lookUpTable = np.empty((1,256), np.uint8)
for i in range(256):
lookUpTable[0,i] = np.clip(pow(i / 255.0, gamma) * 255.0, 0, 255)
img = cv2.LUT(comb2, lookUpTable)
else:
img = cv2.imread(idim+inpf)
thresh, blackAndWhiteImage = cv2.threshold(img, 0, 0, cv2.THRESH_BINARY)
cv2.imwrite("blackblack"+outf,blackAndWhiteImage)
imblack = cv2.imread("blackblack"+outf)
xs=np.shape(img)[0]
ys=np.shape(img)[1]
# definition of input image subdivision for each dymension (height, width)
dh=int(xs/subdx)
dw=int(ys/subdy)
x0=0
y0=0
for k in range(0,subdx,1):
for j in range(0,subdy,1):
subpic=np.copy(img[k*dh:(k+1)*dh,j*dw:(j+1)*dw])
sublack=np.copy(imblack[k*dh:(k+1)*dh,j*dw:(j+1)*dw])
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_trpz)
while(1):
rows, cols, _channels = map(int, subpic.shape)
cv2.imshow('image',subpic)
#k =
if cv2.waitKey(20) & 0xFF == 27:
break
cv2.destroyAllWindows()
img[k*dh:(k+1)*dh,j*dw:(j+1)*dw]=subpic
imblack[k*dh:(k+1)*dh,j*dw:(j+1)*dw]=sublack
cv2.imwrite(idim+'_mM.tif',imblack)
cv2.imwrite(idim+'_mM_overlap.tif',img)
print("************************************************************************************************************")
print("************************************************************************************************************")
t1 = tm.localtime()
print("Job time (s) : ", np.round(t1 - t0,2))
print("************************************************************************************************************")
print("************************************************************************************************************")
def run(self):
# Time initialization
t0= tm.localtime()
# Ignore warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
# Create a time dependent output folder filename format
dirstr=str(round(tm.time()))
distr=dirstr
os.mkdir("out_quantif_"+dirstr)
# Processing mode (supervised, automatic)
procmode=self.selected.get()
# Input images must be labelled as: idim_c1.tif (CM MARKER), idim_c2.tif (CX43 MARKER), idim_c3.tif (INTERSTICIUM MARKER)
# Number of input channels (3 or 1)
Nim=int(self.t1.get())
# Filename input start pattern for biomarked channels
idim=self.t2.get()
# scale
scale=float(self.t4.get())
# Input mask (y/n). If y, an input mask labelled as idim_Mm.tif must be provided as input
if(self.chk1_state.get()==True):
Inpmask='y'
else:
Inpmask='n'
if(self.chk2_state.get()==True):
equalize='y'
else:
equalize='n'
if(self.chk3_state.get()==True):
evaluate='y'
else:
evaluate='n'
# Mode of mask combination (addch/indepch):
modecomb=self.selcomb.get() #'addch'
# scale parameter (in micrometers/pixel)
eqthr=int(self.t5.get())
# Threshold set (if equalize = no):
tresh_c1=int(self.t6.get())
tresh_c2=int(self.t7.get())
tresh_c3=int(self.t8.get())
# Threshold equalization for c4 channel
eqthrcx=int(self.t5_2.get())
# Kernel window size for noise removal in c1 (parameter nr_c1)
dkremovec1=int(self.t9.get())
# kernel window size for dilate of c1 (parameter ng_c1)
dkrgrowc1=int(self.t12.get())
# Iterations for dilate in c2 (parameter ngit_c1)
iters_grow_c1=int(self.t15.get())
# Kernel window size for noise removal in c2 (parameter nr_c2)
dkremovec2=int(self.t10.get())
# kernel window size for dilate of c2 (parameter ng_c2)
dkrgrowc2=int(self.t13.get())
# Iterations for dilate in c2 (parameter ngit_c2)
iters_grow_c2=int(self.t16.get())
# Kernel window size for noise removal in c3 (parameter nr_c3)
dkremovec3=int(self.t11.get())
# kernel window size for dilate of c3 ((parameter ng_c3)
dkrgrowc3=int(self.t14.get())
# Iterations for dilate in c3 (parameter ngit_c3)
iters_grow_c3=int(self.t17.get())
# First filtered parameters
# Minimum area of retrieved contour
ff_areamin=int(self.t21.get()) #100 # squared micrometers
# Minimum perimeter of retrieved contour
ff_permin=int(self.t22.get()) #40 # micrometers
# Second filtered parameters
# Minimum lenght of CM
sf_lboxmin=int(self.t23.get()) #20 # micrometers
# Maximum lenght of CM
sf_lboxmax=int(self.t24.get()) #200 # micrometers
# Minimum width of CM
sf_wmin=int(self.t25.get()) #5 # micrometers
# Maximum width of CM
sf_wmax=int(self.t26.get()) #50 # micrometers
# Minimum aspect ratio (Lenght/Width) of CM
sf_rmin=float(self.t27.get()) #1
# Padding applied to cell enclosing rectangles as function of dilate parameters
scpad=int(self.t270.get())
pad= scpad*dkrgrowc2*iters_grow_c2
# Select specific Cardiomyocite ID (all/ID number)
select=self.t32.get()
# Plot ID numbers (y/n)
if(self.bo1_state.get()==True):
plotidnumb='y'
else:
plotidnumb='n'
# Font type in image annotations index
font = cv2.FONT_HERSHEY_SIMPLEX
# Gamma correction factor (improve brightness of merged image: >1 => darker than original)
gamma=float(self.t28.get())
# 0-3 (number of half-sized reductions for final overlaped image output, it's recommended 2 or 3 for large size input files)
redfactor=0
# Font size
fsize=2
# Contour width
contwidth= 4
# Window size for individual plots (um)
wxsize=float(self.t31.get())/scale
# Plot scale bars
scalebars='y'
# lenght of scale bar (um)
scalebarlen=float(self.t29.get())
# mini scale bar (y/n)
miniscbar='y'
# mini scale bar lenght (um)
minisbarlen=float(self.t30.get())
# Graphical output (generate (y) or not (n)):
if(self.bo2_state.get()==True):
plothist='y'
else:
plothist='n'
if(self.bo3_state.get()==True):
plotboxplot='y'
else:
plotboxplot='n'
plotdens='y'
if(self.bo4_state.get()==True):
plotcombin='y'
else:
plotcombin='n'
if(self.bo5_state.get()==True):
plotchbin='y'
else:
plotchbin='n'
if(self.bo6_state.get()==True):
plotmask='y'
else:
plotmask='n'
if(self.bo7_state.get()==True):
plotanot='y'
else:
plotanot='n'
if(self.bo8_state.get()==True):
plotissuemask='y'
else:
plotissuemask='n'
if(self.bo9_state.get()==True):
plotsepCMs='y'
else:
plotsepCMs='n'
if (plotsepCMs=='y'):
os.mkdir("out_quantif_"+dirstr+"/CMs/")
# Input format
inpf=self.t33.get() #".tif"
outf=self.t34.get() #".png"
#*************************************** END OF PARAMETER SET ********************************************
# define kernels in a proper way
kernel_noise_remove_c2 = np.ones((dkremovec2,dkremovec2),np.uint8)
kernel_grow_c2 =np.ones((dkrgrowc2,dkrgrowc2),np.uint8)
kernel_noise_remove_c1=np.ones((dkremovec1,dkremovec1),np.uint8)
kernel_grow_c1=np.ones((dkrgrowc1,dkrgrowc1),np.uint8)
kernel_noise_remove_c3 = np.ones((dkremovec3,dkremovec3),np.uint8)
kernel_grow_c3 =np.ones((dkrgrowc3,dkrgrowc3),np.uint8)
# Selective color mask (greenchannel)
up_mask_g=255
dwn_mask_g=250
f3 = open("out_quantif_"+dirstr+"/"+idim+"_"+distr+"_paramout.txt", 'w')
f2 = open("out_quantif_"+dirstr+"/"+idim+"_"+distr+"_data.csv", 'w')
if(procmode=='supervised'):
f2.write('ID,value,L(um),W(um),ang(degree),CxLat2,AreaBox(um2),Area(um2),perimeter(um),xc(pix),yc(pix),CXTOT\n')
else:
f2.write('ID,L(um),W(um),ang(degree),CxLat2,AreaBox(um2),Area(um2),perimeter(um),xc(pix),yc(pix),CXTOT\n')
# Set actual time variables
now = datetime.now()
year = now.strftime("%Y")
month = now.strftime("%m")
day = now.strftime("%d")
time = now.strftime("%H:%M:%S")
date_time = now.strftime("%Y%m%d_%H%M%S")
# Start binarization
if(Nim == 3):
fname_c3=idim+'_c3'+inpf
fname_c2=idim+'_c2'+inpf
fname_c1=idim+'_c1'+inpf
if(Nim==1):
fname=idim+inpf
neq = cv2.imread(fname,0)
if(equalize == 'y'):
img=cv2.equalizeHist(neq)
tresh_c1=eqthr
tresh_c2=254
else:
img=neq
ret,backg = cv2.threshold(img,tresh_c1,255,cv2.THRESH_BINARY)
ret,tiss = cv2.threshold(img,tresh_c1,255,cv2.THRESH_BINARY_INV)
ret,foreg = cv2.threshold(img,tresh_c2,255,cv2.THRESH_BINARY)
thresh, blackAndWhiteImage = cv2.threshold(img, 0, 0, cv2.THRESH_BINARY)
cv2.imwrite("blackback"+inpf,blackAndWhiteImage)
imgback = cv2.imread("blackback"+inpf)
imgfor = cv2.imread("blackback"+inpf)
imgtis = cv2.imread("blackback"+inpf)
imgback[:,:,2]=tiss
imgback[:,:,1]=0
imgback[:,:,0]=0
imgfor[:,:,2]=foreg
imgfor[:,:,1]=foreg
imgfor[:,:,0]=foreg
imgtis[:,:,2]=0
imgtis[:,:,1]=backg
imgtis[:,:,0]=0
cv2.imwrite(idim+"_c3"+inpf, imgback)
cv2.imwrite(idim+"_c1"+inpf, imgtis)
cv2.imwrite(idim+"_c2"+inpf, imgfor)
fname_c3=idim+'_c3'+inpf
fname_c2=idim+'_c2'+inpf
fname_c1=idim+'_c1'+inpf
# Process channel 1 (Binarization+noise removal+growth)
thresh, blackAndWhiteImage = cv2.threshold(cv2.imread(fname_c1,0), 0, 0, cv2.THRESH_BINARY)
cv2.imwrite("blackback"+inpf,blackAndWhiteImage)
imgc1 = cv2.imread(fname_c1,0)
if(equalize == 'y'):
equ=cv2.equalizeHist(imgc1)
ret,thresh1serca = cv2.threshold(equ,eqthr,255,cv2.THRESH_BINARY)
else:
ret,thresh1serca = cv2.threshold(imgc1,tresh_c1,255,cv2.THRESH_BINARY)
erserca=cv2.morphologyEx(thresh1serca, cv2.MORPH_OPEN, kernel_noise_remove_c1)
imgserca=cv2.dilate(erserca,kernel_grow_c1,iterations = iters_grow_c1)
grayserca = np.copy(imgserca) #cv2.cvtColor(imgserca, cv2.COLOR_BGR2GRAY)
# Process channel 2 (Binarization+noise removal+growth)
imgc2=cv2.imread(fname_c2,0)
if(equalize == 'y'):
equ=cv2.equalizeHist(imgc2)
ret,imgcxb2 = cv2.threshold(equ,eqthrcx,255,cv2.THRESH_BINARY)
ret,threshcx = cv2.threshold(equ,eqthrcx,255,cv2.THRESH_BINARY)
else:
ret,threshcx = cv2.threshold(imgc2,tresh_c2,255,cv2.THRESH_BINARY)
ret,imgcxb2 = cv2.threshold(cv2.equalizeHist(imgc2),eqthrcx,255,cv2.THRESH_BINARY)
ercx=cv2.morphologyEx(threshcx, cv2.MORPH_OPEN, kernel_noise_remove_c2)
imgcx=cv2.dilate(ercx,kernel_grow_c2,iterations = iters_grow_c2)
imgcxb=np.copy(imgc2)
graycx = np.copy(imgc2)
# Process channel 3 (Binarization+noise removal+growth)
imgc3 = cv2.imread(fname_c3,0)
if(equalize == 'y'):
equ=cv2.equalizeHist(imgc3)
ret,thresh1 = cv2.threshold(equ,eqthr,255,cv2.THRESH_BINARY)
else:
ret,thresh1 = cv2.threshold(imgc3,tresh_c3,255,cv2.THRESH_BINARY)
er=cv2.morphologyEx(thresh1, cv2.MORPH_OPEN, kernel_noise_remove_c3)
imgwga=cv2.dilate(er,kernel_grow_c3,iterations = iters_grow_c3)
graywga = np.copy(imgwga)#cv2.cvtColor(imgwga, cv2.COLOR_BGR2GRAY)
# Write a black background image for mask combination
thresh, blackAndWhiteImage = cv2.threshold(cv2.imread(fname_c2), 0, 0, cv2.THRESH_BINARY)
cv2.imwrite("blackback"+outf,blackAndWhiteImage)