forked from manoharan-lab/camera-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_controller_gui.py
executable file
·2092 lines (1745 loc) · 102 KB
/
camera_controller_gui.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2014, Thomas G. Dimiduk, Rebecca W. Perry, Aaron Goldfain
#
# This file is part of Camera Controller
#
# Camera Controller is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# HoloPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HoloPy. If not, see <http://www.gnu.org/licenses/>.
'''
Provides live feed from a photon focus microscope camera with
an epix frame grabber. Software built to allow extension to
other cameras.
Allows user to save images and time series of images using a
naming convention set by the user.
For the photon focus, it is assumed that the camera is set to
Constant Frame Rate using the Photon Focus Remote software. In
this mode, the camera sends out images at regular intervals
regardless of whether they are being read or not.
The timer event is for refreshing the window viewed by the user
and for timing long, slow time series captures.
.. moduleauthor:: Rebecca W. Perry <[email protected]>
.. moduleauthor:: Aaron Goldfain
.. moduleauthor:: Thomas G. Dimiduk <[email protected]>
'''
#from __future__ import print_function
import sys
import os
from PySide import QtGui, QtCore
from PIL import Image
import h5py
from multiprocessing import Process
import matplotlib
matplotlib.use('Qt4Agg')
matplotlib.rcParams['backend.qt4']='PySide'
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
from scipy.ndimage.measurements import center_of_mass
from scipy.ndimage.filters import gaussian_filter
from scipy.misc import toimage, fromimage, bytescale
import numpy as np
import time
import yaml
import json
import dummy_image_source
import epix_framegrabber
import thorcam
import thorlabs_KPZ101
from compress_h5 import compress_h5
from glob import glob
import fourier_filter as ff
import win32api
try:
import trackpy as tp
except:
print('Could not import trackpy')
try:
epix_framegrabber.Camera()
epix_available = True
except epix_framegrabber.CameraOpenError:
epix_available = False
try:
thorcam.Camera()
thorcamfs_available = True
except thorcam.CameraOpenError:
thorcamfs_available = False
try:
thorlabs_KPZ101.KPZ101()
thorlabs_KPZ101_available = True
except thorlabs_KPZ101.KPZ101OpenError:
thorlabs_KPZ101_available = False
from utility import mkdir_p
from QtConvenience import (make_label, make_HBox, make_VBox,
make_LineEdit, make_button, make_qListWidget,
make_control_group, make_checkbox,
CheckboxGatedValue, increment_textbox,
zero_textbox, textbox_int, textbox_float,
make_combobox, make_tabs)
#set default save path
default_save_path = os.path.join("C:\\", "Users", "manoharanlab", "data", "YourName")
#for iSCAT computer in the basement lab, set the default path to the SSD
if os.path.exists(os.path.join("V:\\", "data")):
if win32api.GetVolumeInformation('V:\\')[0] == 'DataSSD':
default_save_path = os.path.join("V:\\", "data", "YourName")
#TODO: construct format file outside of the image grabbing loop, only
# when someone changes bit depth or ROI
#TODO: automate changing bit depth in PFRemote with the PF Remote DLL and some command like: SetProperty("DataResolution", Value(#1)")
#TODO: tie exposure time back to PFRemote ("SetProperty( "ExposureTime",Value(22.234))
#TODO: tie frame time back to PFRemote ("SetProperty( "ExposureTime",Value(22.234))
#TODO: limit text input for x and y in ROI to integers
#TODO: make sure that in a time series, the images stop getting collected at the end of the time series-- no overwriting the beginning of the buffer
#TODO: start slow time series by capturing an image, and start that as t=0
#TODO: add light source tab
class captureFrames(QtGui.QWidget):
'''
Fill rolling buffer, then save individual frames or time series on command.
'''
def __init__(self):
if epix_available:
self.camera = epix_framegrabber.Camera()
else:
self.camera = dummy_image_source.DummyCamera()
if thorcamfs_available:
self.camera_fs = thorcam.Camera()
if thorlabs_KPZ101_available:
self.z_pstage = thorlabs_KPZ101.KPZ101()
self.x_pstage = thorlabs_KPZ101.KPZ101()
self.y_pstage = thorlabs_KPZ101.KPZ101()
super(captureFrames, self).__init__()
self.initUI()
# we have to set this text after the internals are initialized since the filename is constructed from widget values
self.update_filename()
# pretend the last save was a timeseries, this just means that
# we don't need to increment the dir number before saving the
# first timeseries
self.last_save_was_series = True
QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Q"), self, self.close)
def initUI(self):
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
#Timer is for updating for image display and text to user
self.timerid = self.startTimer(30) # event every x ms
self.cameraNum = 0 # to keep track of which camera is in use
#display for image coming from camera
self.frame = QtGui.QLabel(self)
self.frame.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft)
self.feedback_measure = 0.0
self.fb_sum = 0.0
self.x_fit = 0.0
self.y_fit = 0.0
#########################################
# Tab 1, Main controls viewing/saving
#########################################
self.livebutton = make_button('Live\nf1', self.live, self, QtGui.QKeySequence('f1'))
self.livebutton.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.freeze = make_button('Freeze\nf2', self.live, self, QtGui.QKeySequence('f2'))
self.freeze.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.save = make_button(
'Save\nesc', self.save_image, self, QtGui.QKeySequence('esc'), width=150,
tooltip='Saves the frame that was current when this button was clicked. Freeze first if you want the frame to stay visible.')
self.save.setCheckable(True)
self.save.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.increment_dir_num = make_button(
'Increment dir number', self.next_directory, self, width=150,
tooltip='switch to the next numbered directory (if using numbered directories). Use this for example when switching to a new object')
self.save_raw_epix_buffer = make_checkbox("Save raw EPIX Buffer? (Large time series (<~1 GB) save quicker but must be\nre-saved as hdf5 files. See the Filenames tab for more info.)")
self.timeseries = make_button('Collect and Save\nTime Series',
self.collectTimeSeries, self, QtGui.QKeySequence('f3'), width=200)
self.timeseries.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.timeseries.setCheckable(True)
self.timeseries_slow = make_button('Collect and Save\nSlow Time Series (<= 1 fps)',
self.collectTimeSeries, self, QtGui.QKeySequence('f4'), width=200)
self.timeseries_slow.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.timeseries_slow.setCheckable(True)
self.save_buffer = make_button('Time machine!',
self.collectTimeSeries, self, QtGui.QKeySequence('f12'), width=200)
self.save_buffer.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.save_buffer.setCheckable(True)
make_control_group(self, [self.livebutton, self.freeze],
default=self.livebutton)
#TODO: fix control group, should you be allowed to do multiple at once?
#make_control_group(self, [self.save, self.timeseries, self.timeseries_slow])
self.numOfFrames = make_LineEdit('10', width=75)
self.numOfFrames2 = make_LineEdit('10', width=75)
self.interval = make_LineEdit('0.5', width=75)
self.outfiletitle = QtGui.QLabel()
self.outfiletitle.setText('Your next image will be saved as\n(use filenames tab to change):')
self.outfiletitle.setFixedHeight(50)
self.outfiletitle.setWordWrap(True)
self.outfiletitle.setStyleSheet('font-weight:bold')
self.path = make_label("")
tab1_item_list = [make_HBox([self.livebutton, self.freeze,1]),
1,
'Save image showing when clicked',
make_HBox([self.save, self.increment_dir_num]),
1,
self.save_raw_epix_buffer,
1,
'Store the requested number of images to the buffer and then save the files to hard disk. \n\nThe frame rate is set in the Photon Focus Remote software.',
make_HBox([self.timeseries, self.numOfFrames, 'frames', 1]),
1,
'Equivalent to clicking "Save" at regular intervals',
make_HBox([self.timeseries_slow,
make_VBox([make_HBox([self.numOfFrames2, 'frames', 1]),
make_HBox([self.interval, 'minutes apart', 1])])]),
1,
"Save buffer",
make_HBox([self.save_buffer, self.increment_dir_num]),
self.outfiletitle,
self.path]
if thorcamfs_available and thorlabs_KPZ101_available:
self.stage_serialNo = make_LineEdit('29500244',width=60)
self.close_open_stage_but = make_button('Open\nStage', self.close_open_stage)
self.get_z_zero_but = make_button('Set Zero', self.get_z_zero, width = 60, height = 20)
self.v_out = make_label('NA',bold = True,width=40)
self.v_out.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
#self.v_out.editingFinished.connect(self.change_output_voltage)
self.v_inc_but = make_button("+", self.inc_output_voltage, width = 20, height = 20)
self.v_dec_but = make_button("-", self.dec_output_voltage, width = 20, height = 20)
self.v_step = make_LineEdit('NA',width=40)
self.v_step.editingFinished.connect(self.change_step_voltage)
self.lock_pos_box = make_checkbox("Lock Stage Position", callback = self.set_lock_pos)
self.reset_zpos_but = make_button("Reset Z-Position", self.reset_zpos, width = 100, height = 30)
self.reset_zpos_but.setEnabled(False)
self.feedback_measure_disp = make_label('')
self.fb_measure_to_voltage = make_LineEdit('0',width=40)
self.max_spot_int_but = make_button('Maximize\nIntensity')
self.max_spot_int_but.setCheckable(True)
self.max_spot_int_but.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.spot_diam = make_LineEdit('3',width=20)
self.v_focus_range = make_LineEdit('5.0',width=30)
tab1_item_list = tab1_item_list + [make_label('____________________________________________', height=15, width = 300),
make_HBox([make_label('Z Stage Driver SN:', bold=True, height=15, align='top'), self.stage_serialNo,
self.close_open_stage_but, self.get_z_zero_but, 1]),
make_HBox([make_label('Stage Output Voltage: ', bold=True, height=15, width = 130, align='top'), self.v_out,
make_label('%', bold=True, height=15, align='top'),
make_VBox([self.v_inc_but, self.v_dec_but,1]),
make_label('Step:', bold=True, height=15, align='top'), self.v_step,
make_label('%', bold=True, height=15, align='top'), 1]),
make_HBox([make_label('Feedback-Volts Conversion:', bold=True, height=15, width = 160, align='top'), self.fb_measure_to_voltage, 1]),
make_HBox([self.lock_pos_box, self.reset_zpos_but, 1]),
self.feedback_measure_disp,
make_HBox([self.max_spot_int_but,
make_VBox( [make_HBox([make_label('Spot Diameter (Pixels):', bold=True, height=15, width = 140, align='top'), self.spot_diam, 1]),
make_HBox([make_label('V Range (%):', bold=True, height=15, width = 80, align='top'), self.v_focus_range, 1]),
1]), 1]) ]
tab1 = ("Image Capture", tab1_item_list+[1])
###################################################################
# Tab 2, camera settings need to be set in Photon Focus remote too
###################################################################
cameras = ["Simulated"]
if epix_available:
cameras = ["PhotonFocus", "Basler"] + cameras
if thorcamfs_available:
cameras.append("ThorCam FS")
self.buffersize = make_LineEdit('1000',callback=self.revise_camera_settings,width=80) #number of images kept in rolling buffer
self.camera_choice = make_combobox(cameras, self.change_camera, width=150)
#if thorcamfs_available:
#self.camera_choice.model().item(cameras.index("ThorCam FS")).setEnabled(False)
self.bitdepth_choice = make_combobox(['temp'],
callback=self.revise_camera_settings, default=0, width=150)
self.roi_size_choice = make_combobox(['temp'],
callback=self.revise_camera_settings, default=0, width=150)
self.roi_pos_choicex = make_LineEdit('0',width=60)
self.roi_pos_choicey = make_LineEdit('0',width=60)
self.roi_pos_choicex.editingFinished.connect(self.change_roi_pos)
self.roi_pos_choicey.editingFinished.connect(self.change_roi_pos)
self.posx_inc_but = make_button("+", self.roi_posx_inc, width = 20, height = 20)
self.posx_dec_but = make_button("-", self.roi_posx_dec, width = 20, height = 20)
self.posy_inc_but = make_button("+", self.roi_posy_inc, width = 20, height = 20)
self.posy_dec_but = make_button("-", self.roi_posy_dec, width = 20, height = 20)
self.exposure = make_LineEdit('NA',width=60)
self.exposure.editingFinished.connect(self.change_exposure)
self.frametime = make_LineEdit('NA',width=60)
self.frametime.editingFinished.connect(self.change_frametime)
self.framerate = make_LineEdit('NA',width=60)
self.framerate.editingFinished.connect(self.change_framerate)
self.get_black_image = make_button('Get', self.set_black_image, height = 20)
self.apply_black_image = make_checkbox("Apply", callback = self.set_black_correction)
self.apply_black_image.setEnabled(False)
self.show_black_image = make_checkbox("Show", callback = self.uncheck_show_grey)
self.show_black_image.setEnabled(False)
self.get_grey_image = make_button('Get', self.set_grey_image, height = 20)
self.apply_grey_image = make_checkbox("Apply", callback = self.set_grey_correction)
self.apply_grey_image.setEnabled(False)
self.show_grey_image = make_checkbox("Show", callback = self.uncheck_show_black)
self.show_grey_image.setEnabled(False)
i = 0
opened = False
while i < len(cameras) and not opened:
self.camera_choice.setCurrentIndex(i)
try:
self.change_camera(self.camera_choice.currentText())
opened = True
except epix_framegrabber.CameraOpenError:
i = i+1
if not opened:
print("failed to open a camera")
tab2_item_list = ["Modify Camera Settings",
make_HBox([make_VBox([make_label("Camera:", bold=True) ,self.camera_choice,1]),
make_VBox([make_label("Bit Depth:", bold=True), self.bitdepth_choice,1]), 1]),
"Must match the data output type in camera manufacturer's software",
make_label("Region of Interest Size:", bold=True,
align='bottom', height=30),
'Frame size in pixels. Default to maximum size.\nRegions are taken from top left.\nWant a different size? Make a new format file.',
self.roi_size_choice,
make_HBox([make_label('X ', bold=True, height=15, align='top'), self.roi_pos_choicex,
make_VBox([self.posx_inc_but, self.posx_dec_but,1]),
make_label('Y ', bold=True, height=15, align='top'), self.roi_pos_choicey,
make_VBox([self.posy_inc_but, self.posy_dec_but,1]), 1]),
make_HBox([make_label('Exposure Time (ms):', bold=True, height=15, align='top'), self.exposure, 1]),
make_HBox([make_label('Frame Time (ms):', bold=True, height=15, align='top'), self.frametime,
make_label('Frame Rate (Hz):', bold=True, height=15, align='top'), self.framerate, 1]),
make_HBox([make_label('Rolling Buffer Size (# images):', bold=True, height=15, width=180, align='top'), self.buffersize, 1]),
make_label('Black and Grey Image Corrections:', bold = True),
make_HBox([make_label('Black Correction:'), self.get_black_image, self.apply_black_image, self.show_black_image,1]),
make_HBox([make_label('Grey Correction:'), self.get_grey_image, self.apply_grey_image, self.show_grey_image,1])]
if thorcamfs_available and thorlabs_KPZ101_available:
self.config_thorcam_fs = make_checkbox("Set ThorCam FS Camera Parameters", callback = self.switch_configurable_camera)
self.close_open_thorcam_fs_but = make_button('Open\nThorCam FS', self.close_open_thorcam_fs)
self.fb_measure_figure = plt.figure(figsize=[2,4])
self.fb_measure_ax = self.fb_measure_figure.add_subplot(111)
self.fb_measure_ax.hold(False) #discard old plots
self.fb_measure_canvas = FigureCanvas(self.fb_measure_figure)
tab2_item_list.insert(1, make_HBox([self.config_thorcam_fs, self.close_open_thorcam_fs_but,1]) )
tab2_item_list = tab2_item_list +[make_label('\nFeedback Measure vs. time/(30 ms)', bold=True, height=30, align='top'),
self.fb_measure_canvas]
tab2 = ("Camera", tab2_item_list+[1])
#########################################
# Tab 3, Options for saving output files
#########################################
# fileneame
fileTypeLabel = make_label('Output File Format:', bold=True, height=30,
align='bottom')
self.outputformat = make_combobox(['.tif'], callback=self.update_filename, width=150)
self.include_filename_text = CheckboxGatedValue(
"Include this text:", make_LineEdit("image"), self.update_filename,
True)
self.include_current_date = CheckboxGatedValue(
"include date", lambda : time.strftime("%Y-%m-%d_"),
callback=self.update_filename)
self.include_current_time = CheckboxGatedValue(
"include time", lambda : time.strftime("%H_%M_%S_"),
callback=self.update_filename)
self.include_incrementing_image_num = CheckboxGatedValue(
"include an incrementing number, next is:", make_LineEdit('0000'),
self.update_filename, True)
# Directory
self.browse = make_button("Browse", self.select_directory, self,
height=30, width=100)
self.root_save_path = make_LineEdit(
os.path.join(default_save_path),
self.update_filename)
self.include_dated_subdir = CheckboxGatedValue(
"Use a dated subdirectory", lambda : time.strftime("%Y-%m-%d"),
self.update_filename, True)
self.include_incrementing_dir_num = CheckboxGatedValue(
"include an incrementing number, next is:", make_LineEdit('00'),
self.update_filename, True)
self.include_extra_dir_text = CheckboxGatedValue(
"use the following text:", make_LineEdit(None), self.update_filename)
self.saveMetaYes = make_checkbox('Save metadata as yaml file when saving image?')
self.outfile = make_label("", height=50, align='top')
self.reset = make_button("Reset to Default values", self.resetSavingOptions, self, height=None, width=None)
self.path_example = make_label("")
self.epix_buffer_qlist = make_qListWidget(True, height = 100)
self.convert_epix_buffer_but = make_button("Convert Selected Epix Buffers", self.convert_selected_epix_buffers, self,
height=30, width=200)
self.remove_epix_buffer_but = make_button("Remove Selected Buffers", self.remove_selected_epix_buffers, self,
height=20, width=150)
self.add_epixbuffer_but = make_button("Add Buffer", self.add_epixbuffer, self, height=None, width=70)
self.browse_epixbuffer = make_button("Browse", self.select_epixbuffer, self, height=None, width=50)
self.epixbuffer_path = make_LineEdit(self.root_save_path.text())
tab3 = ("Filenames",
[make_label(
'Select the output format of your images and set up automatically '
'generated file names for saving images',
height=50, align='top'),
make_label('File Name:', bold=True, align='bottom', height=30),
make_HBox(["Image type", self.outputformat]),
self.include_filename_text,
self.include_current_date,
self.include_current_time,
self.include_incrementing_image_num,
######
make_label('Directory:', bold=True, height=30, align='bottom'),
self.browse,
self.root_save_path,
self.include_dated_subdir,
self.include_incrementing_dir_num,
self.include_extra_dir_text,
1,
self.saveMetaYes,
make_label("If you save an image with these settings it will be saved as:", height=50, bold=True, align='bottom'),
self.path_example,
1,
self.reset,
make_label('____________________________________________', height=15, width = 300),
make_label("Convert EPIX buffers to hdf5 files:", height=20, bold=True, align='bottom'),
make_label("Camera will be unusable during conversion.\nAll unconverted buffers in this list are converted when this program is closed.", height=25, align='bottom'),
self.epix_buffer_qlist,
make_HBox([self.convert_epix_buffer_but,self.remove_epix_buffer_but]),
make_label("Add buffer to list (for buffers that did not get properly converted):", height=20, align='bottom'),
make_HBox([self.add_epixbuffer_but,self.epixbuffer_path,self.browse_epixbuffer])])
# TODO: make this function get its values from the defaults we give things
# self.resetSavingOptions() #should set file name
################################
# Tab 4, place to enter metadata
################################
self.microSelections = make_combobox(["Uberscope", "Mgruberscope",
"George", "Superscope", "iSCAT",
"Other (edit to specify)"],
width=250,
editable=True)
self.lightSelections = make_combobox(["660 nm Red Laser",
"405 nm Violet Laser",
"White LED Illuminator",
"Nikon White Light",
"Dic", "Other (edit to specify)"],
width=250,
editable=True)
self.objectiveSelections = make_combobox(
["60x Nikon, Water Immersion, Correction Collar:",
"100x Nikon, Oil Immersion",
"10x Nikon, air",
"40x Nikon, air",
"?x Other: (edit to specify)"],
editable=True)
self.tubeYes = make_checkbox("Yes")
self.metaNotes = QtGui.QLineEdit()
self.saveMetaData = make_button("Save Metadata to Yaml", self.save_metadata, height=30, width=200)
tab4 = ("Metadata",
[make_label('User supplied metadata can be saved with button here, or alongside every image with a setting on the filenames tab', height=50, align='top'),
make_label('Microscope:', bold=True, height=30, align='bottom'),
self.microSelections,
make_label("Light source:", bold=True, height=30, align='bottom'),
self.lightSelections,
make_label('Microscope Objective:', bold=True, height=30, align='bottom'),
self.objectiveSelections,
make_HBox([
make_label("Using additional 1.5x tube lens?", bold=True),
self.tubeYes, 1]),
make_label('Notes (e.g. details about your sample):',
height=30, align='bottom', bold=True),
self.metaNotes,
self.saveMetaData])
################################
# Tab 5, Overlays
################################
self.edgeEntry = make_LineEdit(width=40)
def make_color_combobox():
return make_combobox(["Red", "Green", "Blue"], width=50, default=1)
def make_pixel_entry():
#TODO: do some kind of checking to make sure it is numeric
return make_LineEdit(width=37)
self.cornerRowEntry = make_pixel_entry()
self.cornerColEntry = make_pixel_entry()
self.sqcolor = make_color_combobox()
self.diamEntry = QtGui.QLineEdit()
self.centerRowEntry = make_pixel_entry()
self.centerColEntry = make_pixel_entry()
self.circolor = make_color_combobox()
self.meshSizeEntry = make_pixel_entry()
self.gridcolor = make_color_combobox()
tab5 = ("Overlays",
[make_label("Square", height=20, align='bottom', bold=True),
make_HBox(["Edge Length (pixels):", self.edgeEntry, 1]),
make_HBox(["Upper Left Corner Location (row, col):",
self.cornerRowEntry, self.cornerColEntry, self.sqcolor]),
make_label("Circle:", bold=True, height=30, align='bottom'),
make_HBox(["Diameter (pixels):", self.diamEntry]),
make_HBox(["Center Location (row, col)", self.centerRowEntry,
self.centerColEntry, self.circolor]),
make_label("Grid:", height=30, align='bottom', bold=True),
make_HBox(["Grid Square Size (pixels)", self.meshSizeEntry,
self.gridcolor]),
1])
################################
# Tab 6, x-y active stabilization
################################
if thorlabs_KPZ101_available:
self.get_xy_stab = make_checkbox("Get XY Image", callback = self.init_get_xy_stab)
self.show_xy_stab = make_checkbox("Show Image", callback = self.init_show_xy_stab)
self.xypos_navg = make_LineEdit('33',width=40)
self.xypos_navg.editingFinished.connect(self.init_get_xy_stab)
self.xy_get_background_but = make_button('Get Bkgd', self.get_xy_background, self, width=60, height = 20)
self.xy_get_background_but.setCheckable(True)
self.stab_roi_size = make_LineEdit('16',width=40)
self.stab_roi_size.editingFinished.connect(self.init_get_xy_stab)
self.stab_roi_x = make_LineEdit('0',width=40)
self.stab_roi_y = make_LineEdit('0',width=40)
self.stabsize_inc_but = make_button("+", self.stab_possize_inc, width = 20, height = 20)
self.stabsize_dec_but = make_button("-", self.stab_possize_dec, width = 20, height = 20)
self.stabx_inc_but = make_button("+", self.stab_posx_inc, width = 20, height = 20)
self.stabx_dec_but = make_button("-", self.stab_posx_dec, width = 20, height = 20)
self.staby_inc_but = make_button("+", self.stab_posy_inc, width = 20, height = 20)
self.staby_dec_but = make_button("-", self.stab_posy_dec, width = 20, height = 20)
self.bright_dark_spot = make_checkbox("Dark?")
self.bright_dark_spot.setChecked(True)
self.fit_diam = make_LineEdit('9',width=20)
self.center_tol = make_LineEdit('0.5', width = 20)
self.bp_small_size = make_LineEdit('1',width=20)
self.bp_small_size.editingFinished.connect(self.init_get_xy_stab)
self.bp_large_size = make_LineEdit('7',width=20)
self.bp_large_size.editingFinished.connect(self.init_get_xy_stab)
self.xstage_serialNo = make_LineEdit('29501020',width=60)
self.ystage_serialNo = make_LineEdit('29501025',width=60)
self.close_open_xystage_but = make_button('Open\nStages', self.close_open_xystage)
self.get_xy_zero_but = make_button('Set Zero', self.get_xy_zero, width = 60, height = 20)
self.x_v_out = make_label('NA',bold = True,width=40)
self.x_v_out.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
self.y_v_out = make_label('NA',bold = True,width=40)
self.y_v_out.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
self.x_v_inc_but = make_button("+", self.x_inc_output_voltage, width = 20, height = 20)
self.x_v_dec_but = make_button("-", self.x_dec_output_voltage, width = 20, height = 20)
self.y_v_inc_but = make_button("+", self.y_inc_output_voltage, width = 20, height = 20)
self.y_v_dec_but = make_button("-", self.y_dec_output_voltage, width = 20, height = 20)
self.xy_v_step = make_LineEdit('NA',width=40)
self.xy_v_step.editingFinished.connect(self.change_xystep_voltage)
self.xpos_to_voltage = make_LineEdit('0.0',width=40)
self.ypos_to_voltage = make_LineEdit('0.0',width=40)
self.lock_xypos_box = make_checkbox("Lock XY Position", callback = self.set_lock_xypos)
self.reset_xy_pos_but = make_button("Reset XY", self.reset_xy_pos, width = 60, height = 20)
self.reset_xy_pos_but.setEnabled(False)
self.x_fit_disp = make_label('', width = 80)
self.y_fit_disp = make_label('', width = 80)
self.xfit_figure = plt.figure(figsize=[2,3])
self.xfit_ax = self.xfit_figure.add_subplot(111)
self.xfit_ax.hold(False) #discard old plots
self.xfit_canvas = FigureCanvas(self.xfit_figure)
self.yfit_figure = plt.figure(figsize=[2,3])
self.yfit_ax = self.yfit_figure.add_subplot(111)
self.yfit_ax.hold(False) #discard old plots
self.yfit_canvas = FigureCanvas(self.yfit_figure)
tab6 = ("XY-Stab",
[make_HBox([self.get_xy_stab, self.show_xy_stab, make_label('Frame Med:', height=15, align='top'), self.xypos_navg, self.xy_get_background_but,1]),
make_label("Region of Interest (from main camera image):", height=20, align='bottom', bold=True),
make_HBox([make_label('Width/Height:', bold=True, height=15, align='top'), self.stab_roi_size,
make_VBox([self.stabsize_inc_but, self.stabsize_dec_but,1]),
make_label('X:', bold=True, height=15, align='top'), self.stab_roi_x,
make_VBox([self.stabx_inc_but, self.stabx_dec_but,1]),
make_label('Y:', bold=True, height=15, align='top'), self.stab_roi_y,
make_VBox([self.staby_inc_but, self.staby_dec_but,1]),1]),
make_HBox([make_label('Fit Params:', bold=True, height=15, align='top'), self.bright_dark_spot,
make_label('Diam (px):', height=15, align='top'), self.fit_diam,
make_label('BP lims:', height=15, align='top'), self.bp_small_size, self.bp_large_size,
make_label('Cen. Tol.:', height=15, align='top'), self.center_tol, 1]),
make_HBox([make_label('Piezo Drivers\nSerial #\'s', bold=True, height=30, width = 80, align='top'),
make_VBox([make_label('X:', bold=True, height=15, width = 20, align='top'), make_label('Y:', bold=True, height=15, width = 20, align='top'),1]),
make_VBox([self.xstage_serialNo, self.ystage_serialNo,1]),
self.close_open_xystage_but, self.get_xy_zero_but, 1]),
make_HBox([make_label('Stage Voltages X:', bold=True, height=15, width = 110, align='top'), self.x_v_out,
make_label('%', bold=True, height=15, align='top'), make_VBox([self.x_v_inc_but, self.x_v_dec_but,1]),
make_label('Y:', bold=True, height=15, align='top'), self.y_v_out, make_label('%', bold=True, height=15, align='top'),
make_VBox([self.y_v_inc_but, self.y_v_dec_but,1]),
make_label('Step:', bold=True, height=15, align='top'), self.xy_v_step, 1]),
make_HBox([make_label('Position-To-Volts Conversion:', bold=True, height=15, width = 180, align='top'), make_label('X: ',height=15),
self.xpos_to_voltage, make_label('Y: ',height=15), self.ypos_to_voltage, 1]),
make_HBox([self.lock_xypos_box, self.reset_xy_pos_but, self.x_fit_disp, self.y_fit_disp,1]),
make_label('\nX Fit vs. Time', bold=True, height=30, align='top'),
self.xfit_canvas,
make_label('\nY Fit vs. Time', bold=True, height=30, align='top'),
self.yfit_canvas,
1])
################################################
tab_widget = [tab1, tab2, tab3, tab4, tab5]
if thorlabs_KPZ101_available:
tab_widget = [tab1, tab2, tab6, tab3, tab4, tab5]
tab_widget = make_tabs(tab_widget)
#Text at bottom of screen
self.imageinfo = QtGui.QLabel()
self.imageinfo.setText('Max pixel value: '+str(0))
self.imageinfo.setFont("Arial") #monospaced font avoids flickering
#self.imageinfo.setStyleSheet('font-weight:bold')
self.imageinfo.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft)
#contrast scaling stuff
self.contrastminlabel = QtGui.QLabel()
self.contrastminlabel.setText('Min Contrast Value:')
self.contrastminlabel.setFont("Arial") #monospaced font avoids flickering
self.contrastminlabel.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft)
self.contrastmaxlabel = QtGui.QLabel()
self.contrastmaxlabel.setText('Max Contrast Value:')
self.contrastmaxlabel.setFont("Arial") #monospaced font avoids flickering
self.contrastmaxlabel.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft)
self.minpixval = make_LineEdit('0', width=75)
self.maxpixval = make_LineEdit('255', width=75)
self.contrast_autoscale = make_checkbox("Autoscale Contrast")
self.contrast_default = make_button('Default Contrast', self.set_default_contrast, self, height = 20)
#moving average
self.movavglabel = QtGui.QLabel()
self.movavglabel.setText('# Mov. Avg. Frames (30 ms ft):')
self.movavglabel.setFont("Arial") #monospaced font avoids flickering
self.movavglabel.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft)
self.nmovavg = make_LineEdit('1', width=30, callback = self.new_mov_avg)
self.applymovavg = make_button('Apply Mov. Avg.', self.new_mov_avg, self, width=100, height = 20)
self.applymovavg.setCheckable(True)
self.applymovavg.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
#background
self.bkgdlabel = QtGui.QLabel()
self.bkgdlabel.setText(' | ')
self.bkgdlabel.setFont("Arial") #monospaced font avoids flickering
self.applybackground = make_button('Apply Background',
self.select_background, self, width=100, height = 20)
self.applybackground.setCheckable(True)
self.applybackground.setStyleSheet("QPushButton:checked {background-color: green} QPushButton:pressed {background-color: green}")
self.background_image_filename = make_label("No background applied")
self.background_image = None
self.divide_background = make_checkbox("Divide Bkgd", callback = self.check_contrast_autoscale)
self.get_bkgd_from_file = make_checkbox("Get Bkgd From File")
self.sphObject = QtGui.QLabel(self)
self.sphObject.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft)
self.sphObject.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
self.schemaObject = QtGui.QLabel(self)
self.schemaObject.setWordWrap(True)
self.schemaObject.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
self.warning = QtGui.QLabel(self)
self.warning.setText('')
self.warning.setStyleSheet('font-size: 20pt; color: red')
self.warning.setGeometry(30,300,350,100)
self.warning.setWordWrap(True)
#show live images when program is opened
self.live()
#################
#MASTER LAYOUT
#################
#puts all the parameter adjustment buttons together
vbox = QtGui.QVBoxLayout()
vbox.addWidget(tab_widget)
vbox.addStretch(1)
contentbox = QtGui.QHBoxLayout()
contentbox.addWidget(self.frame) #image
contentbox.addLayout(vbox)
contrastbox = QtGui.QHBoxLayout()
contrastbox.addWidget(self.contrastminlabel)
contrastbox.addWidget(self.minpixval)
contrastbox.addWidget(self.contrastmaxlabel)
contrastbox.addWidget(self.maxpixval)
contrastbox.addWidget(self.contrast_autoscale)
contrastbox.addWidget(self.contrast_default)
contrastbox.addWidget(self.movavglabel)
contrastbox.addWidget(self.nmovavg)
contrastbox.addWidget(self.applymovavg)
contrastbox.addWidget(self.bkgdlabel)
contrastbox.addWidget(self.applybackground)
#contrastbox.addWidget(self.background_image_filename)
contrastbox.addWidget(self.divide_background)
contrastbox.addWidget(self.get_bkgd_from_file)
contrastbox.addStretch(1)
textbox = QtGui.QVBoxLayout()
textbox.addWidget(self.imageinfo)
textbox.addStretch(1)
largevbox = QtGui.QVBoxLayout()
largevbox.addLayout(contentbox)
largevbox.addStretch(1)
largevbox.addLayout(contrastbox)
largevbox.addLayout(textbox)
self.setLayout(largevbox)
self.setGeometry(10, 50, 800, 800) #window size and location
self.setWindowTitle('Camera Controller')
self.show()
def timerEvent(self, event):
#obtain most recent image
frame_number = self.camera.get_frame_number()
if thorcamfs_available and thorlabs_KPZ101_available and self.config_thorcam_fs.isChecked() and self.close_open_thorcam_fs_but.text() == 'Close\nThorCam FS' and not self.show_xy_stab.isChecked():
use_thorcam_fs = True
else:
use_thorcam_fs = False
if self.show_black_image.isChecked():
self.image = np.array(self.black_image)
elif self.show_grey_image.isChecked():
self.image = np.array(self.grey_image)
else: #display normal image
n_mov_avg = textbox_float(self.nmovavg) #get number of frames to use in moving average
if self.applymovavg.isChecked() and n_mov_avg > 1:
#self.avg_number is current position in rolling buffer
if self.avg_number == None: # if this is the start of a new moving average
self.avg_number = 0
self.avg_images = np.zeros((self.image.shape[0],self.image.shape[1], int(n_mov_avg)))
self.image = np.zeros((self.image.shape[0],self.image.shape[1]))
if use_thorcam_fs:
self.avg_images[:,:,int(self.avg_number)] = self.camera_fs.get_image()
else:
self.avg_images[:,:,int(self.avg_number)] = self.camera.get_image()
if self.avg_initiating:
#add each image with the appropriate weight
self.image = self.image*(1-1.0/(self.avg_number+1)) + self.avg_images[:,:,int(self.avg_number)]/float(self.avg_number+1)
if self.avg_number == int(n_mov_avg)-1:
self.avg_initiating = False
else:
#add new image and subtract oldest image
self.image = self.image + (self.avg_images[:,:,int(self.avg_number)] - self.avg_images[:,:,int((self.avg_number+1)%n_mov_avg)])/n_mov_avg
self.avg_number = (self.avg_number + 1)%n_mov_avg
else:#if no moving average is used
if use_thorcam_fs:
self.image = self.camera_fs.get_image()
else:
self.image = self.camera.get_image()
#apply black and grey corrections
#note that normal time series will be saved wihout black and grey corrections
#However, if using the "Save" and "Slow time series" buttons the datea will be saved with these corrections!
#corrections are done as described in the photon focus user manual.
if self.apply_black_image.isChecked():
self.image = self.image-self.black_correction
if self.apply_grey_image.isChecked():
self.image = self.image*self.grey_correction
if self.bit_depth == 8: maxval = 255
elif self.bit_depth > 8: maxval = 65535
self.image.clip(0,maxval, self.image)
#get image to use for xy_stabilization
if thorlabs_KPZ101_available and self.get_xy_stab.isChecked():
x_pos = textbox_int(self.stab_roi_x)
y_pos = textbox_int(self.stab_roi_y)
image_size = textbox_int(self.stab_roi_size)
xy_navg = textbox_int(self.xypos_navg)
if image_size <= 0 or image_size >= self.image.shape[0]:
image_size = self.image.shape[0]
self.xy_stab_image_med[:,:,self.xy_stab_image_number] = self.camera.get_image()[y_pos:y_pos+image_size, x_pos:x_pos+image_size]
if self.xy_stab_image_number == xy_navg-1: #update output image
self.xy_stab_image = np.median(self.xy_stab_image_med, 2)
if self.xy_get_background_but.isChecked():
self.xy_stab_image = self.xy_stab_image-(self.xy_background_image-15000) # the "-15000" is so that there are not negative numbers. (data types are unsigned)
if self.bp_mask != None:
self.xy_stab_image = ff.fourier_filter2D(self.xy_stab_image, self.bp_mask)
self.xy_stab_image_number = (self.xy_stab_image_number + 1)%xy_navg
#show most recent image
self.showImage()
#show info about this image
def set_imageinfo():
maxval = int(self.image.max())
height = len(self.image)
width = np.size(self.image)/height
portion = round(np.sum(self.image == maxval)/(1.0*np.size(self.image)),3)
if self.contrast_autoscale.isChecked():
is_autoscaled=", Contrast Autoscaled"
else:
is_autoscaled=""
imageinfo_text = 'Camera Controller Version 0.0.1, Image Size: {}x{}, Max pixel value: {}, Fraction at max: {}, Frame number in buffer: {}{}'.format(
width,height, maxval, portion, frame_number, is_autoscaled)
if self.timeseries_slow.isChecked():
imageinfo_text = imageinfo_text + ', Slow Time Series Frame: ' +str(textbox_int(self.include_incrementing_image_num))
self.imageinfo.setText(imageinfo_text)
set_imageinfo()
if self.timeseries_slow.isChecked():
if (textbox_int(self.include_incrementing_image_num) *
textbox_float(self.interval) * 60) <= time.time()-self.slowseries_start:
self.save_image()
if textbox_int(self.include_incrementing_image_num) >= textbox_int(self.numOfFrames2):
self.timeseries_slow.setChecked(False)
if thorcamfs_available and thorlabs_KPZ101_available and self.close_open_stage_but.text() == 'Close\nStage':
np.savetxt(self.filename()+'_VOutHistory.txt', self.v_out_history, header = 'z_COM z_voltage(%) z_sum')
if self.close_open_xystage_but.text() == 'Close\nStages':
np.savetxt(self.filename()+'_VOutXYHistory.txt', self.v_out_xyhistory, header = 'x_fit(px) y_fit(px) x_voltage(%) y_voltage(%)')
self.next_directory()
#check if a time series to save has been finished collecting:
if self.timeseries.isChecked():
if self.camera.finished_live_sequence():
time.sleep(0.1)
set_imageinfo()
self.freeze.toggle()
mkdir_p(self.save_directory())
write_timeseries(self.filename(), range(1, 1 + textbox_int(self.numOfFrames)),
self.metadata, self, self.save_raw_epix_buffer.isChecked(), True)
if thorcamfs_available and thorlabs_KPZ101_available and self.close_open_stage_but.text() == 'Close\nStage':
np.savetxt(self.filename()+'_VOutHistory.txt', self.v_out_history, header = 'z_COM z_voltage(%) z_sum')
if self.close_open_xystage_but.text() == 'Close\nStages':
np.savetxt(self.filename()+'_VOutXYHistory.txt', self.v_out_xyhistory, header = 'x_fit(px) y_fit(px) x_voltage(%) y_voltage(%)')
increment_textbox(self.include_incrementing_image_num)
self.next_directory()
self.timeseries.setChecked(False)
self.revise_camera_settings() #prevents odd bug where raw buffers with 1488-1532 frames won't save to disk
self.livebutton.setChecked(True)
self.live()
#for back-saving the contents of the rolling buffer
if self.save_buffer.isChecked():
self.freeze.setChecked(True)
self.live() #this processes that the freeze button was checked
time.sleep(0.1)
set_imageinfo()
mkdir_p(self.save_directory())
lastframe = self.camera.get_frame_number()
imagenums = []
for i in range(lastframe+2,textbox_int(self.buffersize)+1) + range(1,lastframe+2):
#chonological
imagenums.append(i)
write_timeseries(self.filename(), imagenums, self.metadata, self, self.save_raw_epix_buffer.isChecked(), True)
self.next_directory()
self.save_buffer.setChecked(False)
self.revise_camera_settings() #prevents odd bug where raw buffers with 1488-1532 frames won't save to disk
self.livebutton.setChecked(True)
self.live()
#update stage position for focus stabilization
if thorcamfs_available and thorlabs_KPZ101_available:
if self.close_open_xystage_but.text() == 'Close\nStages':
self.update_xy_output_voltage()
if self.close_open_stage_but.text() == 'Close\nStage':
self.update_output_voltage()
if self.lock_pos_box.isChecked():
self.correct_stage_voltage()
if self.lock_xypos_box.isChecked():
self.correct_xystage_voltage()
if self.timeseries.isChecked() or self.timeseries_slow.isChecked():
self.v_out_history.append(np.array([self.feedback_measure, self.z_pstage.stage_output_voltage, self.fb_sum]))
if self.close_open_xystage_but.text() == 'Close\nStages':
self.v_out_xyhistory.append(np.array([self.x_fit, self.y_fit, self.x_pstage.stage_output_voltage, self.y_pstage.stage_output_voltage]))
def set_black_image(self):
self.black_image = np.array(self.image)
self.set_black_correction()
self.apply_black_image.setEnabled(True)
self.show_black_image.setEnabled(True)
def set_black_correction(self):
self.black_correction = self.black_image - np.median(self.black_image)
if self.apply_grey_image.isChecked():
self.set_grey_correction()
#prevent black and grey images from being acquired if corrections are being applied
if self.apply_black_image.isChecked() or self.apply_grey_image.isChecked():
self.get_black_image.setEnabled(False)
self.get_grey_image.setEnabled(False)
else:
self.get_black_image.setEnabled(True)
self.get_grey_image.setEnabled(True)
def set_grey_image(self):
self.grey_image = np.array(self.image)
self.set_grey_correction()
self.apply_grey_image.setEnabled(True)
self.show_grey_image.setEnabled(True)
def set_grey_correction(self):
if self.apply_black_image.isChecked():
denominator = self.grey_image - self.black_correction
else:
denominator = np.array(self.grey_image)
denominator[denominator <= 0] = 1 #prevent divide by zero or negative number
self.grey_correction = float(np.median(self.grey_image))/denominator
#prevent black and grey images from being acquired if corrections are being applied
if self.apply_black_image.isChecked() or self.apply_grey_image.isChecked():
self.get_black_image.setEnabled(False)
self.get_grey_image.setEnabled(False)
else:
self.get_black_image.setEnabled(True)
self.get_grey_image.setEnabled(True)
def uncheck_show_black(self):
if self.show_grey_image.isChecked():
self.show_black_image.setChecked(False)
def uncheck_show_grey(self):
if self.show_black_image.isChecked():
self.show_grey_image.setChecked(False)
def new_mov_avg(self):
self.avg_number = None
self.avg_initiating = True
def set_default_contrast(self):
#resets image contrast to default
if self.bit_depth == 8:
maxval = 255
elif self.bit_depth > 8:
maxval = 65535
self.minpixval.setText('0')
self.maxpixval.setText(str(maxval))
@property
def dtype(self):
if self.bit_depth == 8:
return 'uint8'
else:
return 'uint16'
def check_contrast_autoscale(self):
self.contrast_autoscale.setChecked(True)