python-microscopy 25.6.5__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PYME/Acquire/ActionManager.py +450 -0
- PYME/Acquire/ExecTools.py +235 -0
- PYME/Acquire/Hardware/AAOptoelectronics/MDS.py +175 -0
- PYME/Acquire/Hardware/AAOptoelectronics/__init__.py +0 -0
- PYME/Acquire/Hardware/ARCoptix/__init__.py +0 -0
- PYME/Acquire/Hardware/ARCoptix/lcdriver.py +149 -0
- PYME/Acquire/Hardware/ARCoptix/lcserver32.py +123 -0
- PYME/Acquire/Hardware/AndorIXon/AndorCam.py +1095 -0
- PYME/Acquire/Hardware/AndorIXon/AndorControlFrame.py +312 -0
- PYME/Acquire/Hardware/AndorIXon/AndorIXon.py +737 -0
- PYME/Acquire/Hardware/AndorIXon/__init__.py +27 -0
- PYME/Acquire/Hardware/AndorNeo/AndorNeo.py +644 -0
- PYME/Acquire/Hardware/AndorNeo/AndorNeoControlFrame.py +161 -0
- PYME/Acquire/Hardware/AndorNeo/AndorZyla.py +761 -0
- PYME/Acquire/Hardware/AndorNeo/SDK3.py +307 -0
- PYME/Acquire/Hardware/AndorNeo/SDK3Cam.py +171 -0
- PYME/Acquire/Hardware/AndorNeo/ZylaControlPanel.py +105 -0
- PYME/Acquire/Hardware/AndorNeo/__init__.py +22 -0
- PYME/Acquire/Hardware/AndorNeo/parseAtdebug.py +46 -0
- PYME/Acquire/Hardware/AndorNeo/plotTimings.py +73 -0
- PYME/Acquire/Hardware/AndorNeo/testNeo.py +62 -0
- PYME/Acquire/Hardware/Camera.py +1199 -0
- PYME/Acquire/Hardware/CameraSkeleton.py +642 -0
- PYME/Acquire/Hardware/Coherent/OBIS.py +147 -0
- PYME/Acquire/Hardware/Coherent/Sapphire.py +162 -0
- PYME/Acquire/Hardware/Coherent/__init__.py +0 -0
- PYME/Acquire/Hardware/DMDGui.py +198 -0
- PYME/Acquire/Hardware/DigiData/DigiData.py +95 -0
- PYME/Acquire/Hardware/DigiData/DigiDataClient.py +30 -0
- PYME/Acquire/Hardware/DigiData/RemoteDigiData.py +51 -0
- PYME/Acquire/Hardware/DigiData/__init__.py +24 -0
- PYME/Acquire/Hardware/DigiData/axDD132x.py +348 -0
- PYME/Acquire/Hardware/EMCCDTheory.py +41 -0
- PYME/Acquire/Hardware/ExciterWheel.py +167 -0
- PYME/Acquire/Hardware/FilterWheel.py +184 -0
- PYME/Acquire/Hardware/FocCorr.py +106 -0
- PYME/Acquire/Hardware/FocCorrR.py +196 -0
- PYME/Acquire/Hardware/FrFilter.py +51 -0
- PYME/Acquire/Hardware/GCS/GCS_DLL.py +370 -0
- PYME/Acquire/Hardware/GCS/__init__.py +0 -0
- PYME/Acquire/Hardware/GCS/gcs.py +210 -0
- PYME/Acquire/Hardware/HamamatsuDCAM/HamamatsuDCAM.py +662 -0
- PYME/Acquire/Hardware/HamamatsuDCAM/HamamatsuORCA.py +602 -0
- PYME/Acquire/Hardware/HamamatsuDCAM/Hamamatsu_control_panel.py +54 -0
- PYME/Acquire/Hardware/HamamatsuDCAM/__init__.py +23 -0
- PYME/Acquire/Hardware/LaserControlFrame.py +160 -0
- PYME/Acquire/Hardware/MPBCommunications/MPBCW.py +132 -0
- PYME/Acquire/Hardware/MPBCommunications/__init__.py +0 -0
- PYME/Acquire/Hardware/Mercury/Mercury.py +269 -0
- PYME/Acquire/Hardware/Mercury/PI_Mercury_GCS_DLL.py +857 -0
- PYME/Acquire/Hardware/Mercury/__init__.py +22 -0
- PYME/Acquire/Hardware/Mercury/mercuryStepper.py +203 -0
- PYME/Acquire/Hardware/Mercury/mercuryStepperGCS.py +281 -0
- PYME/Acquire/Hardware/NikonTE2000.py +68 -0
- PYME/Acquire/Hardware/NikonTi.py +214 -0
- PYME/Acquire/Hardware/NikonTiGUI.py +81 -0
- PYME/Acquire/Hardware/OrielCornerstone.py +125 -0
- PYME/Acquire/Hardware/PM100USB.py +51 -0
- PYME/Acquire/Hardware/Piezos/__init__.py +22 -0
- PYME/Acquire/Hardware/Piezos/base_piezo.py +108 -0
- PYME/Acquire/Hardware/Piezos/offsetPiezo.py +162 -0
- PYME/Acquire/Hardware/Piezos/offsetPiezoREST.py +308 -0
- PYME/Acquire/Hardware/Piezos/piezo_c867.py +486 -0
- PYME/Acquire/Hardware/Piezos/piezo_e255.py +68 -0
- PYME/Acquire/Hardware/Piezos/piezo_e662.py +61 -0
- PYME/Acquire/Hardware/Piezos/piezo_e709.py +434 -0
- PYME/Acquire/Hardware/Piezos/piezo_e816.py +452 -0
- PYME/Acquire/Hardware/Piezos/piezo_e816_corr.py +70 -0
- PYME/Acquire/Hardware/Piezos/piezo_e816_dll.py +518 -0
- PYME/Acquire/Hardware/Piezos/piezo_e816b.py +70 -0
- PYME/Acquire/Hardware/Piezos/piezo_pipython_gcs.py +560 -0
- PYME/Acquire/Hardware/Piezos/piezo_test.py +55 -0
- PYME/Acquire/Hardware/Simulator/EmpiricalHist.py +273 -0
- PYME/Acquire/Hardware/Simulator/__init__.py +22 -0
- PYME/Acquire/Hardware/Simulator/dSimControl.py +961 -0
- PYME/Acquire/Hardware/Simulator/fakeCam.py +651 -0
- PYME/Acquire/Hardware/Simulator/fakePiezo.py +95 -0
- PYME/Acquire/Hardware/Simulator/fluor.py +336 -0
- PYME/Acquire/Hardware/Simulator/illuminate.cp39-win_amd64.dll.a +0 -0
- PYME/Acquire/Hardware/Simulator/illuminate.cp39-win_amd64.pyd +0 -0
- PYME/Acquire/Hardware/Simulator/illuminate.pyx +93 -0
- PYME/Acquire/Hardware/Simulator/lasersliders.py +90 -0
- PYME/Acquire/Hardware/Simulator/rend_im.py +446 -0
- PYME/Acquire/Hardware/Simulator/setup.py +69 -0
- PYME/Acquire/Hardware/Simulator/simcontrol.py +348 -0
- PYME/Acquire/Hardware/Simulator/simui_wx.py +794 -0
- PYME/Acquire/Hardware/Tango/__init__.py +0 -0
- PYME/Acquire/Hardware/Tango/marzhauser_tango.py +583 -0
- PYME/Acquire/Hardware/TiLightCrafter.py +388 -0
- PYME/Acquire/Hardware/__init__.py +22 -0
- PYME/Acquire/Hardware/aotf.py +271 -0
- PYME/Acquire/Hardware/arclampshutterpanel.py +71 -0
- PYME/Acquire/Hardware/cameraSoftwareBuffer.py +215 -0
- PYME/Acquire/Hardware/camera_noise.py +270 -0
- PYME/Acquire/Hardware/ccdAdjPanel.py +188 -0
- PYME/Acquire/Hardware/ccdCalibrator.py +161 -0
- PYME/Acquire/Hardware/cobaltLaser.py +108 -0
- PYME/Acquire/Hardware/cobaltLaser561.py +94 -0
- PYME/Acquire/Hardware/comports.py +26 -0
- PYME/Acquire/Hardware/driftTrackGUI.py +488 -0
- PYME/Acquire/Hardware/driftTracking.py +595 -0
- PYME/Acquire/Hardware/fakeShutters.py +52 -0
- PYME/Acquire/Hardware/focusKeys.py +204 -0
- PYME/Acquire/Hardware/focus_locks/__init__.py +0 -0
- PYME/Acquire/Hardware/focus_locks/reflection_focus_lock.py +684 -0
- PYME/Acquire/Hardware/frZStage.py +117 -0
- PYME/Acquire/Hardware/fw102.py +38 -0
- PYME/Acquire/Hardware/ids_peak_cam.py +561 -0
- PYME/Acquire/Hardware/ioslave.py +305 -0
- PYME/Acquire/Hardware/lasers.py +292 -0
- PYME/Acquire/Hardware/matchboxLaser.py +58 -0
- PYME/Acquire/Hardware/microscope_adapter.py +104 -0
- PYME/Acquire/Hardware/mpd_picosecond_delayer.py +395 -0
- PYME/Acquire/Hardware/multiview.py +287 -0
- PYME/Acquire/Hardware/olympusix81.py +59 -0
- PYME/Acquire/Hardware/pco/__init__.py +0 -0
- PYME/Acquire/Hardware/pco/pco_cam.py +348 -0
- PYME/Acquire/Hardware/pco/pco_edge_42_lt.py +34 -0
- PYME/Acquire/Hardware/pco/pco_sdk.py +1645 -0
- PYME/Acquire/Hardware/pco/pco_sdk_cam.py +518 -0
- PYME/Acquire/Hardware/pco/pco_sdk_cam_control_panel.py +54 -0
- PYME/Acquire/Hardware/phoxxLaser.py +199 -0
- PYME/Acquire/Hardware/phoxxLaserOLD.py +242 -0
- PYME/Acquire/Hardware/priorLumen.py +102 -0
- PYME/Acquire/Hardware/priorarclampshutter.py +52 -0
- PYME/Acquire/Hardware/setup.py +50 -0
- PYME/Acquire/Hardware/spacenav.py +148 -0
- PYME/Acquire/Hardware/splitter.py +394 -0
- PYME/Acquire/Hardware/thorlabsPiezo.py +98 -0
- PYME/Acquire/Hardware/thorlabs_cam.py +136 -0
- PYME/Acquire/Hardware/thorlabs_mff_flipper.py +400 -0
- PYME/Acquire/Hardware/toptica_ibeam.py +51 -0
- PYME/Acquire/Hardware/uc480/AndorControlFrame.py +308 -0
- PYME/Acquire/Hardware/uc480/__init__.py +27 -0
- PYME/Acquire/Hardware/uc480/uCam480.py +695 -0
- PYME/Acquire/Hardware/uc480/uc480.py +189 -0
- PYME/Acquire/Hardware/uc480/uc480Deprecated.py +87 -0
- PYME/Acquire/Hardware/uc480/uc480_h.py +767 -0
- PYME/Acquire/Hardware/uc480/uc480_h_gen.py +62 -0
- PYME/Acquire/Hardware/uc480/ucCamControlFrame.py +83 -0
- PYME/Acquire/Hardware/ueye.py +702 -0
- PYME/Acquire/PYMEAcquire.py +186 -0
- PYME/Acquire/Protocols/DMDMFM.py +74 -0
- PYME/Acquire/Protocols/__init__.py +22 -0
- PYME/Acquire/Protocols/darkCalibrate.py +56 -0
- PYME/Acquire/Protocols/dual671_470.py +45 -0
- PYME/Acquire/Protocols/dual671_488.py +46 -0
- PYME/Acquire/Protocols/gainCal.py +53 -0
- PYME/Acquire/Protocols/htsms-cal-psf.py +32 -0
- PYME/Acquire/Protocols/htsms-cal-registration.py +52 -0
- PYME/Acquire/Protocols/htsms-flow.py +29 -0
- PYME/Acquire/Protocols/htsms-staggered.py +31 -0
- PYME/Acquire/Protocols/htsms-tile.py +68 -0
- PYME/Acquire/Protocols/htsms-two-color.py +29 -0
- PYME/Acquire/Protocols/htsms-widefield.py +32 -0
- PYME/Acquire/Protocols/paint671.py +61 -0
- PYME/Acquire/Protocols/photoconversion.py +52 -0
- PYME/Acquire/Protocols/photoconversion2.py +55 -0
- PYME/Acquire/Protocols/prebleach488.py +70 -0
- PYME/Acquire/Protocols/prebleach490.py +69 -0
- PYME/Acquire/Protocols/prebleach561.py +72 -0
- PYME/Acquire/Protocols/prebleach561NeomEos2.py +70 -0
- PYME/Acquire/Protocols/prebleach561NeomEos2ND1.py +70 -0
- PYME/Acquire/Protocols/prebleach642.py +70 -0
- PYME/Acquire/Protocols/prebleach671.py +69 -0
- PYME/Acquire/Protocols/prebleach671ND1.py +58 -0
- PYME/Acquire/Protocols/prebleach671ND2.py +57 -0
- PYME/Acquire/Protocols/prebleach671Neo.py +69 -0
- PYME/Acquire/Protocols/recover671.py +62 -0
- PYME/Acquire/Protocols/sequence642_488.py +85 -0
- PYME/Acquire/Protocols/sequence642_561.py +87 -0
- PYME/Acquire/Protocols/shiftfield.py +198 -0
- PYME/Acquire/Protocols/simul488.py +59 -0
- PYME/Acquire/Protocols/simul642.py +63 -0
- PYME/Acquire/Protocols/simul642HTSMS.py +63 -0
- PYME/Acquire/Protocols/simulPA.py +37 -0
- PYME/Acquire/Protocols/simulSIM.py +76 -0
- PYME/Acquire/Protocols/simulStep.py +62 -0
- PYME/Acquire/Protocols/spdscan.py +178 -0
- PYME/Acquire/Protocols/standard470.py +45 -0
- PYME/Acquire/Protocols/standard488.py +47 -0
- PYME/Acquire/Protocols/standard671.py +48 -0
- PYME/Acquire/Protocols/standard671_no532.py +47 -0
- PYME/Acquire/Protocols/standardArclamp.py +46 -0
- PYME/Acquire/Protocols/strip_tile.py +204 -0
- PYME/Acquire/Protocols/tile.py +204 -0
- PYME/Acquire/Protocols/tile3D.py +192 -0
- PYME/Acquire/Protocols/tile671.py +190 -0
- PYME/Acquire/Protocols/tile_triggered.py +189 -0
- PYME/Acquire/Scripts/init.py +232 -0
- PYME/Acquire/Scripts/init_N1_Ti_Exeter_ZIx.py +374 -0
- PYME/Acquire/Scripts/init_N2_Ti_Zyla_lasers.py +290 -0
- PYME/Acquire/Scripts/init_Neo.py +266 -0
- PYME/Acquire/Scripts/init_NeoSim.py +159 -0
- PYME/Acquire/Scripts/init_TIRF.py +232 -0
- PYME/Acquire/Scripts/init_TIRF_Neo.py +242 -0
- PYME/Acquire/Scripts/init_TIRF_NeoO.py +241 -0
- PYME/Acquire/Scripts/init_TIRF_onecam.py +233 -0
- PYME/Acquire/Scripts/init_Ti.py +257 -0
- PYME/Acquire/Scripts/init_UOA_n.py +256 -0
- PYME/Acquire/Scripts/init_UOA_n2.py +246 -0
- PYME/Acquire/Scripts/init_Y1.py +249 -0
- PYME/Acquire/Scripts/init_Zyla.py +260 -0
- PYME/Acquire/Scripts/init_drift_tracking.py +80 -0
- PYME/Acquire/Scripts/init_emccd_basic.py +277 -0
- PYME/Acquire/Scripts/init_htsms.py +277 -0
- PYME/Acquire/Scripts/init_htsms_focus_lock.py +132 -0
- PYME/Acquire/Scripts/init_micrpi.py +45 -0
- PYME/Acquire/Scripts/init_orca.py +70 -0
- PYME/Acquire/Scripts/init_pco.py +49 -0
- PYME/Acquire/Scripts/init_rev.py +74 -0
- PYME/Acquire/Scripts/init_sim100.py +169 -0
- PYME/Acquire/Scripts/init_sim103.py +169 -0
- PYME/Acquire/Scripts/init_sim2.py +211 -0
- PYME/Acquire/Scripts/init_sim50.py +169 -0
- PYME/Acquire/Scripts/init_sim75.py +169 -0
- PYME/Acquire/Scripts/init_sim_drift_tracking.py +166 -0
- PYME/Acquire/Scripts/init_sim_htsms.py +224 -0
- PYME/Acquire/Scripts/init_sim_htsms_n.py +233 -0
- PYME/Acquire/Scripts/init_sim_main.py +229 -0
- PYME/Acquire/Scripts/init_sim_min.py +197 -0
- PYME/Acquire/Scripts/init_sim_rem.py +176 -0
- PYME/Acquire/Scripts/init_smi1.py +110 -0
- PYME/Acquire/Scripts/init_spectro.py +78 -0
- PYME/Acquire/Scripts/init_spim.py +116 -0
- PYME/Acquire/Scripts/init_thorcam.py +62 -0
- PYME/Acquire/Scripts/init_twophoton.py +112 -0
- PYME/Acquire/Scripts/init_uc480.py +262 -0
- PYME/Acquire/Scripts/init_ueye.py +261 -0
- PYME/Acquire/SpoolController.py +958 -0
- PYME/Acquire/Utils/MultiPointScanner.py +80 -0
- PYME/Acquire/Utils/__init__.py +13 -0
- PYME/Acquire/Utils/failsafe.py +157 -0
- PYME/Acquire/Utils/fastTiler.py +153 -0
- PYME/Acquire/Utils/pointScanner.py +496 -0
- PYME/Acquire/Utils/sarcSpacing.py +86 -0
- PYME/Acquire/Utils/strip_tiler.py +93 -0
- PYME/Acquire/Utils/tiler.py +464 -0
- PYME/Acquire/Utils/vibrationAnalysis.py +65 -0
- PYME/Acquire/__init__.py +44 -0
- PYME/Acquire/acquire_client.py +90 -0
- PYME/Acquire/acquire_server.py +316 -0
- PYME/Acquire/acquirebase.py +139 -0
- PYME/Acquire/acquiremainframe.py +716 -0
- PYME/Acquire/acquirewx.py +61 -0
- PYME/Acquire/acquisition_base.py +148 -0
- PYME/Acquire/actions.py +209 -0
- PYME/Acquire/autofocus.py +54 -0
- PYME/Acquire/eventLog.py +95 -0
- PYME/Acquire/event_loop.py +119 -0
- PYME/Acquire/frameWrangler.py +530 -0
- PYME/Acquire/htsms/__init__.py +8 -0
- PYME/Acquire/htsms/rule_ui.py +970 -0
- PYME/Acquire/htsms/rule_ui_v2.py +573 -0
- PYME/Acquire/htsms/tweeter.py +222 -0
- PYME/Acquire/microscope.py +1050 -0
- PYME/Acquire/positionTracker.py +181 -0
- PYME/Acquire/protocol.py +299 -0
- PYME/Acquire/protocol_acquisition.py +404 -0
- PYME/Acquire/sampleInformation.py +591 -0
- PYME/Acquire/sampleInformationDjangoDirect.py +446 -0
- PYME/Acquire/setup.py +52 -0
- PYME/Acquire/stackSettings.py +295 -0
- PYME/Acquire/stage_leveling.py +285 -0
- PYME/Acquire/ui/AnalysisSettingsUI.py +184 -0
- PYME/Acquire/ui/HDFSpoolFrame.py +584 -0
- PYME/Acquire/ui/__init__.py +0 -0
- PYME/Acquire/ui/actionUI.py +892 -0
- PYME/Acquire/ui/focus_lock_gui.py +149 -0
- PYME/Acquire/ui/intensity_trace.py +143 -0
- PYME/Acquire/ui/intsliders.py +222 -0
- PYME/Acquire/ui/lasersliders.py +329 -0
- PYME/Acquire/ui/mpd_picosecond_delay_panel.py +69 -0
- PYME/Acquire/ui/multiview_select.py +77 -0
- PYME/Acquire/ui/positionUI.py +519 -0
- PYME/Acquire/ui/preflight.py +58 -0
- PYME/Acquire/ui/scanner_panel.py +41 -0
- PYME/Acquire/ui/selectCameraPanel.py +46 -0
- PYME/Acquire/ui/seqdialog.py +501 -0
- PYME/Acquire/ui/splashScreen.py +175 -0
- PYME/Acquire/ui/spool_panel.py +830 -0
- PYME/Acquire/ui/tile_panel.py +556 -0
- PYME/Acquire/ui/tilesettingsui.py +91 -0
- PYME/Acquire/ui/voxelSizeDialog.py +149 -0
- PYME/Acquire/webui/__init__.py +36 -0
- PYME/Acquire/webui/ipy.py +361 -0
- PYME/Acquire/webui/static/css/pyme-bootstrap.css +9908 -0
- PYME/Acquire/webui/static/css/pymeacquire.css +85 -0
- PYME/Acquire/webui/static/js/pymeacquire.js +375 -0
- PYME/Acquire/webui/static/js/pzf.js +95 -0
- PYME/Acquire/webui/templates/PYMEAcquire.html +232 -0
- PYME/Acquire/webui/templates/login.html +84 -0
- PYME/Acquire/webui/templates/xtermpage.html +106 -0
- PYME/Acquire/xyztc.py +418 -0
- PYME/Acquire/zScanner.py +287 -0
- PYME/Analysis/BleachProfile/__init__.py +26 -0
- PYME/Analysis/BleachProfile/deMod.py +91 -0
- PYME/Analysis/BleachProfile/fitRecover.py +90 -0
- PYME/Analysis/BleachProfile/intensProf.py +519 -0
- PYME/Analysis/BleachProfile/kinModels.py +507 -0
- PYME/Analysis/BleachProfile/rawIntensity.py +227 -0
- PYME/Analysis/BleachProfile/rollins.py +555 -0
- PYME/Analysis/Colocalisation/__init__.py +27 -0
- PYME/Analysis/Colocalisation/colocScaleDep.py +126 -0
- PYME/Analysis/Colocalisation/correlationCoeffs.py +198 -0
- PYME/Analysis/Colocalisation/distColoc.py +110 -0
- PYME/Analysis/Colocalisation/edtColoc.py +191 -0
- PYME/Analysis/MetaData.py +278 -0
- PYME/Analysis/PSFEst/__init__.py +27 -0
- PYME/Analysis/PSFEst/dec.py +283 -0
- PYME/Analysis/PSFEst/extractImages.py +316 -0
- PYME/Analysis/PSFEst/fit_psf_zernikes.py +194 -0
- PYME/Analysis/PSFEst/psfQuality.py +225 -0
- PYME/Analysis/PSFGen/__init__.py +40 -0
- PYME/Analysis/PSFGen/fourier.py +138 -0
- PYME/Analysis/PSFGen/fourierHNA.py +1108 -0
- PYME/Analysis/PSFGen/fourierHNA2.py +979 -0
- PYME/Analysis/PSFGen/genCRBcurves.py +185 -0
- PYME/Analysis/PSFGen/nijboer_zernike.py +79 -0
- PYME/Analysis/PSFGen/ps_app.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/PSFGen/ps_app.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/PSFGen/test_ps_app.py +24 -0
- PYME/Analysis/Tracking/__init__.py +3 -0
- PYME/Analysis/Tracking/msd.py +57 -0
- PYME/Analysis/Tracking/trackUtils.py +528 -0
- PYME/Analysis/Tracking/tracking.py +152 -0
- PYME/Analysis/__init__.py +30 -0
- PYME/Analysis/_fithelpers.py +161 -0
- PYME/Analysis/angleFilter.py +287 -0
- PYME/Analysis/annealThresh.py +157 -0
- PYME/Analysis/autoencoder_classifier.py +45 -0
- PYME/Analysis/binAvg.py +144 -0
- PYME/Analysis/composite.py +183 -0
- PYME/Analysis/cramerRao.py +259 -0
- PYME/Analysis/deTile.py +441 -0
- PYME/Analysis/density_filter.py +45 -0
- PYME/Analysis/distributed_pyramid.py +426 -0
- PYME/Analysis/fiducial_matching.py +220 -0
- PYME/Analysis/gen_sCMOS_maps.py +355 -0
- PYME/Analysis/graphing_filters.py +311 -0
- PYME/Analysis/implicitFilter.py +359 -0
- PYME/Analysis/keep_pairs.py +69 -0
- PYME/Analysis/optic_flow.py +108 -0
- PYME/Analysis/piecewise.py +36 -0
- PYME/Analysis/piecewiseMapping.py +304 -0
- PYME/Analysis/piezo_movement_correction.py +153 -0
- PYME/Analysis/points/DeClump/__init__.py +78 -0
- PYME/Analysis/points/DeClump/deClump.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/DeClump/deClump.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/DeClump/deClumpGUI.py +87 -0
- PYME/Analysis/points/DeClump/pyDeClump.py +284 -0
- PYME/Analysis/points/DeClump/testClump.py +40 -0
- PYME/Analysis/points/DistHist/__init__.py +25 -0
- PYME/Analysis/points/DistHist/distHist.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/DistHist/distHist.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/DistHist/distHistThreaded.py +71 -0
- PYME/Analysis/points/DistHist/setup.py +54 -0
- PYME/Analysis/points/EdgeDB/__init__.py +24 -0
- PYME/Analysis/points/EdgeDB/edgeDB.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/EdgeDB/edgeDB.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/EdgeDB/edgeTest.py +66 -0
- PYME/Analysis/points/EdgeDB/edges.py +102 -0
- PYME/Analysis/points/EdgeDB/segment.py +75 -0
- PYME/Analysis/points/EdgeDB/setup.py +54 -0
- PYME/Analysis/points/QuadTree/QTrend.py +232 -0
- PYME/Analysis/points/QuadTree/__init__.py +25 -0
- PYME/Analysis/points/QuadTree/pointQT.py +227 -0
- PYME/Analysis/points/QuadTree/pointQTF.py +254 -0
- PYME/Analysis/points/QuadTree/qtUtils.py +36 -0
- PYME/Analysis/points/QuadTree/rendQT.py +118 -0
- PYME/Analysis/points/SoftRend/__init__.py +24 -0
- PYME/Analysis/points/SoftRend/setup.py +61 -0
- PYME/Analysis/points/SoftRend/testTetrahedra.py +41 -0
- PYME/Analysis/points/SoftRend/triRend.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/SoftRend/triRend.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/__init__.py +3 -0
- PYME/Analysis/points/arcfit/__init__.py +1 -0
- PYME/Analysis/points/arcfit/arcmf.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/arcfit/arcmf.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/arcfit/setup.py +51 -0
- PYME/Analysis/points/astigmatism/__init__.py +0 -0
- PYME/Analysis/points/astigmatism/astigTools.py +338 -0
- PYME/Analysis/points/astigmatism/astiglookup.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/astigmatism/astiglookup.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/astigmatism/setup.py +54 -0
- PYME/Analysis/points/cluster_morphology.py +199 -0
- PYME/Analysis/points/coordinate_tools.py +278 -0
- PYME/Analysis/points/features/__init__.py +0 -0
- PYME/Analysis/points/features/metal.py +46 -0
- PYME/Analysis/points/features/shaders/vect_feat_3d.metal +49 -0
- PYME/Analysis/points/fiducials.py +142 -0
- PYME/Analysis/points/gen3DTriangs.py +796 -0
- PYME/Analysis/points/moments.py +143 -0
- PYME/Analysis/points/multiview.py +458 -0
- PYME/Analysis/points/objectMeasure.py +206 -0
- PYME/Analysis/points/qpaint.py +97 -0
- PYME/Analysis/points/rings.py +372 -0
- PYME/Analysis/points/ripleys.py +427 -0
- PYME/Analysis/points/segmentLL.py +134 -0
- PYME/Analysis/points/setup.py +56 -0
- PYME/Analysis/points/spherical_harmonics.py +909 -0
- PYME/Analysis/points/surfit.py +829 -0
- PYME/Analysis/points/tCluster.py +75 -0
- PYME/Analysis/points/traveling_salesperson/__init__.py +0 -0
- PYME/Analysis/points/traveling_salesperson/queue_opt.py +117 -0
- PYME/Analysis/points/traveling_salesperson/sectioned_two_opt.py +327 -0
- PYME/Analysis/points/traveling_salesperson/setup.py +40 -0
- PYME/Analysis/points/traveling_salesperson/sort.py +78 -0
- PYME/Analysis/points/traveling_salesperson/two_opt.py +189 -0
- PYME/Analysis/points/traveling_salesperson/two_opt_utils.cp39-win_amd64.dll.a +0 -0
- PYME/Analysis/points/traveling_salesperson/two_opt_utils.cp39-win_amd64.pyd +0 -0
- PYME/Analysis/points/traveling_salesperson/two_opt_utils.pyx +41 -0
- PYME/Analysis/points/twoColour.py +572 -0
- PYME/Analysis/points/twoColourPlot.py +107 -0
- PYME/Analysis/processLogger.py +129 -0
- PYME/Analysis/profile_extraction.py +72 -0
- PYME/Analysis/setup.py +60 -0
- PYME/Analysis/splitting.py +372 -0
- PYME/Analysis/svmSegment.py +214 -0
- PYME/Analysis/thresholding.py +192 -0
- PYME/Analysis/tile_pyramid.py +938 -0
- PYME/Analysis/widefieldify.py +54 -0
- PYME/DSView/DisplayOptionsPanel.py +503 -0
- PYME/DSView/LUT/__init__.py +33 -0
- PYME/DSView/LUT/lut.cp39-win_amd64.dll.a +0 -0
- PYME/DSView/LUT/lut.cp39-win_amd64.pyd +0 -0
- PYME/DSView/LUT/setup.py +54 -0
- PYME/DSView/OpenSequenceDialog.py +83 -0
- PYME/DSView/OverlaysPanel.py +111 -0
- PYME/DSView/__init__.py +32 -0
- PYME/DSView/arrayViewPanel.py +1035 -0
- PYME/DSView/displayOptions.py +453 -0
- PYME/DSView/displaySettingsPanel.py +271 -0
- PYME/DSView/dsviewer.py +542 -0
- PYME/DSView/eventLogViewer.py +805 -0
- PYME/DSView/fitInfo.py +486 -0
- PYME/DSView/htmlServe.py +72 -0
- PYME/DSView/logparser.py +100 -0
- PYME/DSView/modules/LMAnalysis.py +1053 -0
- PYME/DSView/modules/LMDisplay.py +194 -0
- PYME/DSView/modules/__init__.py +162 -0
- PYME/DSView/modules/_base.py +39 -0
- PYME/DSView/modules/annotation.py +725 -0
- PYME/DSView/modules/arrayView.py +71 -0
- PYME/DSView/modules/blobFinding.py +455 -0
- PYME/DSView/modules/blobMeasure.py +1093 -0
- PYME/DSView/modules/camera_maps.py +38 -0
- PYME/DSView/modules/coloc.py +414 -0
- PYME/DSView/modules/composite.py +715 -0
- PYME/DSView/modules/convnet.py +24 -0
- PYME/DSView/modules/cropping.py +133 -0
- PYME/DSView/modules/dark_and_flatfield.py +31 -0
- PYME/DSView/modules/deconvolution.py +499 -0
- PYME/DSView/modules/eventView.py +80 -0
- PYME/DSView/modules/extractBlobs.py +46 -0
- PYME/DSView/modules/fastGraphPanel.py +85 -0
- PYME/DSView/modules/filtering.py +335 -0
- PYME/DSView/modules/flowView.py +268 -0
- PYME/DSView/modules/fourierRingCorrelation.py +172 -0
- PYME/DSView/modules/gl_image_view.py +12 -0
- PYME/DSView/modules/graphViewPanel.py +272 -0
- PYME/DSView/modules/measure/__init__.py +1 -0
- PYME/DSView/modules/measure/filterPan.py +239 -0
- PYME/DSView/modules/metadataView.py +28 -0
- PYME/DSView/modules/multithreshold.py +98 -0
- PYME/DSView/modules/neuroglancer.py +129 -0
- PYME/DSView/modules/object_tagging.py +157 -0
- PYME/DSView/modules/particleTracking.py +463 -0
- PYME/DSView/modules/playback.py +256 -0
- PYME/DSView/modules/prebleachExtraction.py +75 -0
- PYME/DSView/modules/profileFitting.py +137 -0
- PYME/DSView/modules/profilePlotting.py +408 -0
- PYME/DSView/modules/projections.py +48 -0
- PYME/DSView/modules/psfExtraction.py +570 -0
- PYME/DSView/modules/psfGeneration.py +138 -0
- PYME/DSView/modules/psfTools.py +661 -0
- PYME/DSView/modules/pupilTools.py +204 -0
- PYME/DSView/modules/pupilView.py +139 -0
- PYME/DSView/modules/recipes.py +266 -0
- PYME/DSView/modules/redimension.py +75 -0
- PYME/DSView/modules/segmentation.py +192 -0
- PYME/DSView/modules/sheetView.py +24 -0
- PYME/DSView/modules/shell.py +39 -0
- PYME/DSView/modules/shiftfield_estimation.py +433 -0
- PYME/DSView/modules/sparkprepare.py +94 -0
- PYME/DSView/modules/splitter.py +148 -0
- PYME/DSView/modules/synchronise.py +64 -0
- PYME/DSView/modules/templates/astigCal.html +42 -0
- PYME/DSView/modules/templates/measureView.html +69 -0
- PYME/DSView/modules/templates/measureView2.html +48 -0
- PYME/DSView/modules/templates/measureView3.html +98 -0
- PYME/DSView/modules/templates/trackView.html +139 -0
- PYME/DSView/modules/templates/tracksOverview.html +21 -0
- PYME/DSView/modules/tiling.py +147 -0
- PYME/DSView/modules/unmixing.py +148 -0
- PYME/DSView/modules/vis3D.py +320 -0
- PYME/DSView/modules/visgui.py +163 -0
- PYME/DSView/modules/webview.py +14 -0
- PYME/DSView/overlays.py +295 -0
- PYME/DSView/scrolledImagePanel.py +188 -0
- PYME/DSView/setup.py +53 -0
- PYME/DSView/splashScreen.py +158 -0
- PYME/DSView/voxSizeDialog.py +84 -0
- PYME/Deconv/__init__.py +35 -0
- PYME/Deconv/beadGen.py +55 -0
- PYME/Deconv/dec.py +659 -0
- PYME/Deconv/decTask.py +65 -0
- PYME/Deconv/decThread.py +113 -0
- PYME/Deconv/dec_test.py +47 -0
- PYME/Deconv/deconvDialogs.py +417 -0
- PYME/Deconv/fftwWisdom.py +62 -0
- PYME/Deconv/richardsonLucy.py +141 -0
- PYME/Deconv/richardsonLucyMV.py +151 -0
- PYME/Deconv/richardsonLucyMVM.py +218 -0
- PYME/Deconv/test_block_dec.py +46 -0
- PYME/Deconv/tq_block_dec.py +331 -0
- PYME/Deconv/wiener.py +163 -0
- PYME/IO/DataSources/AlignDataSource.py +91 -0
- PYME/IO/DataSources/ArrayDataSource.py +260 -0
- PYME/IO/DataSources/BGSDataSource.py +353 -0
- PYME/IO/DataSources/BaseDataSource.py +457 -0
- PYME/IO/DataSources/BioformatsDataSource.py +178 -0
- PYME/IO/DataSources/BufferedDataSource.py +99 -0
- PYME/IO/DataSources/ClusterPZFDataSource.py +124 -0
- PYME/IO/DataSources/ConcatenatedDataSource.py +56 -0
- PYME/IO/DataSources/CropDataSource.py +243 -0
- PYME/IO/DataSources/DcimgDataSource.py +54 -0
- PYME/IO/DataSources/ElectronsPerSecondDataSource.py +61 -0
- PYME/IO/DataSources/FlatFieldDataSource.py +77 -0
- PYME/IO/DataSources/HDFDataSource.py +160 -0
- PYME/IO/DataSources/HTTPDataSource.py +80 -0
- PYME/IO/DataSources/ImageSeriesDataSource.py +123 -0
- PYME/IO/DataSources/MultiviewDataSource.py +99 -0
- PYME/IO/DataSources/OBFDataSource.py +67 -0
- PYME/IO/DataSources/RandomDataSource.py +23 -0
- PYME/IO/DataSources/SupertileDatasource.py +148 -0
- PYME/IO/DataSources/TQDataSource.py +41 -0
- PYME/IO/DataSources/TiffDataSource.py +193 -0
- PYME/IO/DataSources/TileDataSource.py +91 -0
- PYME/IO/DataSources/UnsplitDataSource.py +92 -0
- PYME/IO/DataSources/__init__.py +59 -0
- PYME/IO/FileUtils/IJLut.py +43 -0
- PYME/IO/FileUtils/RawToHdf5.py +105 -0
- PYME/IO/FileUtils/SPAD.py +54 -0
- PYME/IO/FileUtils/TiffSeqToHdf5.py +87 -0
- PYME/IO/FileUtils/__init__.py +24 -0
- PYME/IO/FileUtils/compHdf.py +39 -0
- PYME/IO/FileUtils/fileID.py +246 -0
- PYME/IO/FileUtils/fnlGen.py +40 -0
- PYME/IO/FileUtils/freeSpace.py +59 -0
- PYME/IO/FileUtils/h5-thumbnailer.py +85 -0
- PYME/IO/FileUtils/h5ExFrames.py +98 -0
- PYME/IO/FileUtils/h5ToTiffSeries.py +50 -0
- PYME/IO/FileUtils/h5r-thumbnailer.py +118 -0
- PYME/IO/FileUtils/h5rFormatDef.py +99 -0
- PYME/IO/FileUtils/h5rToTxt.py +77 -0
- PYME/IO/FileUtils/nameUtils.py +300 -0
- PYME/IO/FileUtils/obf_support.py +538 -0
- PYME/IO/FileUtils/ply.py +147 -0
- PYME/IO/FileUtils/readSpeckle.py +78 -0
- PYME/IO/FileUtils/readTiff.py +64 -0
- PYME/IO/FileUtils/saveTiffStack.py +137 -0
- PYME/IO/FileUtils/setup.py +36 -0
- PYME/IO/FileUtils/sf-thumbnailer.py +76 -0
- PYME/IO/FileUtils/stl.py +44 -0
- PYME/IO/FileUtils/thumbnailDatabase.py +104 -0
- PYME/IO/HTTPSpooler_v2.py +141 -0
- PYME/IO/MetaDataHandler.py +1072 -0
- PYME/IO/PZFFormat.py +375 -0
- PYME/IO/Spooler.py +279 -0
- PYME/IO/__init__.py +12 -0
- PYME/IO/acquisition_backends.py +353 -0
- PYME/IO/buffer_helpers.cp39-win_amd64.dll.a +0 -0
- PYME/IO/buffer_helpers.cp39-win_amd64.pyd +0 -0
- PYME/IO/buffer_helpers.pyx +190 -0
- PYME/IO/buffers.py +291 -0
- PYME/IO/clusterDuplication.py +204 -0
- PYME/IO/clusterExport.py +152 -0
- PYME/IO/clusterGlob.py +108 -0
- PYME/IO/clusterIO.py +1076 -0
- PYME/IO/clusterListing.py +232 -0
- PYME/IO/clusterResults.py +206 -0
- PYME/IO/clusterUpload.py +49 -0
- PYME/IO/cluster_directory.py +419 -0
- PYME/IO/cluster_streaming.py +216 -0
- PYME/IO/compatibility.py +12 -0
- PYME/IO/countdir/__init__.py +5 -0
- PYME/IO/countdir/setup.py +58 -0
- PYME/IO/csv_flavours.py +251 -0
- PYME/IO/dataExporter.py +470 -0
- PYME/IO/dataWrap.py +108 -0
- PYME/IO/dcimg.py +167 -0
- PYME/IO/events.py +161 -0
- PYME/IO/h5File.py +148 -0
- PYME/IO/h5rFile.py +323 -0
- PYME/IO/image.py +1447 -0
- PYME/IO/load_psf.py +26 -0
- PYME/IO/pyme_h5ls.py +58 -0
- PYME/IO/ragged.py +138 -0
- PYME/IO/rgb_image.py +94 -0
- PYME/IO/tabular.py +1338 -0
- PYME/IO/testClusterSpooling.py +199 -0
- PYME/IO/unifiedIO.py +301 -0
- PYME/LMVis/Extras/QPobjectSegment.py +220 -0
- PYME/LMVis/Extras/__init__.py +55 -0
- PYME/LMVis/Extras/animation.py +359 -0
- PYME/LMVis/Extras/annotation.py +78 -0
- PYME/LMVis/Extras/clusterAnalysis.py +460 -0
- PYME/LMVis/Extras/dockedPanel.py +69 -0
- PYME/LMVis/Extras/extra_layers.py +373 -0
- PYME/LMVis/Extras/fiducial.py +230 -0
- PYME/LMVis/Extras/flagZMotionArtifacts.py +60 -0
- PYME/LMVis/Extras/fusionUtils.py +9 -0
- PYME/LMVis/Extras/multiColourAnalysis.py +103 -0
- PYME/LMVis/Extras/multiviewMapping.py +489 -0
- PYME/LMVis/Extras/objectMeasurements.py +246 -0
- PYME/LMVis/Extras/particleTracking.py +272 -0
- PYME/LMVis/Extras/perFrameVariable.py +77 -0
- PYME/LMVis/Extras/photophysics.py +72 -0
- PYME/LMVis/Extras/pointSetGeneration.py +232 -0
- PYME/LMVis/Extras/pointwiseColoc.py +54 -0
- PYME/LMVis/Extras/saved_views.py +125 -0
- PYME/LMVis/Extras/scaleBox.py +115 -0
- PYME/LMVis/Extras/sequentialSpecies.py +125 -0
- PYME/LMVis/Extras/setBGImage.py +74 -0
- PYME/LMVis/Extras/shiftmapGenerator.py +138 -0
- PYME/LMVis/Extras/showShortcuts.py +69 -0
- PYME/LMVis/Extras/snapshot.py +135 -0
- PYME/LMVis/Extras/spherical_harmonics.py +98 -0
- PYME/LMVis/Extras/subsets.py +15 -0
- PYME/LMVis/Extras/surface_fitting.py +52 -0
- PYME/LMVis/Extras/temperaturePlot.py +53 -0
- PYME/LMVis/Extras/vibration.py +112 -0
- PYME/LMVis/VisGUI.py +506 -0
- PYME/LMVis/__init__.py +39 -0
- PYME/LMVis/colourFilterGUI.py +77 -0
- PYME/LMVis/colourPanel.py +491 -0
- PYME/LMVis/displayPane.py +462 -0
- PYME/LMVis/dyeRatios.py +116 -0
- PYME/LMVis/genImageDialog.py +298 -0
- PYME/LMVis/gl_offScreenHandler.py +134 -0
- PYME/LMVis/gl_render.py +1302 -0
- PYME/LMVis/gl_render3D.py +1453 -0
- PYME/LMVis/gl_render3D_shaders.py +1213 -0
- PYME/LMVis/glcanvas_core.py +1157 -0
- PYME/LMVis/imageView.py +752 -0
- PYME/LMVis/imageView2.py +372 -0
- PYME/LMVis/importTextDialog.py +342 -0
- PYME/LMVis/layer_panel.py +231 -0
- PYME/LMVis/layers/AxesOverlayLayer.py +126 -0
- PYME/LMVis/layers/LUTOverlayLayer.py +346 -0
- PYME/LMVis/layers/OverlayLayer.py +46 -0
- PYME/LMVis/layers/ScaleBarOverlayLayer.py +97 -0
- PYME/LMVis/layers/ScaleBoxOverlayLayer.py +181 -0
- PYME/LMVis/layers/SelectionOverlayLayer.py +124 -0
- PYME/LMVis/layers/__init__.py +53 -0
- PYME/LMVis/layers/base.py +319 -0
- PYME/LMVis/layers/image_layer.py +363 -0
- PYME/LMVis/layers/labels.py +186 -0
- PYME/LMVis/layers/layer_defaults.py +97 -0
- PYME/LMVis/layers/mesh.py +378 -0
- PYME/LMVis/layers/octree.py +194 -0
- PYME/LMVis/layers/pointcloud.py +372 -0
- PYME/LMVis/layers/quiver.py +271 -0
- PYME/LMVis/layers/text.py +250 -0
- PYME/LMVis/layers/tracks.py +309 -0
- PYME/LMVis/mv_math.py +78 -0
- PYME/LMVis/objectDarkMeasure.py +120 -0
- PYME/LMVis/pipeline.py +1227 -0
- PYME/LMVis/pipelineView.py +115 -0
- PYME/LMVis/pointSettingsPanel.py +135 -0
- PYME/LMVis/progGraph.py +59 -0
- PYME/LMVis/quadTreeSettings.py +90 -0
- PYME/LMVis/rendGauss.py +158 -0
- PYME/LMVis/renderers.py +576 -0
- PYME/LMVis/sessionpaths.py +136 -0
- PYME/LMVis/setup.py +39 -0
- PYME/LMVis/setup_exe.py +71 -0
- PYME/LMVis/shader_programs/DefaultShaderProgram.py +149 -0
- PYME/LMVis/shader_programs/GLProgram.py +119 -0
- PYME/LMVis/shader_programs/GouraudShaderProgram.py +157 -0
- PYME/LMVis/shader_programs/PointSpriteShaderProgram.py +163 -0
- PYME/LMVis/shader_programs/ShaderProgramFactory.py +54 -0
- PYME/LMVis/shader_programs/TesselShaderProgram.py +47 -0
- PYME/LMVis/shader_programs/WireFrameShaderProgram.py +50 -0
- PYME/LMVis/shader_programs/__init__.py +20 -0
- PYME/LMVis/shader_programs/oit_compositor.py +23 -0
- PYME/LMVis/shader_programs/shader_loader.py +84 -0
- PYME/LMVis/shader_programs/shader_program.py +168 -0
- PYME/LMVis/shader_programs/shaders/bigflatpoints_fs.glsl +16 -0
- PYME/LMVis/shader_programs/shaders/bigpoints_gs.glsl +40 -0
- PYME/LMVis/shader_programs/shaders/bigpointsprites_fs.glsl +20 -0
- PYME/LMVis/shader_programs/shaders/bigspheres_fs.glsl +53 -0
- PYME/LMVis/shader_programs/shaders/compose_fs.glsl +41 -0
- PYME/LMVis/shader_programs/shaders/compose_vs.glsl +25 -0
- PYME/LMVis/shader_programs/shaders/default_fs.glsl +27 -0
- PYME/LMVis/shader_programs/shaders/default_vs.glsl +88 -0
- PYME/LMVis/shader_programs/shaders/flatpoints_fs.glsl +27 -0
- PYME/LMVis/shader_programs/shaders/gouraud_flatpoints_fs.glsl +30 -0
- PYME/LMVis/shader_programs/shaders/gouraud_fs.glsl +26 -0
- PYME/LMVis/shader_programs/shaders/gouraud_oit_fs.glsl +68 -0
- PYME/LMVis/shader_programs/shaders/gouraud_vs.glsl +135 -0
- PYME/LMVis/shader_programs/shaders/image_fs.glsl +60 -0
- PYME/LMVis/shader_programs/shaders/image_vs.glsl +79 -0
- PYME/LMVis/shader_programs/shaders/phong_fs.glsl +43 -0
- PYME/LMVis/shader_programs/shaders/phong_vs.glsl +45 -0
- PYME/LMVis/shader_programs/shaders/pointsprites_fs.glsl +33 -0
- PYME/LMVis/shader_programs/shaders/pointsprites_vs.glsl +77 -0
- PYME/LMVis/shader_programs/shaders/spheres_fs.glsl +102 -0
- PYME/LMVis/shader_programs/shaders/tessel_fs.glsl +23 -0
- PYME/LMVis/shader_programs/shaders/tessel_vs.glsl +37 -0
- PYME/LMVis/shader_programs/shaders/text_fs.glsl +42 -0
- PYME/LMVis/shader_programs/shaders/text_vs.glsl +84 -0
- PYME/LMVis/shader_programs/shaders/widelines_fs.glsl +19 -0
- PYME/LMVis/shader_programs/shaders/widelines_gs.glsl +56 -0
- PYME/LMVis/shader_programs/shaders/widelines_vs.glsl +51 -0
- PYME/LMVis/statusLog.py +57 -0
- PYME/LMVis/triBlobs.py +142 -0
- PYME/LMVis/view_clipping_pane.py +429 -0
- PYME/LMVis/views.py +275 -0
- PYME/LMVis/visCore.py +1005 -0
- PYME/LMVis/visHelpers.py +880 -0
- PYME/LMVis/visHelpersMin.py +230 -0
- PYME/LMVis/workspaceTree.py +238 -0
- PYME/__init__.py +22 -0
- PYME/cluster/HTTPDataServer.py +1063 -0
- PYME/cluster/HTTPRulePusher.py +382 -0
- PYME/cluster/HTTPTaskPusher.py +377 -0
- PYME/cluster/PYMERuleNodeServer.py +192 -0
- PYME/cluster/PYMERuleServer.py +109 -0
- PYME/cluster/__init__.py +0 -0
- PYME/cluster/clusterUI/accounts/__init__.py +0 -0
- PYME/cluster/clusterUI/accounts/admin.py +85 -0
- PYME/cluster/clusterUI/accounts/forms.py +8 -0
- PYME/cluster/clusterUI/accounts/migrations/0001_initial.py +31 -0
- PYME/cluster/clusterUI/accounts/migrations/__init__.py +0 -0
- PYME/cluster/clusterUI/accounts/models.py +44 -0
- PYME/cluster/clusterUI/accounts/templates/accounts/user_form.html +13 -0
- PYME/cluster/clusterUI/accounts/templates/registration/initial_complete.html +6 -0
- PYME/cluster/clusterUI/accounts/templates/registration/initial_confirm.html +13 -0
- PYME/cluster/clusterUI/accounts/templates/registration/initial_done.html +7 -0
- PYME/cluster/clusterUI/accounts/templates/registration/verification.html +2 -0
- PYME/cluster/clusterUI/accounts/templates/registration/verification_subject.txt +1 -0
- PYME/cluster/clusterUI/accounts/urls.py +19 -0
- PYME/cluster/clusterUI/accounts/views.py +36 -0
- PYME/cluster/clusterUI/clusterUI/__init__.py +0 -0
- PYME/cluster/clusterUI/clusterUI/settings.py +147 -0
- PYME/cluster/clusterUI/clusterUI/urls.py +31 -0
- PYME/cluster/clusterUI/clusterUI/wsgi.py +16 -0
- PYME/cluster/clusterUI/clusterbrowser/__init__.py +0 -0
- PYME/cluster/clusterUI/clusterbrowser/admin.py +3 -0
- PYME/cluster/clusterUI/clusterbrowser/apps.py +7 -0
- PYME/cluster/clusterUI/clusterbrowser/migrations/__init__.py +0 -0
- PYME/cluster/clusterUI/clusterbrowser/models.py +5 -0
- PYME/cluster/clusterUI/clusterbrowser/templates/base.html +129 -0
- PYME/cluster/clusterUI/clusterbrowser/templates/clusterbrowser/dirlisting.html +231 -0
- PYME/cluster/clusterUI/clusterbrowser/templates/clusterbrowser/form_new_folder.html +18 -0
- PYME/cluster/clusterUI/clusterbrowser/templates/clusterbrowser/form_upload_file.html +17 -0
- PYME/cluster/clusterUI/clusterbrowser/templates/clusterbrowser/lightlisting.html +25 -0
- PYME/cluster/clusterUI/clusterbrowser/templates/registration/login.html +38 -0
- PYME/cluster/clusterUI/clusterbrowser/urls.py +10 -0
- PYME/cluster/clusterUI/clusterbrowser/views.py +148 -0
- PYME/cluster/clusterUI/clusterstatus/__init__.py +0 -0
- PYME/cluster/clusterUI/clusterstatus/admin.py +3 -0
- PYME/cluster/clusterUI/clusterstatus/apps.py +7 -0
- PYME/cluster/clusterUI/clusterstatus/migrations/__init__.py +0 -0
- PYME/cluster/clusterUI/clusterstatus/models.py +5 -0
- PYME/cluster/clusterUI/clusterstatus/templates/clusterstatus/load_content.html +29 -0
- PYME/cluster/clusterUI/clusterstatus/templates/clusterstatus/queue_info.html +28 -0
- PYME/cluster/clusterUI/clusterstatus/templates/clusterstatus/queue_info_content.html +50 -0
- PYME/cluster/clusterUI/clusterstatus/templates/clusterstatus/status_dash.html +29 -0
- PYME/cluster/clusterUI/clusterstatus/templates/clusterstatus/status_dash_content.html +90 -0
- PYME/cluster/clusterUI/clusterstatus/urls.py +9 -0
- PYME/cluster/clusterUI/clusterstatus/views.py +69 -0
- PYME/cluster/clusterUI/clusterui_tornado.py +117 -0
- PYME/cluster/clusterUI/deploy.py +62 -0
- PYME/cluster/clusterUI/localization/__init__.py +0 -0
- PYME/cluster/clusterUI/localization/admin.py +3 -0
- PYME/cluster/clusterUI/localization/apps.py +7 -0
- PYME/cluster/clusterUI/localization/migrations/__init__.py +0 -0
- PYME/cluster/clusterUI/localization/models.py +5 -0
- PYME/cluster/clusterUI/localization/templates/localization/settings_form.html +67 -0
- PYME/cluster/clusterUI/localization/urls.py +10 -0
- PYME/cluster/clusterUI/localization/views.py +170 -0
- PYME/cluster/clusterUI/manage.py +17 -0
- PYME/cluster/clusterUI/recipes/__init__.py +0 -0
- PYME/cluster/clusterUI/recipes/admin.py +3 -0
- PYME/cluster/clusterUI/recipes/migrations/__init__.py +0 -0
- PYME/cluster/clusterUI/recipes/models.py +3 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/extra_inputs.html +35 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/form_recipe.html +82 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/input_list.html +7 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/recipe_editor.html +28 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/recipe_editor_common.html +46 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/recipe_editrun.html +93 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/recipe_standalone.html +100 -0
- PYME/cluster/clusterUI/recipes/templates/recipes/recipe_template.html +109 -0
- PYME/cluster/clusterUI/recipes/urls.py +17 -0
- PYME/cluster/clusterUI/recipes/views.py +109 -0
- PYME/cluster/cluster_of_one.py +200 -0
- PYME/cluster/dataserver_wsgi.py +615 -0
- PYME/cluster/distribution.py +71 -0
- PYME/cluster/rulenodeserver.py +487 -0
- PYME/cluster/rules.py +979 -0
- PYME/cluster/ruleserver.py +1106 -0
- PYME/cluster/status.py +101 -0
- PYME/cluster/taskWorkerHTTP.py +522 -0
- PYME/cluster/webdav.py +1102 -0
- PYME/config.py +659 -0
- PYME/contrib/TextCtrlAutoComplete.py +582 -0
- PYME/contrib/__init__.py +7 -0
- PYME/contrib/aniso/__init__.py +2 -0
- PYME/contrib/aniso/aniso.py +268 -0
- PYME/contrib/auiFloatBook.py +94 -0
- PYME/contrib/congrid.py +127 -0
- PYME/contrib/dispatch/__init__.py +19 -0
- PYME/contrib/dispatch/dispatcher.py +289 -0
- PYME/contrib/gohlke/__init__.py +1 -0
- PYME/contrib/gohlke/_tifffile.cp39-win_amd64.dll.a +0 -0
- PYME/contrib/gohlke/_tifffile.cp39-win_amd64.pyd +0 -0
- PYME/contrib/gohlke/czifile.py +1289 -0
- PYME/contrib/gohlke/fcsfiles.py +514 -0
- PYME/contrib/gohlke/setup.py +54 -0
- PYME/contrib/gohlke/tifffile.py +3095 -0
- PYME/contrib/listctrlMixins.py +896 -0
- PYME/contrib/lzw.py +838 -0
- PYME/contrib/pad/__init__.py +13 -0
- PYME/contrib/pad/info_pad.py +18 -0
- PYME/contrib/pad/pad.py +670 -0
- PYME/contrib/setup.py +38 -0
- PYME/contrib/wxPlotPanel.py +137 -0
- PYME/experimental/SimReconstruction.py +49 -0
- PYME/experimental/__init__.pxd +0 -0
- PYME/experimental/__init__.py +4 -0
- PYME/experimental/_octree.cp39-win_amd64.dll.a +0 -0
- PYME/experimental/_octree.cp39-win_amd64.pyd +0 -0
- PYME/experimental/_octree.pyx +477 -0
- PYME/experimental/_treap.cp39-win_amd64.dll.a +0 -0
- PYME/experimental/_treap.cp39-win_amd64.pyd +0 -0
- PYME/experimental/_treap.pyx +267 -0
- PYME/experimental/_triangle_mesh.cp39-win_amd64.dll.a +0 -0
- PYME/experimental/_triangle_mesh.cp39-win_amd64.pyd +0 -0
- PYME/experimental/_triangle_mesh.pxd +149 -0
- PYME/experimental/_triangle_mesh.pyx +2787 -0
- PYME/experimental/aqavg.py +40 -0
- PYME/experimental/dcimgFileChucker.py +375 -0
- PYME/experimental/dcimgSpoolShim.py +174 -0
- PYME/experimental/dcimg_chuck_test.py +78 -0
- PYME/experimental/dual_marching_cubes.py +801 -0
- PYME/experimental/dual_marching_cubes_v2.py +645 -0
- PYME/experimental/expectationMaximisation.py +298 -0
- PYME/experimental/func_octree.cp39-win_amd64.dll.a +0 -0
- PYME/experimental/func_octree.cp39-win_amd64.pyd +0 -0
- PYME/experimental/func_octree.pyx +381 -0
- PYME/experimental/fusionRadial.py +520 -0
- PYME/experimental/fusionUtils.py +522 -0
- PYME/experimental/isosurface.py +147 -0
- PYME/experimental/labview_spooling_hacks.py +48 -0
- PYME/experimental/marching_cubes.py +811 -0
- PYME/experimental/marching_tetrahedra.py +343 -0
- PYME/experimental/modified_marching_cubes.py +1245 -0
- PYME/experimental/music.py +25 -0
- PYME/experimental/octree.py +188 -0
- PYME/experimental/pSpaceMap.py +34 -0
- PYME/experimental/pointFitConfoc.py +112 -0
- PYME/experimental/scanner_control.py +107 -0
- PYME/experimental/setup.py +109 -0
- PYME/experimental/spark.py +31 -0
- PYME/experimental/tcHist.py +71 -0
- PYME/experimental/treap.py +262 -0
- PYME/experimental/triangle_mesh.py +2287 -0
- PYME/experimental/triangle_mesh_utils.cp39-win_amd64.dll.a +0 -0
- PYME/experimental/triangle_mesh_utils.cp39-win_amd64.pyd +0 -0
- PYME/experimental/triangle_utils.py +87 -0
- PYME/experimental/triangular_mesh.py +2255 -0
- PYME/experimental/zMotionArtifactUtils.py +55 -0
- PYME/localization/FitFactories/AstigGaussFitFR.py +175 -0
- PYME/localization/FitFactories/AstigGaussGPUFitFR.py +326 -0
- PYME/localization/FitFactories/BeadConvolvedAstigGaussFit.py +206 -0
- PYME/localization/FitFactories/ChecksumFR.py +82 -0
- PYME/localization/FitFactories/ChecksumGPUFR.py +213 -0
- PYME/localization/FitFactories/ChecksumMultifitSR.py +86 -0
- PYME/localization/FitFactories/ConfocCOIR.py +93 -0
- PYME/localization/FitFactories/Dumbell3DFitR.py +193 -0
- PYME/localization/FitFactories/DumbellFitR.py +163 -0
- PYME/localization/FitFactories/FFBase.py +403 -0
- PYME/localization/FitFactories/Gauss3DFitR.py +213 -0
- PYME/localization/FitFactories/GaussFitConstrR.py +177 -0
- PYME/localization/FitFactories/GaussMultifitLinesR.py +351 -0
- PYME/localization/FitFactories/GaussMultifitR.py +326 -0
- PYME/localization/FitFactories/GaussMultifitSR.py +373 -0
- PYME/localization/FitFactories/InterpFitR.py +236 -0
- PYME/localization/FitFactories/InterpFitWFR.py +111 -0
- PYME/localization/FitFactories/Interpolators/CSInterpolator.py +148 -0
- PYME/localization/FitFactories/Interpolators/CubeSInterpolatorP.py +121 -0
- PYME/localization/FitFactories/Interpolators/CubicSplineInterpolator.py +69 -0
- PYME/localization/FitFactories/Interpolators/LinearInterpolator.py +135 -0
- PYME/localization/FitFactories/Interpolators/LinearPInterpolatorP.py +95 -0
- PYME/localization/FitFactories/Interpolators/__init__.py +33 -0
- PYME/localization/FitFactories/Interpolators/baseInterpolator.py +202 -0
- PYME/localization/FitFactories/LatFitCOIR.py +82 -0
- PYME/localization/FitFactories/LatGaussFitFR.py +220 -0
- PYME/localization/FitFactories/LatObjFindFR.py +85 -0
- PYME/localization/FitFactories/LatPSFFitR.py +142 -0
- PYME/localization/FitFactories/MultiviewFitInterpNR.py +400 -0
- PYME/localization/FitFactories/PRInterpFitQR.py +192 -0
- PYME/localization/FitFactories/PRInterpFitR.py +223 -0
- PYME/localization/FitFactories/ROIExtractNR.py +93 -0
- PYME/localization/FitFactories/SpecGaussFitFR.py +174 -0
- PYME/localization/FitFactories/SplitterFitCOIR.py +142 -0
- PYME/localization/FitFactories/SplitterFitFNR.py +312 -0
- PYME/localization/FitFactories/SplitterFitFusionR.py +318 -0
- PYME/localization/FitFactories/SplitterFitInterpBNR.py +357 -0
- PYME/localization/FitFactories/SplitterFitInterpNR.py +343 -0
- PYME/localization/FitFactories/SplitterFitScavNR.py +352 -0
- PYME/localization/FitFactories/SplitterMultifitSR.py +410 -0
- PYME/localization/FitFactories/SplitterObjFindR.py +194 -0
- PYME/localization/FitFactories/SplitterROIExtractNR.py +91 -0
- PYME/localization/FitFactories/SplitterShiftEstFR.py +230 -0
- PYME/localization/FitFactories/__init__.py +103 -0
- PYME/localization/FitFactories/fitCommon.py +195 -0
- PYME/localization/FitFactories/zEstimators/__init__.py +29 -0
- PYME/localization/FitFactories/zEstimators/astigEstimator.py +173 -0
- PYME/localization/FitFactories/zEstimators/biplaneEstimator.py +209 -0
- PYME/localization/FitFactories/zEstimators/genericDualEstimator.py +232 -0
- PYME/localization/FitFactories/zEstimators/genericEstimator.py +224 -0
- PYME/localization/FitFactories/zEstimators/priEstimator.py +255 -0
- PYME/localization/MetaDataEdit.py +543 -0
- PYME/localization/Test/30_9_series_A_1.sf +0 -0
- PYME/localization/Test/PRI.md +45 -0
- PYME/localization/Test/PRI_qr.md +52 -0
- PYME/localization/Test/PRI_r.md +52 -0
- PYME/localization/Test/__init__.py +22 -0
- PYME/localization/Test/astig.md +50 -0
- PYME/localization/Test/astigCOI.md +50 -0
- PYME/localization/Test/astig_gauss.md +52 -0
- PYME/localization/Test/astig_pe.md +50 -0
- PYME/localization/Test/astig_splitter.md +66 -0
- PYME/localization/Test/astig_splitterCOI.md +67 -0
- PYME/localization/Test/astig_splitterQ.md +66 -0
- PYME/localization/Test/astig_theory.md +50 -0
- PYME/localization/Test/astig_theory.psf +0 -0
- PYME/localization/Test/astig_theory.tif +0 -0
- PYME/localization/Test/beads1.psf +0 -0
- PYME/localization/Test/beads1.tif +0 -0
- PYME/localization/Test/biplane_splitter.md +75 -0
- PYME/localization/Test/biplane_splitter2.md +103 -0
- PYME/localization/Test/biplane_splitter3.md +115 -0
- PYME/localization/Test/defoc.md +48 -0
- PYME/localization/Test/dumbell_3d.md +52 -0
- PYME/localization/Test/fitTestJig.py +172 -0
- PYME/localization/Test/fitTestJigSCMOS.py +487 -0
- PYME/localization/Test/fitTestJigWC.py +225 -0
- PYME/localization/Test/gauss.md +50 -0
- PYME/localization/Test/gaussCOI.md +50 -0
- PYME/localization/Test/pri_pe.md +50 -0
- PYME/localization/Test/pri_theory.md +51 -0
- PYME/localization/Test/pri_theory.psf +0 -0
- PYME/localization/Test/pri_theory.tif +0 -0
- PYME/localization/Test/psf_astig.psf +0 -0
- PYME/localization/Test/psf_astig.tif +0 -0
- PYME/localization/Test/psf_astig_bg_d.psf +0 -0
- PYME/localization/Test/psf_astig_bg_d.tif +0 -0
- PYME/localization/Test/psf_astig_pe.psf +0 -0
- PYME/localization/Test/psf_astig_pe.tif +0 -0
- PYME/localization/Test/psf_decon.psf +0 -0
- PYME/localization/Test/psf_decon.tif +0 -0
- PYME/localization/Test/psf_decon_pe.psf +0 -0
- PYME/localization/Test/psf_decon_pe.tif +0 -0
- PYME/localization/Test/psf_guess.psf +0 -0
- PYME/localization/Test/splitter.md +63 -0
- PYME/localization/Test/splitter_scav.md +63 -0
- PYME/localization/Test/test.psf +0 -0
- PYME/localization/Test/test.tif +0 -0
- PYME/localization/Test/test_decon.psf +0 -0
- PYME/localization/Test/test_decon.tif +0 -0
- PYME/localization/Test/test_pe.psf +0 -0
- PYME/localization/Test/test_pe.tif +0 -0
- PYME/localization/Test/wf_theory.psf +0 -0
- PYME/localization/Test/wf_theory2.psf +0 -0
- PYME/localization/__init__.py +17 -0
- PYME/localization/autopsf/__init__.py +1 -0
- PYME/localization/autopsf/autopsf.py +486 -0
- PYME/localization/autopsf/roifit.py +310 -0
- PYME/localization/cInterp/__init__.py +24 -0
- PYME/localization/cInterp/cInterp.cp39-win_amd64.dll.a +0 -0
- PYME/localization/cInterp/cInterp.cp39-win_amd64.pyd +0 -0
- PYME/localization/cInterp/setup.py +54 -0
- PYME/localization/cModels/__init__.py +24 -0
- PYME/localization/cModels/gauss_app.cp39-win_amd64.dll.a +0 -0
- PYME/localization/cModels/gauss_app.cp39-win_amd64.pyd +0 -0
- PYME/localization/ofind.py +444 -0
- PYME/localization/ofind3d.py +306 -0
- PYME/localization/ofind_nofilt.py +128 -0
- PYME/localization/ofind_pri.py +478 -0
- PYME/localization/ofind_split.py +399 -0
- PYME/localization/ofind_xcorr.py +351 -0
- PYME/localization/ofind_xcorr_fw.py +441 -0
- PYME/localization/remFitBuf.py +657 -0
- PYME/localization/setup.py +56 -0
- PYME/localization/splitting.py +240 -0
- PYME/localization/twist.py +60 -0
- PYME/misc/TiSettings.py +36 -0
- PYME/misc/TiffImagePlugin.py +838 -0
- PYME/misc/VolProj.py +144 -0
- PYME/misc/__init__.py +25 -0
- PYME/misc/aligned_array.py +10 -0
- PYME/misc/aniso.py +29 -0
- PYME/misc/big_sur_fix.py +20 -0
- PYME/misc/check_for_updates.py +139 -0
- PYME/misc/colormaps.py +199 -0
- PYME/misc/colorsys.py +201 -0
- PYME/misc/computerName.py +33 -0
- PYME/misc/coverslipGeometries.py +60 -0
- PYME/misc/cython_numpy_monkey.py +40 -0
- PYME/misc/depGraph.py +406 -0
- PYME/misc/dirSize.py +31 -0
- PYME/misc/diskCleanup.py +64 -0
- PYME/misc/djangoRecarray.py +57 -0
- PYME/misc/django_widgets.py +27 -0
- PYME/misc/editgrid.py +101 -0
- PYME/misc/eventSpy.py +122 -0
- PYME/misc/exceptions.py +30 -0
- PYME/misc/facsPlot.py +89 -0
- PYME/misc/fbpIcons.py +90 -0
- PYME/misc/fftw_compat.py +28 -0
- PYME/misc/findCycles.py +91 -0
- PYME/misc/fortran_interrupt_defeat.py +43 -0
- PYME/misc/glassModel.py +64 -0
- PYME/misc/hash32.py +41 -0
- PYME/misc/hillcurve.py +88 -0
- PYME/misc/hybrid_ns.py +84 -0
- PYME/misc/kdFit.py +72 -0
- PYME/misc/locate.py +10 -0
- PYME/misc/memUsage.py +65 -0
- PYME/misc/memmap.py +52 -0
- PYME/misc/mock_ctypes.py +28 -0
- PYME/misc/mock_traits.py +59 -0
- PYME/misc/mock_traitsui.py +29 -0
- PYME/misc/pyme_zeroconf.py +287 -0
- PYME/misc/pyro_tracebacks.py +32 -0
- PYME/misc/read_agf.py +605 -0
- PYME/misc/sffake.py +16 -0
- PYME/misc/snells.py +71 -0
- PYME/misc/sqlite_ns.py +132 -0
- PYME/misc/sqlitendarray.py +56 -0
- PYME/misc/taskDef.py +44 -0
- PYME/misc/tempDB.py +56 -0
- PYME/misc/wxThread.py +33 -0
- PYME/misc/zemax.py +259 -0
- PYME/misc/zernike.py +151 -0
- PYME/pyme_warnings.py +70 -0
- PYME/recipes/Recipes/STEDDeconvolution.yaml +14 -0
- PYME/recipes/Recipes/STEDMinistacks.yaml +15 -0
- PYME/recipes/Recipes/STED_COP3.yaml +25 -0
- PYME/recipes/Recipes/blobMeas.yaml +19 -0
- PYME/recipes/Recipes/blobMeas2.yaml +37 -0
- PYME/recipes/Recipes/blobMeasSR.yaml +66 -0
- PYME/recipes/Recipes/coloc.yaml +43 -0
- PYME/recipes/Recipes/coloc_roi_masked.yaml +46 -0
- PYME/recipes/Recipes/multiblob.yaml +38 -0
- PYME/recipes/Recipes/pre_particleTracking.yaml +30 -0
- PYME/recipes/Recipes/segmentAndMeasureLoci.yaml +41 -0
- PYME/recipes/__init__.py +6 -0
- PYME/recipes/acquisition.py +158 -0
- PYME/recipes/bakeshop.py +32 -0
- PYME/recipes/base.py +1393 -0
- PYME/recipes/batchProcess.py +147 -0
- PYME/recipes/filters.py +394 -0
- PYME/recipes/fudges.py +41 -0
- PYME/recipes/graphing.py +108 -0
- PYME/recipes/html_recipe_editor.py +90 -0
- PYME/recipes/localisations.py +1386 -0
- PYME/recipes/machine_learning.py +286 -0
- PYME/recipes/measurement.py +1062 -0
- PYME/recipes/modules.py +50 -0
- PYME/recipes/multiview.py +435 -0
- PYME/recipes/output.py +667 -0
- PYME/recipes/pointcloud.py +510 -0
- PYME/recipes/processing.py +2954 -0
- PYME/recipes/pyramid.py +206 -0
- PYME/recipes/recipe.py +965 -0
- PYME/recipes/recipeGui.py +1029 -0
- PYME/recipes/recipeLayout.py +499 -0
- PYME/recipes/runRecipe.py +140 -0
- PYME/recipes/setup.py +37 -0
- PYME/recipes/simulation.py +91 -0
- PYME/recipes/skfilters.py +143 -0
- PYME/recipes/surface_fitting.py +776 -0
- PYME/recipes/tablefilters.py +275 -0
- PYME/recipes/tracking.py +343 -0
- PYME/recipes/traits.py +157 -0
- PYME/recipes/vertical_recipe_display.py +373 -0
- PYME/resources/__init__.py +23 -0
- PYME/resources/config_template/distributor.yaml +14 -0
- PYME/resources/config_template/nodeserver.yaml +15 -0
- PYME/resources/icons/LUT.png +0 -0
- PYME/resources/icons/YSM_Shield.png +0 -0
- PYME/resources/icons/YSM_logo.png +0 -0
- PYME/resources/icons/arrow.png +0 -0
- PYME/resources/icons/crosshairs.png +0 -0
- PYME/resources/icons/line_select.png +0 -0
- PYME/resources/icons/logo_fmhs.png +0 -0
- PYME/resources/icons/media-playback-pause.png +0 -0
- PYME/resources/icons/media-playback-start.png +0 -0
- PYME/resources/icons/media-skip-backward.png +0 -0
- PYME/resources/icons/media-skip-forward.png +0 -0
- PYME/resources/icons/mesh.png +0 -0
- PYME/resources/icons/mesh.svg +28 -0
- PYME/resources/icons/pmacquire.icns +0 -0
- PYME/resources/icons/pmacquire.ico +0 -0
- PYME/resources/icons/pmanal.icns +0 -0
- PYME/resources/icons/pmanal.ico +0 -0
- PYME/resources/icons/pmvis.icns +0 -0
- PYME/resources/icons/pmvis.ico +0 -0
- PYME/resources/icons/points.png +0 -0
- PYME/resources/icons/points.svg +16 -0
- PYME/resources/icons/pymeLogo.png +0 -0
- PYME/resources/icons/rect_select.png +0 -0
- PYME/resources/icons/squiggle_select.png +0 -0
- PYME/resources/icons/text3800.icns +0 -0
- PYME/resources/icons/text3800.ico +0 -0
- PYME/resources/icons/text3800.png +0 -0
- PYME/resources/icons/text3800.tif +0 -0
- PYME/resources/icons/text5377.icns +0 -0
- PYME/resources/icons/text5377.ico +0 -0
- PYME/resources/icons/text5377.png +0 -0
- PYME/resources/icons/tracks.png +0 -0
- PYME/resources/icons/tracks.svg +19 -0
- PYME/resources/icons/view-front.png +0 -0
- PYME/resources/icons/view-home.png +0 -0
- PYME/resources/icons/view-right.png +0 -0
- PYME/resources/icons/view-top.png +0 -0
- PYME/resources/test_datasets/README.md +8 -0
- PYME/resources/test_datasets/t_im.tif +0 -0
- PYME/resources/test_datasets/test_csv.csv +4282 -0
- PYME/resources/test_datasets/test_hdf.hdf +0 -0
- PYME/resources/web/rule_inline.html +21 -0
- PYME/resources/web/ruleserver.html +75 -0
- PYME/resources/web/static/bootstrap.min.js +7 -0
- PYME/resources/web/static/cluster.css +137 -0
- PYME/resources/web/static/css/bootstrap-theme.css +587 -0
- PYME/resources/web/static/css/bootstrap-theme.min.css +6 -0
- PYME/resources/web/static/css/bootstrap.css +6757 -0
- PYME/resources/web/static/css/bootstrap.min.css +6 -0
- PYME/resources/web/static/css/flat_design_colors_full.css +306 -0
- PYME/resources/web/static/css/recipe_editor.css +106 -0
- PYME/resources/web/static/dashboard.css +106 -0
- PYME/resources/web/static/fileselector.js +77 -0
- PYME/resources/web/static/fonts/glyphicons-halflings-regular.eot +0 -0
- PYME/resources/web/static/fonts/glyphicons-halflings-regular.svg +288 -0
- PYME/resources/web/static/fonts/glyphicons-halflings-regular.ttf +0 -0
- PYME/resources/web/static/fonts/glyphicons-halflings-regular.woff +0 -0
- PYME/resources/web/static/fonts/glyphicons-halflings-regular.woff2 +0 -0
- PYME/resources/web/static/images/osd_flat/LICENSE.txt +116 -0
- PYME/resources/web/static/images/osd_flat/README.md +9 -0
- PYME/resources/web/static/images/osd_flat/fullpage_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/fullpage_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/fullpage_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/fullpage_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/home_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/home_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/home_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/home_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/next_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/next_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/next_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/next_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/previous_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/previous_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/previous_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/previous_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateleft_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateleft_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateleft_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateleft_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateright_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateright_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateright_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/rotateright_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomin_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomin_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomin_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomin_rest.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomout_grouphover.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomout_hover.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomout_pressed.png +0 -0
- PYME/resources/web/static/images/osd_flat/zoomout_rest.png +0 -0
- PYME/resources/web/static/jigna-vue-bare.js +1395 -0
- PYME/resources/web/static/jquery.min.js +2 -0
- PYME/resources/web/static/jstree.min.js +6 -0
- PYME/resources/web/static/openSeadragonGL.js +102 -0
- PYME/resources/web/static/openseadragon-svg-overlay.js +103 -0
- PYME/resources/web/static/openseadragon-viewerinputhook.min.js +6 -0
- PYME/resources/web/static/openseadragon.min.js +9 -0
- PYME/resources/web/static/recipe_editor.js +119 -0
- PYME/resources/web/static/shaders/fragment/lut.glsl +20 -0
- PYME/resources/web/static/shaders/fragment/none.glsl +17 -0
- PYME/resources/web/static/shaders/fragment/outline.glsl +43 -0
- PYME/resources/web/static/shaders/fragment/rect.glsl +7 -0
- PYME/resources/web/static/shaders/fragment/sobel3.glsl +71 -0
- PYME/resources/web/static/shaders/fragment/white.glsl +4 -0
- PYME/resources/web/static/shaders/vertex/rect.glsl +22 -0
- PYME/resources/web/static/shaders/vertex/square.glsl +9 -0
- PYME/resources/web/static/utils.js +3 -0
- PYME/resources/web/static/viaWebGL.js +217 -0
- PYME/setup.py +109 -0
- PYME/setup_exe.py +57 -0
- PYME/simulation/__init__.py +0 -0
- PYME/simulation/locify.py +319 -0
- PYME/simulation/pointsets.py +279 -0
- PYME/simulation/wormlike.py +99 -0
- PYME/simulation/wormlike2.py +198 -0
- PYME/simulation/wormlike3.py +197 -0
- PYME/simulation/wormlike_curled.py +104 -0
- PYME/tileviewer/__init__.py +0 -0
- PYME/tileviewer/templates/roi_list.html +12 -0
- PYME/tileviewer/templates/tileviewer.html +247 -0
- PYME/tileviewer/tileviewer.py +207 -0
- PYME/ui/AUIFrame.py +279 -0
- PYME/ui/MetadataTree.py +469 -0
- PYME/ui/__init__.py +4 -0
- PYME/ui/about_dlg.py +29 -0
- PYME/ui/autoFoldPanel.py +643 -0
- PYME/ui/cascading_layout.py +45 -0
- PYME/ui/crop_dialog.py +145 -0
- PYME/ui/custom_traits_editors.py +508 -0
- PYME/ui/editFilterDialog.py +80 -0
- PYME/ui/editList.py +40 -0
- PYME/ui/fastGraph.py +240 -0
- PYME/ui/filterPane.py +348 -0
- PYME/ui/histLimits.py +543 -0
- PYME/ui/layerFoldPanel.py +232 -0
- PYME/ui/manualFoldPanel.py +870 -0
- PYME/ui/mytimer.py +116 -0
- PYME/ui/patch_traitsui.py +151 -0
- PYME/ui/progress.py +160 -0
- PYME/ui/recArrayView.py +145 -0
- PYME/ui/selection.py +71 -0
- PYME/ui/shell.py +37 -0
- PYME/ui/traitsui_constants.py +91 -0
- PYME/ui/wx_compat.py +43 -0
- PYME/update_version.py +159 -0
- PYME/util/__init__.py +3 -0
- PYME/util/authenticate.py +164 -0
- PYME/util/execfile.py +21 -0
- PYME/util/fProfile/__init__.py +1 -0
- PYME/util/fProfile/convertProfile.py +117 -0
- PYME/util/fProfile/fProfile.py +162 -0
- PYME/util/fProfile/html/404.html +60 -0
- PYME/util/fProfile/html/css/main.css +258 -0
- PYME/util/fProfile/html/css/normalize.css +427 -0
- PYME/util/fProfile/html/css/normalize.min.css +1 -0
- PYME/util/fProfile/html/index.html +64 -0
- PYME/util/fProfile/html/js/main.js +492 -0
- PYME/util/fProfile/html/js/plugins.js +24 -0
- PYME/util/fProfile/html/js/vendor/crossfilter.min.js +1 -0
- PYME/util/fProfile/html/js/vendor/jquery-1.11.2.min.js +4 -0
- PYME/util/fProfile/html/js/vendor/modernizr-2.8.3.min.js +4 -0
- PYME/util/fProfile/html/js/vendor/tinycolor-min.js +4 -0
- PYME/util/fProfile/viewProfile.py +30 -0
- PYME/util/install_dependencies.py +95 -0
- PYME/util/log_verbosity.py +11 -0
- PYME/util/mProfile/__init__.py +1 -0
- PYME/util/mProfile/colorize_db_t.py +297 -0
- PYME/util/mProfile/mProfile.py +164 -0
- PYME/util/mProfile/p.py +101 -0
- PYME/util/mProfile/tProfile.py +165 -0
- PYME/util/pymelauncher.py +47 -0
- PYME/util/shmarray/__init__.py +0 -0
- PYME/util/shmarray/shmTest.py +74 -0
- PYME/util/shmarray/shmarray.py +165 -0
- PYME/util/webframework.py +365 -0
- PYME/version.py +65 -0
- python_microscopy-25.6.5.dist-info/METADATA +68 -0
- python_microscopy-25.6.5.dist-info/RECORD +1277 -0
- python_microscopy-25.6.5.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,3095 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# tifffile.py
|
|
4
|
+
|
|
5
|
+
# Copyright (c) 2008-2012, Christoph Gohlke
|
|
6
|
+
# Copyright (c) 2008-2012, The Regents of the University of California
|
|
7
|
+
# Produced at the Laboratory for Fluorescence Dynamics
|
|
8
|
+
# All rights reserved.
|
|
9
|
+
#
|
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
|
12
|
+
#
|
|
13
|
+
# * Redistributions of source code must retain the above copyright
|
|
14
|
+
# notice, this list of conditions and the following disclaimer.
|
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
16
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
17
|
+
# documentation and/or other materials provided with the distribution.
|
|
18
|
+
# * Neither the name of the copyright holders nor the names of any
|
|
19
|
+
# contributors may be used to endorse or promote products derived
|
|
20
|
+
# from this software without specific prior written permission.
|
|
21
|
+
#
|
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
+
|
|
34
|
+
"""Read and write image data from and to TIFF files.
|
|
35
|
+
|
|
36
|
+
Image and meta-data can be read from TIFF, BigTIFF, OME-TIFF, STK, LSM, NIH,
|
|
37
|
+
and FluoView files. Only a subset of the TIFF specification is supported,
|
|
38
|
+
mainly uncompressed and losslessly compressed 2**(0 to 6) bit integer,
|
|
39
|
+
16, 32 and 64-bit float, grayscale and RGB(A) images, which are commonly
|
|
40
|
+
used in bio-scientific imaging. Specifically, reading JPEG or CCITT
|
|
41
|
+
compressed image data is not implemented. Only primary info records are
|
|
42
|
+
read for STK, FluoView, and NIH image formats.
|
|
43
|
+
|
|
44
|
+
TIFF, the Tagged Image File Format, is under the control of Adobe Systems.
|
|
45
|
+
BigTIFF allows for files greater than 4 GB. STK, LSM, FluoView, and OME-TIFF
|
|
46
|
+
are custom extensions defined by MetaMorph, Carl Zeiss MicroImaging,
|
|
47
|
+
Olympus, and the Open Microscopy Environment consortium respectively.
|
|
48
|
+
|
|
49
|
+
The API is not stable yet and might change between revisions.
|
|
50
|
+
Tested on little-endian platforms only.
|
|
51
|
+
|
|
52
|
+
For command line usage run ``python tifffile.py --help``
|
|
53
|
+
|
|
54
|
+
:Authors:
|
|
55
|
+
`Christoph Gohlke <http://www.lfd.uci.edu/~gohlke/>`__,
|
|
56
|
+
Laboratory for Fluorescence Dynamics, University of California, Irvine
|
|
57
|
+
|
|
58
|
+
:Version: 2012.04.21
|
|
59
|
+
|
|
60
|
+
Requirements
|
|
61
|
+
------------
|
|
62
|
+
|
|
63
|
+
* `Python 2.7 or 3.2 <http://www.python.org>`__
|
|
64
|
+
* `Numpy 1.6 <http://numpy.scipy.org>`__
|
|
65
|
+
* `Matplotlib 1.1 <http://matplotlib.sourceforge.net>`__
|
|
66
|
+
(optional for plotting)
|
|
67
|
+
* `tifffile.c 2012.01.01 <http://www.lfd.uci.edu/~gohlke/>`__
|
|
68
|
+
(optional for faster decoding of PackBits and LZW encoded strings)
|
|
69
|
+
|
|
70
|
+
Acknowledgements
|
|
71
|
+
----------------
|
|
72
|
+
* Egor Zindy, University of Manchester, for cz_lsm_scan_info specifics.
|
|
73
|
+
* Wim Lewis, for a bug fix and some read_cz_lsm functions.
|
|
74
|
+
|
|
75
|
+
References
|
|
76
|
+
----------
|
|
77
|
+
|
|
78
|
+
(1) TIFF 6.0 Specification and Supplements. Adobe Systems Incorporated.
|
|
79
|
+
http://partners.adobe.com/public/developer/tiff/
|
|
80
|
+
(2) TIFF File Format FAQ. http://www.awaresystems.be/imaging/tiff/faq.html
|
|
81
|
+
(3) MetaMorph Stack (STK) Image File Format.
|
|
82
|
+
http://support.meta.moleculardevices.com/docs/t10243.pdf
|
|
83
|
+
(4) File Format Description - LSM 5xx Release 2.0.
|
|
84
|
+
http://ibb.gsf.de/homepage/karsten.rodenacker/IDL/Lsmfile.doc
|
|
85
|
+
(5) BioFormats. http://www.loci.wisc.edu/ome/formats.html
|
|
86
|
+
(6) The OME-TIFF format.
|
|
87
|
+
http://www.openmicroscopy.org/site/support/file-formats/ome-tiff
|
|
88
|
+
|
|
89
|
+
Examples
|
|
90
|
+
--------
|
|
91
|
+
|
|
92
|
+
>>> data = numpy.random.rand(301, 219)
|
|
93
|
+
>>> imsave('temp.tif', data)
|
|
94
|
+
>>> image = imread('temp.tif')
|
|
95
|
+
>>> assert numpy.all(image == data)
|
|
96
|
+
|
|
97
|
+
>>> tif = TIFFfile('test.tif')
|
|
98
|
+
>>> images = tif.asarray()
|
|
99
|
+
>>> image0 = tif[0].asarray()
|
|
100
|
+
>>> for page in tif:
|
|
101
|
+
... for tag in page.tags.values():
|
|
102
|
+
... t = tag.name, tag.value
|
|
103
|
+
... image = page.asarray()
|
|
104
|
+
... if page.is_rgb: pass
|
|
105
|
+
... if page.is_palette:
|
|
106
|
+
... t = page.color_map
|
|
107
|
+
... if page.is_stk:
|
|
108
|
+
... t = page.mm_uic_tags.number_planes
|
|
109
|
+
... if page.is_lsm:
|
|
110
|
+
... t = page.cz_lsm_info
|
|
111
|
+
>>> tif.close()
|
|
112
|
+
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
from __future__ import division, print_function
|
|
116
|
+
|
|
117
|
+
import sys
|
|
118
|
+
import os
|
|
119
|
+
import math
|
|
120
|
+
import zlib
|
|
121
|
+
import time
|
|
122
|
+
import struct
|
|
123
|
+
import warnings
|
|
124
|
+
import datetime
|
|
125
|
+
import collections
|
|
126
|
+
from xml.etree import cElementTree as ElementTree
|
|
127
|
+
|
|
128
|
+
import numpy
|
|
129
|
+
|
|
130
|
+
__all__ = ['imsave', 'imread', 'imshow', 'TIFFfile']
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def imsave(filename, data, photometric=None, planarconfig=None,
|
|
134
|
+
resolution=None, description=None, software='tifffile.py',
|
|
135
|
+
byteorder=None, bigtiff=False):
|
|
136
|
+
"""Write image data to TIFF file.
|
|
137
|
+
|
|
138
|
+
Image data are written uncompressed in one stripe per plane.
|
|
139
|
+
Dimensions larger than 2 or 3 (depending on photometric mode and
|
|
140
|
+
planar configuration) are flattened and saved as separate pages.
|
|
141
|
+
|
|
142
|
+
Arguments
|
|
143
|
+
---------
|
|
144
|
+
|
|
145
|
+
filename : str
|
|
146
|
+
Name of file to write.
|
|
147
|
+
|
|
148
|
+
data : array_like
|
|
149
|
+
Input image. The last dimensions are assumed to be image height,
|
|
150
|
+
width, and samples.
|
|
151
|
+
|
|
152
|
+
photometric : {'minisblack', 'miniswhite', 'rgb'}
|
|
153
|
+
The color space of the image data.
|
|
154
|
+
By default this setting is inferred from the data shape.
|
|
155
|
+
|
|
156
|
+
planarconfig : {'contig', 'planar'}
|
|
157
|
+
Specifies if samples are stored contiguous or in separate planes.
|
|
158
|
+
By default this setting is inferred from the data shape.
|
|
159
|
+
'contig': last dimension contains samples.
|
|
160
|
+
'planar': third last dimension contains samples.
|
|
161
|
+
|
|
162
|
+
resolution : ((int, int), (int, int))
|
|
163
|
+
X and Y resolution in dots per inch as rational numbers.
|
|
164
|
+
|
|
165
|
+
description : str
|
|
166
|
+
The subject of the image. Saved with the first page only.
|
|
167
|
+
|
|
168
|
+
software : str
|
|
169
|
+
Name of the software used to create the image.
|
|
170
|
+
Saved with the first page only.
|
|
171
|
+
|
|
172
|
+
byteorder : {'<', '>'}
|
|
173
|
+
The endianness of the data in the file.
|
|
174
|
+
By default this is the system's native byte order.
|
|
175
|
+
|
|
176
|
+
bigtiff : bool
|
|
177
|
+
If True the BigTIFF format is used.
|
|
178
|
+
By default the standard TIFF format is used for data less than 2040 MB.
|
|
179
|
+
|
|
180
|
+
Example
|
|
181
|
+
-------
|
|
182
|
+
|
|
183
|
+
>>> data = numpy.random.rand(10, 3, 301, 219)
|
|
184
|
+
>>> imsave('temp.tif', data)
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
assert(photometric in (None, 'minisblack', 'miniswhite', 'rgb'))
|
|
188
|
+
assert(planarconfig in (None, 'contig', 'planar'))
|
|
189
|
+
assert(byteorder in (None, '<', '>'))
|
|
190
|
+
|
|
191
|
+
if byteorder is None:
|
|
192
|
+
byteorder = '<' if sys.byteorder == 'little' else '>'
|
|
193
|
+
|
|
194
|
+
data = numpy.asarray(data, dtype=byteorder+data.dtype.char, order='C')
|
|
195
|
+
data_shape = shape = data.shape
|
|
196
|
+
data = numpy.atleast_2d(data)
|
|
197
|
+
|
|
198
|
+
if not bigtiff and data.size * data.dtype.itemsize < 2040*2**20:
|
|
199
|
+
bigtiff = False
|
|
200
|
+
offset_size = 4
|
|
201
|
+
tag_size = 12
|
|
202
|
+
numtag_format = 'H'
|
|
203
|
+
offset_format = 'I'
|
|
204
|
+
val_format = '4s'
|
|
205
|
+
else:
|
|
206
|
+
bigtiff = True
|
|
207
|
+
offset_size = 8
|
|
208
|
+
tag_size = 20
|
|
209
|
+
numtag_format = 'Q'
|
|
210
|
+
offset_format = 'Q'
|
|
211
|
+
val_format = '8s'
|
|
212
|
+
|
|
213
|
+
# unify shape of data
|
|
214
|
+
samplesperpixel = 1
|
|
215
|
+
extrasamples = 0
|
|
216
|
+
if photometric is None:
|
|
217
|
+
if data.ndim > 2 and (shape[-3] in (3, 4) or shape[-1] in (3, 4)):
|
|
218
|
+
photometric = 'rgb'
|
|
219
|
+
else:
|
|
220
|
+
photometric = 'minisblack'
|
|
221
|
+
if photometric == 'rgb':
|
|
222
|
+
if len(shape) < 3:
|
|
223
|
+
raise ValueError("not a RGB(A) image")
|
|
224
|
+
if planarconfig is None:
|
|
225
|
+
planarconfig = 'planar' if shape[-3] in (3, 4) else 'contig'
|
|
226
|
+
if planarconfig == 'contig':
|
|
227
|
+
if shape[-1] not in (3, 4):
|
|
228
|
+
raise ValueError("not a contiguous RGB(A) image")
|
|
229
|
+
data = data.reshape((-1, 1) + shape[-3:])
|
|
230
|
+
samplesperpixel = shape[-1]
|
|
231
|
+
else:
|
|
232
|
+
if shape[-3] not in (3, 4):
|
|
233
|
+
raise ValueError("not a planar RGB(A) image")
|
|
234
|
+
data = data.reshape((-1, ) + shape[-3:] + (1, ))
|
|
235
|
+
samplesperpixel = shape[-3]
|
|
236
|
+
if samplesperpixel == 4:
|
|
237
|
+
extrasamples = 1
|
|
238
|
+
elif planarconfig and len(shape) > 2:
|
|
239
|
+
if planarconfig == 'contig':
|
|
240
|
+
data = data.reshape((-1, 1) + shape[-3:])
|
|
241
|
+
samplesperpixel = shape[-1]
|
|
242
|
+
else:
|
|
243
|
+
data = data.reshape((-1, ) + shape[-3:] + (1, ))
|
|
244
|
+
samplesperpixel = shape[-3]
|
|
245
|
+
extrasamples = samplesperpixel - 1
|
|
246
|
+
else:
|
|
247
|
+
planarconfig = None
|
|
248
|
+
data = data.reshape((-1, 1) + shape[-2:] + (1, ))
|
|
249
|
+
|
|
250
|
+
shape = data.shape # (pages, planes, height, width, contig samples)
|
|
251
|
+
|
|
252
|
+
bytestr = bytes if sys.version[0] == '2' else lambda x: bytes(x, 'ascii')
|
|
253
|
+
tifftypes = {'B': 1, 's': 2, 'H': 3, 'I': 4, '2I': 5, 'b': 6,
|
|
254
|
+
'h': 8, 'i': 9, 'f': 11, 'd': 12, 'Q': 16, 'q': 17}
|
|
255
|
+
tifftags = {'new_subfile_type': 254, 'subfile_type': 255,
|
|
256
|
+
'image_width': 256, 'image_length': 257, 'bits_per_sample': 258,
|
|
257
|
+
'compression': 259, 'photometric': 262, 'fill_order': 266,
|
|
258
|
+
'document_name': 269, 'image_description': 270, 'strip_offsets': 273,
|
|
259
|
+
'orientation': 274, 'samples_per_pixel': 277, 'rows_per_strip': 278,
|
|
260
|
+
'strip_byte_counts': 279, 'x_resolution': 282, 'y_resolution': 283,
|
|
261
|
+
'planar_configuration': 284, 'page_name': 285, 'resolution_unit': 296,
|
|
262
|
+
'software': 305, 'datetime': 306, 'predictor': 317, 'color_map': 320,
|
|
263
|
+
'extra_samples': 338, 'sample_format': 339}
|
|
264
|
+
|
|
265
|
+
tags = []
|
|
266
|
+
tag_data = []
|
|
267
|
+
|
|
268
|
+
def pack(fmt, *val):
|
|
269
|
+
return struct.pack(byteorder+fmt, *val)
|
|
270
|
+
|
|
271
|
+
def tag(name, dtype, number, value, offset=[0]):
|
|
272
|
+
# append tag binary string to tags list
|
|
273
|
+
# append (offset, value as binary string) to tag_data list
|
|
274
|
+
# increment offset by tag_size
|
|
275
|
+
if dtype == 's':
|
|
276
|
+
value = bytestr(value) + b'\0'
|
|
277
|
+
number = len(value)
|
|
278
|
+
value = (value, )
|
|
279
|
+
t = [pack('HH', tifftags[name], tifftypes[dtype]),
|
|
280
|
+
pack(offset_format, number)]
|
|
281
|
+
if len(dtype) > 1:
|
|
282
|
+
number *= int(dtype[:-1])
|
|
283
|
+
dtype = dtype[-1]
|
|
284
|
+
if number == 1:
|
|
285
|
+
if isinstance(value, (tuple, list)):
|
|
286
|
+
value = value[0]
|
|
287
|
+
t.append(pack(val_format, pack(dtype, value)))
|
|
288
|
+
elif struct.calcsize(dtype) * number <= offset_size:
|
|
289
|
+
t.append(pack(val_format, pack(str(number)+dtype, *value)))
|
|
290
|
+
else:
|
|
291
|
+
t.append(pack(offset_format, 0))
|
|
292
|
+
tag_data.append((offset[0] + offset_size + 4,
|
|
293
|
+
pack(str(number)+dtype, *value)))
|
|
294
|
+
tags.append(b''.join(t))
|
|
295
|
+
offset[0] += tag_size
|
|
296
|
+
|
|
297
|
+
if software:
|
|
298
|
+
tag('software', 's', 0, software)
|
|
299
|
+
if description:
|
|
300
|
+
tag('image_description', 's', 0, description)
|
|
301
|
+
elif shape != data_shape:
|
|
302
|
+
tag('image_description', 's', 0,
|
|
303
|
+
"shape=(%s)" % (",".join('%i' % i for i in data_shape)))
|
|
304
|
+
tag('datetime', 's', 0,
|
|
305
|
+
datetime.datetime.now().strftime("%Y:%m:%d %H:%M:%S"))
|
|
306
|
+
# write previous tags only once
|
|
307
|
+
writeonce = (len(tags), len(tag_data)) if shape[0] > 1 else None
|
|
308
|
+
tag('compression', 'H', 1, 1)
|
|
309
|
+
tag('orientation', 'H', 1, 1)
|
|
310
|
+
tag('image_width', 'I', 1, shape[-2])
|
|
311
|
+
tag('image_length', 'I', 1, shape[-3])
|
|
312
|
+
tag('new_subfile_type', 'I', 1, 0 if shape[0] == 1 else 2)
|
|
313
|
+
tag('sample_format', 'H', 1,
|
|
314
|
+
{'u': 1, 'i': 2, 'f': 3, 'c': 6}[data.dtype.kind])
|
|
315
|
+
tag('photometric', 'H', 1,
|
|
316
|
+
{'miniswhite': 0, 'minisblack': 1, 'rgb': 2}[photometric])
|
|
317
|
+
tag('samples_per_pixel', 'H', 1, samplesperpixel)
|
|
318
|
+
if planarconfig:
|
|
319
|
+
tag('planar_configuration', 'H', 1, 1 if planarconfig=='contig' else 2)
|
|
320
|
+
tag('bits_per_sample', 'H', samplesperpixel,
|
|
321
|
+
(data.dtype.itemsize * 8, ) * samplesperpixel)
|
|
322
|
+
else:
|
|
323
|
+
tag('bits_per_sample', 'H', 1, data.dtype.itemsize * 8)
|
|
324
|
+
if extrasamples:
|
|
325
|
+
if photometric == 'rgb':
|
|
326
|
+
tag('extra_samples', 'H', 1, 1) # alpha channel
|
|
327
|
+
else:
|
|
328
|
+
tag('extra_samples', 'H', extrasamples, (0, ) * extrasamples)
|
|
329
|
+
if resolution:
|
|
330
|
+
tag('x_resolution', '2I', 1, resolution[0])
|
|
331
|
+
tag('y_resolution', '2I', 1, resolution[1])
|
|
332
|
+
tag('resolution_unit', 'H', 1, 2)
|
|
333
|
+
tag('rows_per_strip', 'I', 1, shape[-3])
|
|
334
|
+
# use one strip per plane
|
|
335
|
+
strip_byte_counts = (data[0, 0].size * data.dtype.itemsize, ) * shape[1]
|
|
336
|
+
tag('strip_byte_counts', offset_format, shape[1], strip_byte_counts)
|
|
337
|
+
# strip_offsets must be the last tag; will be updated later
|
|
338
|
+
tag('strip_offsets', offset_format, shape[1], (0, ) * shape[1])
|
|
339
|
+
|
|
340
|
+
fd = open(filename, 'wb')
|
|
341
|
+
seek = fd.seek
|
|
342
|
+
tell = fd.tell
|
|
343
|
+
|
|
344
|
+
def write(arg, *args):
|
|
345
|
+
fd.write(pack(arg, *args) if args else arg)
|
|
346
|
+
|
|
347
|
+
write({'<': b'II', '>': b'MM'}[byteorder])
|
|
348
|
+
if bigtiff:
|
|
349
|
+
write('HHH', 43, 8, 0)
|
|
350
|
+
else:
|
|
351
|
+
write('H', 42)
|
|
352
|
+
ifd_offset = tell()
|
|
353
|
+
write(offset_format, 0) # first IFD
|
|
354
|
+
for i in range(shape[0]):
|
|
355
|
+
# update pointer at ifd_offset
|
|
356
|
+
pos = tell()
|
|
357
|
+
seek(ifd_offset)
|
|
358
|
+
write(offset_format, pos)
|
|
359
|
+
seek(pos)
|
|
360
|
+
# write tags
|
|
361
|
+
write(numtag_format, len(tags))
|
|
362
|
+
tag_offset = tell()
|
|
363
|
+
write(b''.join(tags))
|
|
364
|
+
ifd_offset = tell()
|
|
365
|
+
write(offset_format, 0) # offset to next ifd
|
|
366
|
+
# write extra tag data and update pointers
|
|
367
|
+
for off, dat in tag_data:
|
|
368
|
+
pos = tell()
|
|
369
|
+
seek(tag_offset + off)
|
|
370
|
+
write(offset_format, pos)
|
|
371
|
+
seek(pos)
|
|
372
|
+
write(dat)
|
|
373
|
+
# update strip_offsets
|
|
374
|
+
pos = tell()
|
|
375
|
+
if len(strip_byte_counts) == 1:
|
|
376
|
+
seek(ifd_offset - offset_size)
|
|
377
|
+
write(offset_format, pos)
|
|
378
|
+
else:
|
|
379
|
+
seek(pos - offset_size*shape[1])
|
|
380
|
+
strip_offset = pos
|
|
381
|
+
for size in strip_byte_counts:
|
|
382
|
+
write(offset_format, strip_offset)
|
|
383
|
+
strip_offset += size
|
|
384
|
+
seek(pos)
|
|
385
|
+
# write data
|
|
386
|
+
data[i].tofile(fd) # if this fails, try update Python and numpy
|
|
387
|
+
fd.flush()
|
|
388
|
+
# remove tags that should be written only once
|
|
389
|
+
if writeonce:
|
|
390
|
+
tags = tags[writeonce[0]:]
|
|
391
|
+
d = writeonce[0] * tag_size
|
|
392
|
+
tag_data = [(o-d, v) for (o, v) in tag_data[writeonce[1]:]]
|
|
393
|
+
writeonce = None
|
|
394
|
+
fd.close()
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
#modified by D. Baddeley for different image dimensionality and to avoid the
|
|
398
|
+
#requirement for the whole image to be in memory
|
|
399
|
+
#also saves each colour channel as an individual plane for better compatibility with
|
|
400
|
+
#ImageJ / OME
|
|
401
|
+
def imsave_f(filename, data,
|
|
402
|
+
resolution=None, description=None, software='tifffile.py',
|
|
403
|
+
byteorder=None, bigtiff=False):
|
|
404
|
+
"""Write image data to TIFF file.
|
|
405
|
+
|
|
406
|
+
Image data are written uncompressed in one stripe per plane.
|
|
407
|
+
Dimensions larger than 2 are flattened and saved as separate pages.
|
|
408
|
+
|
|
409
|
+
Arguments
|
|
410
|
+
---------
|
|
411
|
+
|
|
412
|
+
filename : str
|
|
413
|
+
Name of file to write.
|
|
414
|
+
|
|
415
|
+
data : array_like
|
|
416
|
+
Input image. The first two dimensions are assumed to be imagewidth and height (x & y)
|
|
417
|
+
The following ones, time/z and colour.
|
|
418
|
+
|
|
419
|
+
resolution : ((int, int), (int, int))
|
|
420
|
+
X and Y resolution in dots per inch as rational numbers.
|
|
421
|
+
|
|
422
|
+
description : str
|
|
423
|
+
The subject of the image. Saved with the first page only.
|
|
424
|
+
|
|
425
|
+
software : str
|
|
426
|
+
Name of the software used to create the image.
|
|
427
|
+
Saved with the first page only.
|
|
428
|
+
|
|
429
|
+
byteorder : {'<', '>'}
|
|
430
|
+
The endianness of the data in the file.
|
|
431
|
+
By default this is the system's native byte order.
|
|
432
|
+
|
|
433
|
+
bigtiff : bool
|
|
434
|
+
If True the BigTIFF format is used.
|
|
435
|
+
By default the standard TIFF format is used for data less than 2040 MB.
|
|
436
|
+
|
|
437
|
+
Example
|
|
438
|
+
-------
|
|
439
|
+
|
|
440
|
+
>>> data = numpy.random.rand(10, 3, 301, 219)
|
|
441
|
+
>>> imsave('temp.tif', data)
|
|
442
|
+
|
|
443
|
+
"""
|
|
444
|
+
#assert(photometric in (None, 'minisblack', 'miniswhite', 'rgb'))
|
|
445
|
+
#assert(planarconfig in (None, 'contig', 'planar'))
|
|
446
|
+
photometric = 'minisblack'
|
|
447
|
+
assert(byteorder in (None, '<', '>'))
|
|
448
|
+
|
|
449
|
+
if byteorder is None:
|
|
450
|
+
byteorder = '<' if sys.byteorder == 'little' else '>'
|
|
451
|
+
|
|
452
|
+
#don't modify data here (forces copy or bringing it into memory)
|
|
453
|
+
#data = numpy.asarray(data, dtype=byteorder+data.dtype.char, order='C')
|
|
454
|
+
data_shape = shape = data.shape
|
|
455
|
+
#data = numpy.atleast_2d(data)
|
|
456
|
+
num_planes = numpy.prod(shape[2:])
|
|
457
|
+
|
|
458
|
+
frame0 = data[:,:,0,0,0]
|
|
459
|
+
data_type = frame0.dtype
|
|
460
|
+
|
|
461
|
+
if data_type == 'float64':
|
|
462
|
+
#force downcast as no-one understands 64bit float tiffs
|
|
463
|
+
#NB actual downcast occurs on a per-frame basis just before write so we
|
|
464
|
+
#don't need to load everything into memory here
|
|
465
|
+
data_type = numpy.dtype('float32')
|
|
466
|
+
|
|
467
|
+
data_size = frame0.size*data_type.itemsize*num_planes
|
|
468
|
+
|
|
469
|
+
if not bigtiff and data_size < 2040*2**20:
|
|
470
|
+
bigtiff = False
|
|
471
|
+
offset_size = 4
|
|
472
|
+
tag_size = 12
|
|
473
|
+
numtag_format = 'H'
|
|
474
|
+
offset_format = 'I'
|
|
475
|
+
val_format = '4s'
|
|
476
|
+
else:
|
|
477
|
+
bigtiff = True
|
|
478
|
+
offset_size = 8
|
|
479
|
+
tag_size = 20
|
|
480
|
+
numtag_format = 'Q'
|
|
481
|
+
offset_format = 'Q'
|
|
482
|
+
val_format = '8s'
|
|
483
|
+
|
|
484
|
+
# unify shape of data
|
|
485
|
+
samplesperpixel = 1
|
|
486
|
+
#extrasamples = 0
|
|
487
|
+
# if photometric is None:
|
|
488
|
+
# if data.ndim > 2 and (shape[-3] in (3, 4) or shape[-1] in (3, 4)):
|
|
489
|
+
# photometric = 'rgb'
|
|
490
|
+
# else:
|
|
491
|
+
# photometric = 'minisblack'
|
|
492
|
+
# if photometric == 'rgb':
|
|
493
|
+
# if len(shape) < 3:
|
|
494
|
+
# raise ValueError("not a RGB(A) image")
|
|
495
|
+
# if planarconfig is None:
|
|
496
|
+
# planarconfig = 'planar' if shape[-3] in (3, 4) else 'contig'
|
|
497
|
+
# if planarconfig == 'contig':
|
|
498
|
+
# if shape[-1] not in (3, 4):
|
|
499
|
+
# raise ValueError("not a contiguous RGB(A) image")
|
|
500
|
+
# data = data.reshape((-1, 1) + shape[-3:])
|
|
501
|
+
# samplesperpixel = shape[-1]
|
|
502
|
+
# else:
|
|
503
|
+
# if shape[-3] not in (3, 4):
|
|
504
|
+
# raise ValueError("not a planar RGB(A) image")
|
|
505
|
+
# data = data.reshape((-1, ) + shape[-3:] + (1, ))
|
|
506
|
+
# samplesperpixel = shape[-3]
|
|
507
|
+
# if samplesperpixel == 4:
|
|
508
|
+
# extrasamples = 1
|
|
509
|
+
# elif planarconfig and len(shape) > 2:
|
|
510
|
+
# if planarconfig == 'contig':
|
|
511
|
+
# data = data.reshape((-1, 1) + shape[-3:])
|
|
512
|
+
# samplesperpixel = shape[-1]
|
|
513
|
+
# else:
|
|
514
|
+
# data = data.reshape((-1, ) + shape[-3:] + (1, ))
|
|
515
|
+
# samplesperpixel = shape[-3]
|
|
516
|
+
# extrasamples = samplesperpixel - 1
|
|
517
|
+
# else:
|
|
518
|
+
# planarconfig = None
|
|
519
|
+
# data = data.reshape((-1, 1) + shape[-2:] + (1, ))
|
|
520
|
+
|
|
521
|
+
shape = data.shape # (pages, planes, height, width, contig samples)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
bytestr = bytes if sys.version[0] == '2' else lambda x: bytes(x, 'ascii')
|
|
525
|
+
tifftypes = {'B': 1, 's': 2, 'H': 3, 'I': 4, '2I': 5, 'b': 6,
|
|
526
|
+
'h': 8, 'i': 9, 'f': 11, 'd': 12, 'Q': 16, 'q': 17}
|
|
527
|
+
tifftags = {'new_subfile_type': 254, 'subfile_type': 255,
|
|
528
|
+
'image_width': 256, 'image_length': 257, 'bits_per_sample': 258,
|
|
529
|
+
'compression': 259, 'photometric': 262, 'fill_order': 266,
|
|
530
|
+
'document_name': 269, 'image_description': 270, 'strip_offsets': 273,
|
|
531
|
+
'orientation': 274, 'samples_per_pixel': 277, 'rows_per_strip': 278,
|
|
532
|
+
'strip_byte_counts': 279, 'x_resolution': 282, 'y_resolution': 283,
|
|
533
|
+
'planar_configuration': 284, 'page_name': 285, 'resolution_unit': 296,
|
|
534
|
+
'software': 305, 'datetime': 306, 'predictor': 317, 'color_map': 320,
|
|
535
|
+
'extra_samples': 338, 'sample_format': 339}
|
|
536
|
+
|
|
537
|
+
tags = []
|
|
538
|
+
tag_data = []
|
|
539
|
+
|
|
540
|
+
def pack(fmt, *val):
|
|
541
|
+
return struct.pack(byteorder+fmt, *val)
|
|
542
|
+
|
|
543
|
+
def tag(name, dtype, number, value, offset=[0]):
|
|
544
|
+
# append tag binary string to tags list
|
|
545
|
+
# append (offset, value as binary string) to tag_data list
|
|
546
|
+
# increment offset by tag_size
|
|
547
|
+
if dtype == 's':
|
|
548
|
+
value = bytestr(value) + b'\0'
|
|
549
|
+
number = len(value)
|
|
550
|
+
value = (value, )
|
|
551
|
+
t = [pack('HH', tifftags[name], tifftypes[dtype]),
|
|
552
|
+
pack(offset_format, number)]
|
|
553
|
+
if len(dtype) > 1:
|
|
554
|
+
number *= int(dtype[:-1])
|
|
555
|
+
dtype = dtype[-1]
|
|
556
|
+
if number == 1:
|
|
557
|
+
if isinstance(value, (tuple, list)):
|
|
558
|
+
value = value[0]
|
|
559
|
+
t.append(pack(val_format, pack(dtype, value)))
|
|
560
|
+
elif struct.calcsize(dtype) * number <= offset_size:
|
|
561
|
+
t.append(pack(val_format, pack(str(number)+dtype, *value)))
|
|
562
|
+
else:
|
|
563
|
+
t.append(pack(offset_format, 0))
|
|
564
|
+
tag_data.append((offset[0] + offset_size + 4,
|
|
565
|
+
pack(str(number)+dtype, *value)))
|
|
566
|
+
tags.append(b''.join(t))
|
|
567
|
+
offset[0] += tag_size
|
|
568
|
+
|
|
569
|
+
if software:
|
|
570
|
+
tag('software', 's', 0, software)
|
|
571
|
+
if description:
|
|
572
|
+
tag('image_description', 's', 0, description)
|
|
573
|
+
elif shape != data_shape:
|
|
574
|
+
tag('image_description', 's', 0,
|
|
575
|
+
"shape=(%s)" % (",".join('%i' % i for i in data_shape)))
|
|
576
|
+
tag('datetime', 's', 0,
|
|
577
|
+
datetime.datetime.now().strftime("%Y:%m:%d %H:%M:%S"))
|
|
578
|
+
# write previous tags only once
|
|
579
|
+
writeonce = (len(tags), len(tag_data)) if num_planes > 1 else None
|
|
580
|
+
tag('compression', 'H', 1, 1)
|
|
581
|
+
tag('orientation', 'H', 1, 1)
|
|
582
|
+
tag('image_width', 'I', 1, shape[1])
|
|
583
|
+
tag('image_length', 'I', 1, shape[0])
|
|
584
|
+
tag('new_subfile_type', 'I', 1, 0 if num_planes == 1 else 2)
|
|
585
|
+
tag('sample_format', 'H', 1,
|
|
586
|
+
{'u': 1, 'i': 2, 'f': 3, 'c': 6}[data_type.kind])
|
|
587
|
+
tag('photometric', 'H', 1,
|
|
588
|
+
{'miniswhite': 0, 'minisblack': 1, 'rgb': 2}[photometric])
|
|
589
|
+
tag('samples_per_pixel', 'H', 1, samplesperpixel)
|
|
590
|
+
|
|
591
|
+
# if False:#planarconfig:
|
|
592
|
+
# tag('planar_configuration', 'H', 1, 1 if planarconfig=='contig' else 2)
|
|
593
|
+
# tag('bits_per_sample', 'H', samplesperpixel,
|
|
594
|
+
# (data.dtype.itemsize * 8, ) * samplesperpixel)
|
|
595
|
+
# else:
|
|
596
|
+
tag('bits_per_sample', 'H', 1, data_type.itemsize * 8)
|
|
597
|
+
|
|
598
|
+
# if extrasamples:
|
|
599
|
+
# if photometric == 'rgb':
|
|
600
|
+
# tag('extra_samples', 'H', 1, 1) # alpha channel
|
|
601
|
+
# else:
|
|
602
|
+
# tag('extra_samples', 'H', extrasamples, (0, ) * extrasamples)
|
|
603
|
+
|
|
604
|
+
if resolution:
|
|
605
|
+
tag('x_resolution', '2I', 1, resolution[0])
|
|
606
|
+
tag('y_resolution', '2I', 1, resolution[1])
|
|
607
|
+
tag('resolution_unit', 'H', 1, 2)
|
|
608
|
+
tag('rows_per_strip', 'I', 1, shape[0])
|
|
609
|
+
# use one strip per plane
|
|
610
|
+
strip_byte_counts = (frame0.size * data_type.itemsize, )
|
|
611
|
+
tag('strip_byte_counts', offset_format, len(strip_byte_counts), strip_byte_counts)
|
|
612
|
+
# strip_offsets must be the last tag; will be updated later
|
|
613
|
+
tag('strip_offsets', offset_format, len(strip_byte_counts), (0, ) * len(strip_byte_counts))
|
|
614
|
+
|
|
615
|
+
fd = open(filename, 'wb')
|
|
616
|
+
seek = fd.seek
|
|
617
|
+
tell = fd.tell
|
|
618
|
+
|
|
619
|
+
def write(arg, *args):
|
|
620
|
+
fd.write(pack(arg, *args) if args else arg)
|
|
621
|
+
|
|
622
|
+
write({'<': b'II', '>': b'MM'}[byteorder])
|
|
623
|
+
if bigtiff:
|
|
624
|
+
write('HHH', 43, 8, 0)
|
|
625
|
+
else:
|
|
626
|
+
write('H', 42)
|
|
627
|
+
ifd_offset = tell()
|
|
628
|
+
write(offset_format, 0) # first IFD
|
|
629
|
+
|
|
630
|
+
for k in range(shape[4]):
|
|
631
|
+
for j in range(shape[3]):
|
|
632
|
+
for i in range(shape[2]):
|
|
633
|
+
# update pointer at ifd_offset
|
|
634
|
+
pos = tell()
|
|
635
|
+
seek(ifd_offset)
|
|
636
|
+
write(offset_format, pos)
|
|
637
|
+
seek(pos)
|
|
638
|
+
# write tags
|
|
639
|
+
write(numtag_format, len(tags))
|
|
640
|
+
tag_offset = tell()
|
|
641
|
+
write(b''.join(tags))
|
|
642
|
+
ifd_offset = tell()
|
|
643
|
+
write(offset_format, 0) # offset to next ifd
|
|
644
|
+
# write extra tag data and update pointers
|
|
645
|
+
for off, dat in tag_data:
|
|
646
|
+
pos = tell()
|
|
647
|
+
seek(tag_offset + off)
|
|
648
|
+
write(offset_format, pos)
|
|
649
|
+
seek(pos)
|
|
650
|
+
write(dat)
|
|
651
|
+
# update strip_offsets
|
|
652
|
+
pos = tell()
|
|
653
|
+
if len(strip_byte_counts) == 1:
|
|
654
|
+
seek(ifd_offset - offset_size)
|
|
655
|
+
write(offset_format, pos)
|
|
656
|
+
else:
|
|
657
|
+
seek(pos - offset_size*shape[1])
|
|
658
|
+
strip_offset = pos
|
|
659
|
+
for size in strip_byte_counts:
|
|
660
|
+
write(offset_format, strip_offset)
|
|
661
|
+
strip_offset += size
|
|
662
|
+
seek(pos)
|
|
663
|
+
# write data
|
|
664
|
+
data[:,:,i,j,k].astype(data_type).tofile(fd) # if this fails, try update Python and numpy
|
|
665
|
+
fd.flush()
|
|
666
|
+
# remove tags that should be written only once
|
|
667
|
+
if writeonce:
|
|
668
|
+
tags = tags[writeonce[0]:]
|
|
669
|
+
d = writeonce[0] * tag_size
|
|
670
|
+
tag_data = [(o-d, v) for (o, v) in tag_data[writeonce[1]:]]
|
|
671
|
+
writeonce = None
|
|
672
|
+
fd.close()
|
|
673
|
+
|
|
674
|
+
def imread(filename, *args, **kwargs):
|
|
675
|
+
"""Return image data from TIFF file as numpy array.
|
|
676
|
+
|
|
677
|
+
The first image series is returned if no arguments are provided.
|
|
678
|
+
|
|
679
|
+
Arguments
|
|
680
|
+
---------
|
|
681
|
+
|
|
682
|
+
key : int, slice, or sequence of page indices
|
|
683
|
+
Defines which pages to return as array.
|
|
684
|
+
|
|
685
|
+
series : int
|
|
686
|
+
Defines which series of pages to return as array.
|
|
687
|
+
|
|
688
|
+
Example
|
|
689
|
+
-------
|
|
690
|
+
|
|
691
|
+
>>> image = imread('test.tif', 0)
|
|
692
|
+
|
|
693
|
+
"""
|
|
694
|
+
with TIFFfile(filename) as tif:
|
|
695
|
+
return tif.asarray(*args, **kwargs)
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
class lazyattr(object):
|
|
699
|
+
"""Lazy object attribute whose value is computed on first access."""
|
|
700
|
+
def __init__(self, func):
|
|
701
|
+
self.func = func
|
|
702
|
+
|
|
703
|
+
def __get__(self, instance, owner):
|
|
704
|
+
if instance is None:
|
|
705
|
+
return self
|
|
706
|
+
result = self.func(instance)
|
|
707
|
+
if result is NotImplemented:
|
|
708
|
+
return getattr(super(owner, instance), self.func.__name__)
|
|
709
|
+
setattr(instance, self.func.__name__, result)
|
|
710
|
+
return result
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
class TIFFfile(object):
|
|
714
|
+
"""Read image and meta-data from TIFF, STK, LSM, and FluoView files.
|
|
715
|
+
|
|
716
|
+
TIFFfile instances must be closed using the close method.
|
|
717
|
+
|
|
718
|
+
Attributes
|
|
719
|
+
----------
|
|
720
|
+
|
|
721
|
+
pages : list
|
|
722
|
+
All TIFFpages in file.
|
|
723
|
+
|
|
724
|
+
series : list of Records(shape, dtype, axes, TIFFpages)
|
|
725
|
+
TIFF pages with compatible shapes and types.
|
|
726
|
+
|
|
727
|
+
All attributes are read-only.
|
|
728
|
+
|
|
729
|
+
Example
|
|
730
|
+
-------
|
|
731
|
+
|
|
732
|
+
>>> tif = TIFFfile('test.tif')
|
|
733
|
+
... try:
|
|
734
|
+
... images = tif.asarray()
|
|
735
|
+
... except Exception as e:
|
|
736
|
+
... print(e)
|
|
737
|
+
... finally:
|
|
738
|
+
... tif.close()
|
|
739
|
+
|
|
740
|
+
"""
|
|
741
|
+
def __init__(self, filename):
|
|
742
|
+
"""Initialize instance from file."""
|
|
743
|
+
from PYME.IO import unifiedIO
|
|
744
|
+
#filename = unifiedIO.local_or_temp_filename(filename)
|
|
745
|
+
#filename = os.path.abspath(filename)
|
|
746
|
+
#self._fd = open(filename, 'rb')
|
|
747
|
+
self._fd = unifiedIO.openFile(filename)
|
|
748
|
+
self.fname = os.path.basename(filename)
|
|
749
|
+
self.fpath = os.path.dirname(filename)
|
|
750
|
+
self._tiffs = {self.fname: self} # cache of TIFFfiles
|
|
751
|
+
self.offset_size = None
|
|
752
|
+
self.pages = []
|
|
753
|
+
try:
|
|
754
|
+
self._fromfile()
|
|
755
|
+
except Exception:
|
|
756
|
+
self._fd.close()
|
|
757
|
+
raise
|
|
758
|
+
|
|
759
|
+
def close(self):
|
|
760
|
+
"""Close open file handle(s)."""
|
|
761
|
+
if not hasattr(self, 'tiffs'):
|
|
762
|
+
return
|
|
763
|
+
for tif in self._tiffs.values():
|
|
764
|
+
if tif._fd:
|
|
765
|
+
tif._fd.close()
|
|
766
|
+
tif._fd = None
|
|
767
|
+
|
|
768
|
+
def _fromfile(self):
|
|
769
|
+
"""Read TIFF header and all page records from file."""
|
|
770
|
+
self._fd.seek(0)
|
|
771
|
+
try:
|
|
772
|
+
self.byte_order = {b'II': '<', b'MM': '>'}[self._fd.read(2)]
|
|
773
|
+
except KeyError:
|
|
774
|
+
raise ValueError("not a valid TIFF file")
|
|
775
|
+
version = struct.unpack(self.byte_order+'H', self._fd.read(2))[0]
|
|
776
|
+
if version == 43: # BigTiff
|
|
777
|
+
self.offset_size, zero = struct.unpack(self.byte_order+'HH',
|
|
778
|
+
self._fd.read(4))
|
|
779
|
+
if zero or self.offset_size != 8:
|
|
780
|
+
raise ValueError("not a valid BigTIFF file")
|
|
781
|
+
elif version == 42:
|
|
782
|
+
self.offset_size = 4
|
|
783
|
+
else:
|
|
784
|
+
raise ValueError("not a TIFF file")
|
|
785
|
+
self.pages = []
|
|
786
|
+
while True:
|
|
787
|
+
try:
|
|
788
|
+
page = TIFFpage(self)
|
|
789
|
+
self.pages.append(page)
|
|
790
|
+
except StopIteration:
|
|
791
|
+
break
|
|
792
|
+
if not self.pages:
|
|
793
|
+
raise ValueError("empty TIFF file")
|
|
794
|
+
|
|
795
|
+
@lazyattr
|
|
796
|
+
def series(self):
|
|
797
|
+
"""Return series of TIFFpage with compatible shape and properties."""
|
|
798
|
+
if self.is_ome:
|
|
799
|
+
series = self._omeseries()
|
|
800
|
+
elif self.is_fluoview:
|
|
801
|
+
dims = {b'X': 'X', b'Y': 'Y', b'Z': 'Z', b'T': 'T',
|
|
802
|
+
b'WAVELENGTH': 'C', b'TIME': 'T', b'XY': 'R',
|
|
803
|
+
b'EVENT': 'V', b'EXPOSURE': 'L'}
|
|
804
|
+
mmhd = list(reversed(self.pages[0].mm_header.dimensions))
|
|
805
|
+
series = [Record(
|
|
806
|
+
axes=''.join(dims.get(i[0].strip().upper(), 'O')
|
|
807
|
+
for i in mmhd if i[1] > 1),
|
|
808
|
+
shape=tuple(int(i[1]) for i in mmhd if i[1] > 1),
|
|
809
|
+
pages=self.pages, dtype=numpy.dtype(self.pages[0].dtype))]
|
|
810
|
+
elif self.is_lsm:
|
|
811
|
+
lsmi = self.pages[0].cz_lsm_info
|
|
812
|
+
axes = CZ_SCAN_TYPES[lsmi.scan_type]
|
|
813
|
+
if self.pages[0].is_rgb:
|
|
814
|
+
axes = axes.replace('C', '').replace('XY', 'XYC')
|
|
815
|
+
axes = axes[::-1]
|
|
816
|
+
shape = [getattr(lsmi, CZ_DIMENSIONS[i]) for i in axes]
|
|
817
|
+
pages = [p for p in self.pages if not p.is_reduced]
|
|
818
|
+
series = [Record(axes=axes, shape=shape, pages=pages,
|
|
819
|
+
dtype=numpy.dtype(pages[0].dtype))]
|
|
820
|
+
if len(pages) != len(self.pages): # reduced RGB pages
|
|
821
|
+
pages = [p for p in self.pages if p.is_reduced]
|
|
822
|
+
cp = 1
|
|
823
|
+
i = 0
|
|
824
|
+
while cp < len(pages) and i < len(shape)-2:
|
|
825
|
+
cp *= shape[i]
|
|
826
|
+
i += 1
|
|
827
|
+
shape = shape[:i] + list(pages[0].shape)
|
|
828
|
+
axes = axes[:i] + 'CYX'
|
|
829
|
+
series.append(Record(axes=axes, shape=shape, pages=pages,
|
|
830
|
+
dtype=numpy.dtype(pages[0].dtype)))
|
|
831
|
+
elif self.is_nih:
|
|
832
|
+
series = [Record(pages=self.pages,
|
|
833
|
+
shape=(len(self.pages),) + self.pages[0].shape,
|
|
834
|
+
axes='I' + self.pages[0].axes,
|
|
835
|
+
dtype=numpy.dtype(self.pages[0].dtype))]
|
|
836
|
+
elif self.pages[0].is_shaped:
|
|
837
|
+
shape = self.pages[0].tags['image_description'].value[7:-1]
|
|
838
|
+
shape = tuple(int(i) for i in shape.split(b','))
|
|
839
|
+
series = [Record(pages=self.pages, shape=shape,
|
|
840
|
+
axes='O' * len(shape),
|
|
841
|
+
dtype=numpy.dtype(self.pages[0].dtype))]
|
|
842
|
+
else:
|
|
843
|
+
shapes = []
|
|
844
|
+
pages = {}
|
|
845
|
+
for page in self.pages:
|
|
846
|
+
shape = page.shape + (page.axes,
|
|
847
|
+
page.compression in TIFF_DECOMPESSORS)
|
|
848
|
+
if not shape in pages:
|
|
849
|
+
shapes.append(shape)
|
|
850
|
+
pages[shape] = [page]
|
|
851
|
+
else:
|
|
852
|
+
pages[shape].append(page)
|
|
853
|
+
series = [Record(pages=pages[s],
|
|
854
|
+
axes=(('I' + s[-2])
|
|
855
|
+
if len(pages[s]) > 1 else s[-2]),
|
|
856
|
+
dtype=numpy.dtype(pages[s][0].dtype),
|
|
857
|
+
shape=((len(pages[s]), ) + s[:-2]
|
|
858
|
+
if len(pages[s]) > 1 else s[:-2]))
|
|
859
|
+
for s in shapes]
|
|
860
|
+
return series
|
|
861
|
+
|
|
862
|
+
def asarray(self, key=None, series=None):
|
|
863
|
+
"""Return image data of multiple TIFF pages as numpy array.
|
|
864
|
+
|
|
865
|
+
By default the first image series is returned.
|
|
866
|
+
|
|
867
|
+
Arguments
|
|
868
|
+
---------
|
|
869
|
+
|
|
870
|
+
key : int, slice, or sequence of page indices
|
|
871
|
+
Defines which pages to return as array.
|
|
872
|
+
|
|
873
|
+
series : int
|
|
874
|
+
Defines which series of pages to return as array.
|
|
875
|
+
|
|
876
|
+
"""
|
|
877
|
+
if key is None and series is None:
|
|
878
|
+
series = 0
|
|
879
|
+
if series is not None:
|
|
880
|
+
pages = self.series[series].pages
|
|
881
|
+
else:
|
|
882
|
+
pages = self.pages
|
|
883
|
+
|
|
884
|
+
if key is None:
|
|
885
|
+
pass
|
|
886
|
+
elif isinstance(key, int):
|
|
887
|
+
pages = [pages[key]]
|
|
888
|
+
elif isinstance(key, slice):
|
|
889
|
+
pages = pages[key]
|
|
890
|
+
elif isinstance(key, collections.Iterable):
|
|
891
|
+
pages = [pages[k] for k in key]
|
|
892
|
+
else:
|
|
893
|
+
raise TypeError('key must be an int, slice, or sequence')
|
|
894
|
+
|
|
895
|
+
if len(pages) == 1:
|
|
896
|
+
return pages[0].asarray()
|
|
897
|
+
elif self.is_nih:
|
|
898
|
+
result = numpy.vstack(p.asarray(colormapped=False,
|
|
899
|
+
squeeze=False) for p in pages)
|
|
900
|
+
if pages[0].is_palette:
|
|
901
|
+
result = numpy.take(pages[0].color_map, result, axis=1)
|
|
902
|
+
result = numpy.swapaxes(result, 0, 1)
|
|
903
|
+
else:
|
|
904
|
+
if self.is_ome and any(p is None for p in pages):
|
|
905
|
+
firstpage = next(p for p in pages if p)
|
|
906
|
+
nopage = numpy.zeros_like(
|
|
907
|
+
firstpage.asarray())
|
|
908
|
+
result = numpy.vstack((p.asarray() if p else nopage)
|
|
909
|
+
for p in pages)
|
|
910
|
+
if key is None:
|
|
911
|
+
try:
|
|
912
|
+
result.shape = self.series[series].shape
|
|
913
|
+
except ValueError:
|
|
914
|
+
warnings.warn("failed to reshape %s to %s" % (
|
|
915
|
+
result.shape, self.series[series].shape))
|
|
916
|
+
result.shape = (-1,) + pages[0].shape
|
|
917
|
+
else:
|
|
918
|
+
result.shape = (-1,) + pages[0].shape
|
|
919
|
+
return result
|
|
920
|
+
|
|
921
|
+
def _omeseries(self):
|
|
922
|
+
"""Return image series in OME-TIFF files."""
|
|
923
|
+
root = ElementTree.XML(self.pages[0].tags['image_description'].value)
|
|
924
|
+
uuid = root.attrib.get('UUID', None)
|
|
925
|
+
self._tiffs = {uuid: self}
|
|
926
|
+
modulo = {}
|
|
927
|
+
result = []
|
|
928
|
+
for element in root:
|
|
929
|
+
if element.tag.endswith('BinaryOnly'):
|
|
930
|
+
warnings.warn("not an OME-TIFF master file")
|
|
931
|
+
break
|
|
932
|
+
if element.tag.endswith('StructuredAnnotations'):
|
|
933
|
+
for annot in element:
|
|
934
|
+
if not annot.attrib.get('Namespace',
|
|
935
|
+
'').endswith('modulo'):
|
|
936
|
+
continue
|
|
937
|
+
for value in annot:
|
|
938
|
+
for modul in value:
|
|
939
|
+
for along in modul:
|
|
940
|
+
if not along.tag[:-1].endswith('Along'):
|
|
941
|
+
continue
|
|
942
|
+
axis = along.tag[-1]
|
|
943
|
+
newaxis = along.attrib.get('Type', 'other')
|
|
944
|
+
newaxis = AXES_LABELS[newaxis]
|
|
945
|
+
if 'Start' in along.attrib:
|
|
946
|
+
labels = range(
|
|
947
|
+
int(along.attrib['Start']),
|
|
948
|
+
int(along.attrib['End']) + 1,
|
|
949
|
+
int(along.attrib.get('Step', 1)))
|
|
950
|
+
else:
|
|
951
|
+
labels = [label.text for label in along
|
|
952
|
+
if label.tag.endswith('Label')]
|
|
953
|
+
modulo[axis] = (newaxis, labels)
|
|
954
|
+
if not element.tag.endswith('Image'):
|
|
955
|
+
continue
|
|
956
|
+
for pixels in element:
|
|
957
|
+
if not pixels.tag.endswith('Pixels'):
|
|
958
|
+
continue
|
|
959
|
+
atr = pixels.attrib
|
|
960
|
+
axes = "".join(reversed(atr['DimensionOrder']))
|
|
961
|
+
shape = list(int(atr['Size'+ax]) for ax in axes)
|
|
962
|
+
size = numpy.prod(shape[:-2])
|
|
963
|
+
ifds = [None] * size
|
|
964
|
+
for data in pixels:
|
|
965
|
+
if not data.tag.endswith('TiffData'):
|
|
966
|
+
continue
|
|
967
|
+
atr = data.attrib
|
|
968
|
+
ifd = int(atr.get('IFD', 0))
|
|
969
|
+
num = int(atr.get('NumPlanes', 1 if 'IFD' in atr else 0))
|
|
970
|
+
num = int(atr.get('PlaneCount', num))
|
|
971
|
+
idx = [int(atr.get('First'+ax, 0)) for ax in axes[:-2]]
|
|
972
|
+
idx = numpy.ravel_multi_index(idx, shape[:-2])
|
|
973
|
+
for uuid in data:
|
|
974
|
+
if uuid.tag.endswith('UUID'):
|
|
975
|
+
if uuid.text not in self._tiffs:
|
|
976
|
+
fn = uuid.attrib['FileName']
|
|
977
|
+
try:
|
|
978
|
+
tf = TIFFfile(os.path.join(self.fpath, fn))
|
|
979
|
+
except (IOError, ValueError):
|
|
980
|
+
warnings.warn("failed to read %s" % fn)
|
|
981
|
+
break
|
|
982
|
+
self._tiffs[uuid.text] = tf
|
|
983
|
+
pages = self._tiffs[uuid.text].pages
|
|
984
|
+
try:
|
|
985
|
+
for i in range(num if num else len(pages)):
|
|
986
|
+
ifds[idx + i] = pages[ifd + i]
|
|
987
|
+
except IndexError:
|
|
988
|
+
warnings.warn("ome-xml: index out of range")
|
|
989
|
+
break
|
|
990
|
+
else:
|
|
991
|
+
pages = self.pages
|
|
992
|
+
try:
|
|
993
|
+
for i in range(num if num else len(pages)):
|
|
994
|
+
ifds[idx + i] = pages[ifd + i]
|
|
995
|
+
except IndexError:
|
|
996
|
+
warnings.warn("ome-xml: index out of range")
|
|
997
|
+
result.append(Record(axes=axes, shape=shape, pages=ifds,
|
|
998
|
+
dtype=numpy.dtype(ifds[0].dtype)))
|
|
999
|
+
|
|
1000
|
+
for record in result:
|
|
1001
|
+
for axis, (newaxis, labels) in modulo.items():
|
|
1002
|
+
i = record.axes.index(axis)
|
|
1003
|
+
size = len(labels)
|
|
1004
|
+
if record.shape[i] == size:
|
|
1005
|
+
record.axes = record.axes.replace(axis, newaxis, 1)
|
|
1006
|
+
else:
|
|
1007
|
+
record.shape[i] //= size
|
|
1008
|
+
record.shape.insert(i+1, size)
|
|
1009
|
+
record.axes = record.axes.replace(axis, axis+newaxis, 1)
|
|
1010
|
+
|
|
1011
|
+
return result
|
|
1012
|
+
|
|
1013
|
+
def __len__(self):
|
|
1014
|
+
"""Return number of image pages in file."""
|
|
1015
|
+
return len(self.pages)
|
|
1016
|
+
|
|
1017
|
+
def __getitem__(self, key):
|
|
1018
|
+
"""Return specified page."""
|
|
1019
|
+
return self.pages[key]
|
|
1020
|
+
|
|
1021
|
+
def __iter__(self):
|
|
1022
|
+
"""Return iterator over pages."""
|
|
1023
|
+
return iter(self.pages)
|
|
1024
|
+
|
|
1025
|
+
def __str__(self):
|
|
1026
|
+
"""Return string containing information about file."""
|
|
1027
|
+
result = [self.fname.capitalize(),
|
|
1028
|
+
"%.2f MB" % (self.fstat[6] / 1048576),
|
|
1029
|
+
{'<': 'little endian', '>': 'big endian'}[self.byte_order]]
|
|
1030
|
+
if self.is_bigtiff:
|
|
1031
|
+
result.append("bigtiff")
|
|
1032
|
+
if len(self.pages) > 1:
|
|
1033
|
+
result.append("%i pages" % len(self.pages))
|
|
1034
|
+
if len(self.series) > 1:
|
|
1035
|
+
result.append("%i series" % len(self.series))
|
|
1036
|
+
if len(self._tiffs) > 1:
|
|
1037
|
+
result.append("%i files" % (len(self._tiffs)))
|
|
1038
|
+
return ", ".join(result)
|
|
1039
|
+
|
|
1040
|
+
def __enter__(self):
|
|
1041
|
+
return self
|
|
1042
|
+
|
|
1043
|
+
def __exit__(self, *args):
|
|
1044
|
+
self.close()
|
|
1045
|
+
|
|
1046
|
+
@lazyattr
|
|
1047
|
+
def fstat(self):
|
|
1048
|
+
return os.fstat(self._fd.fileno())
|
|
1049
|
+
|
|
1050
|
+
@lazyattr
|
|
1051
|
+
def is_bigtiff(self):
|
|
1052
|
+
return self.offset_size != 4
|
|
1053
|
+
|
|
1054
|
+
@lazyattr
|
|
1055
|
+
def is_rgb(self):
|
|
1056
|
+
return all(p.is_rgb for p in self.pages)
|
|
1057
|
+
|
|
1058
|
+
@lazyattr
|
|
1059
|
+
def is_palette(self):
|
|
1060
|
+
return all(p.is_palette for p in self.pages)
|
|
1061
|
+
|
|
1062
|
+
@lazyattr
|
|
1063
|
+
def is_stk(self):
|
|
1064
|
+
return all(p.is_stk for p in self.pages)
|
|
1065
|
+
|
|
1066
|
+
@lazyattr
|
|
1067
|
+
def is_lsm(self):
|
|
1068
|
+
return self.pages[0].is_lsm
|
|
1069
|
+
|
|
1070
|
+
@lazyattr
|
|
1071
|
+
def is_nih(self):
|
|
1072
|
+
return self.pages[0].is_nih
|
|
1073
|
+
|
|
1074
|
+
@lazyattr
|
|
1075
|
+
def is_fluoview(self):
|
|
1076
|
+
return self.pages[0].is_fluoview
|
|
1077
|
+
|
|
1078
|
+
@lazyattr
|
|
1079
|
+
def is_ome(self):
|
|
1080
|
+
return self.pages[0].is_ome
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
class TIFFpage(object):
|
|
1084
|
+
"""A TIFF image file directory (IFD).
|
|
1085
|
+
|
|
1086
|
+
Attributes
|
|
1087
|
+
----------
|
|
1088
|
+
|
|
1089
|
+
index : int
|
|
1090
|
+
Index of page in file.
|
|
1091
|
+
|
|
1092
|
+
dtype : str {TIFF_SAMPLE_DTYPES}
|
|
1093
|
+
Data type of image, colormapped if applicable.
|
|
1094
|
+
|
|
1095
|
+
shape : tuple
|
|
1096
|
+
Dimensions of the image array in TIFF page,
|
|
1097
|
+
colormapped and with one alpha channel if applicable.
|
|
1098
|
+
|
|
1099
|
+
axes : str
|
|
1100
|
+
Axes label codes:
|
|
1101
|
+
'X' width, 'Y' height, 'S' sample, 'P' plane, 'I' image series,
|
|
1102
|
+
'Z' depth, 'C' color|em-wavelength|channel, 'E' ex-wavelength|lambda,
|
|
1103
|
+
'T' time, 'R' region|tile, 'A' angle, 'F' phase, 'H' lifetime,
|
|
1104
|
+
'L' exposure, 'V' event, 'O' unknown, '_' missing
|
|
1105
|
+
|
|
1106
|
+
tags : TiffTags
|
|
1107
|
+
Dictionary of tags in page.
|
|
1108
|
+
Tag values are also directly accessible as attributes.
|
|
1109
|
+
|
|
1110
|
+
color_map : numpy array
|
|
1111
|
+
Color look up table if exists.
|
|
1112
|
+
|
|
1113
|
+
mm_uic_tags: Record(dict)
|
|
1114
|
+
Consolidated MetaMorph mm_uic# tags, if exists.
|
|
1115
|
+
|
|
1116
|
+
cz_lsm_scan_info: Record(dict)
|
|
1117
|
+
LSM scan info attributes, if exists.
|
|
1118
|
+
|
|
1119
|
+
All attributes are read-only.
|
|
1120
|
+
|
|
1121
|
+
"""
|
|
1122
|
+
def __init__(self, parent):
|
|
1123
|
+
"""Initialize instance from file."""
|
|
1124
|
+
self.parent = parent
|
|
1125
|
+
self.index = len(parent.pages)
|
|
1126
|
+
self.shape = self._shape = ()
|
|
1127
|
+
self.dtype = self._dtype = None
|
|
1128
|
+
self.axes = ""
|
|
1129
|
+
self.tags = TiffTags()
|
|
1130
|
+
|
|
1131
|
+
self._fromfile()
|
|
1132
|
+
self._process_tags()
|
|
1133
|
+
|
|
1134
|
+
def _fromfile(self):
|
|
1135
|
+
"""Read TIFF IFD structure and its tags from file.
|
|
1136
|
+
|
|
1137
|
+
File cursor must be at storage position of IFD offset and is left at
|
|
1138
|
+
offset to next IFD.
|
|
1139
|
+
|
|
1140
|
+
Raises StopIteration if offset (first bytes read) is 0.
|
|
1141
|
+
|
|
1142
|
+
"""
|
|
1143
|
+
fd = self.parent._fd
|
|
1144
|
+
byte_order = self.parent.byte_order
|
|
1145
|
+
offset_size = self.parent.offset_size
|
|
1146
|
+
|
|
1147
|
+
fmt = {4: 'I', 8: 'Q'}[offset_size]
|
|
1148
|
+
offset = struct.unpack(byte_order + fmt, fd.read(offset_size))[0]
|
|
1149
|
+
if not offset:
|
|
1150
|
+
raise StopIteration()
|
|
1151
|
+
|
|
1152
|
+
# read standard tags
|
|
1153
|
+
tags = self.tags
|
|
1154
|
+
fd.seek(offset, 0)
|
|
1155
|
+
fmt, size = {4: ('H', 2), 8: ('Q', 8)}[offset_size]
|
|
1156
|
+
try:
|
|
1157
|
+
numtags = struct.unpack(byte_order + fmt, fd.read(size))[0]
|
|
1158
|
+
except Exception:
|
|
1159
|
+
warnings.warn("corrupted page list")
|
|
1160
|
+
raise StopIteration()
|
|
1161
|
+
|
|
1162
|
+
for _ in range(numtags):
|
|
1163
|
+
tag = TIFFtag(self.parent)
|
|
1164
|
+
tags[tag.name] = tag
|
|
1165
|
+
|
|
1166
|
+
# read custom tags
|
|
1167
|
+
for name, readtag in CUSTOM_TAGS.values():
|
|
1168
|
+
if name in tags and readtag:
|
|
1169
|
+
pos = fd.tell()
|
|
1170
|
+
value = readtag(fd, byte_order, tags[name])
|
|
1171
|
+
if isinstance(value, dict): # numpy.core.records.record
|
|
1172
|
+
value = Record(value)
|
|
1173
|
+
tags[name].value = value
|
|
1174
|
+
fd.seek(pos)
|
|
1175
|
+
|
|
1176
|
+
# read LSM info subrecords
|
|
1177
|
+
if self.is_lsm:
|
|
1178
|
+
pos = fd.tell()
|
|
1179
|
+
for name, reader in CZ_LSM_INFO_READERS.items():
|
|
1180
|
+
try:
|
|
1181
|
+
offset = self.cz_lsm_info["offset_"+name]
|
|
1182
|
+
except KeyError:
|
|
1183
|
+
continue
|
|
1184
|
+
if not offset:
|
|
1185
|
+
continue
|
|
1186
|
+
fd.seek(offset)
|
|
1187
|
+
try:
|
|
1188
|
+
setattr(self, "cz_lsm_"+name, reader(fd, byte_order))
|
|
1189
|
+
except ValueError:
|
|
1190
|
+
pass
|
|
1191
|
+
fd.seek(pos)
|
|
1192
|
+
|
|
1193
|
+
def _process_tags(self):
|
|
1194
|
+
"""Validate standard tags and initialize attributes.
|
|
1195
|
+
|
|
1196
|
+
Raise ValueError if tag values are not supported.
|
|
1197
|
+
|
|
1198
|
+
"""
|
|
1199
|
+
tags = self.tags
|
|
1200
|
+
for code, (name, default, dtype, count, validate) in TIFF_TAGS.items():
|
|
1201
|
+
if not (name in tags or default is None):
|
|
1202
|
+
tags[name] = TIFFtag(code, dtype=dtype, count=count,
|
|
1203
|
+
value=default, name=name)
|
|
1204
|
+
if name in tags and validate:
|
|
1205
|
+
try:
|
|
1206
|
+
if tags[name].count == 1:
|
|
1207
|
+
setattr(self, name, validate[tags[name].value])
|
|
1208
|
+
else:
|
|
1209
|
+
setattr(self, name, tuple(validate[value]
|
|
1210
|
+
for value in tags[name].value))
|
|
1211
|
+
except KeyError:
|
|
1212
|
+
raise ValueError("%s.value (%s) not supported" %
|
|
1213
|
+
(name, tags[name].value))
|
|
1214
|
+
|
|
1215
|
+
tag = tags['bits_per_sample']
|
|
1216
|
+
if tag.count == 1:
|
|
1217
|
+
self.bits_per_sample = tag.value
|
|
1218
|
+
else:
|
|
1219
|
+
value = tag.value[:self.samples_per_pixel]
|
|
1220
|
+
if any((v-value[0] for v in value)):
|
|
1221
|
+
self.bits_per_sample = value
|
|
1222
|
+
else:
|
|
1223
|
+
self.bits_per_sample = value[0]
|
|
1224
|
+
|
|
1225
|
+
tag = tags['sample_format']
|
|
1226
|
+
if tag.count == 1:
|
|
1227
|
+
self.sample_format = TIFF_SAMPLE_FORMATS[tag.value]
|
|
1228
|
+
else:
|
|
1229
|
+
value = tag.value[:self.samples_per_pixel]
|
|
1230
|
+
if any((v-value[0] for v in value)):
|
|
1231
|
+
self.sample_format = [TIFF_SAMPLE_FORMATS[v] for v in value]
|
|
1232
|
+
else:
|
|
1233
|
+
self.sample_format = TIFF_SAMPLE_FORMATS[value[0]]
|
|
1234
|
+
|
|
1235
|
+
self.strips_per_image = int(math.floor(float(self.image_length +
|
|
1236
|
+
self.rows_per_strip - 1) / self.rows_per_strip))
|
|
1237
|
+
|
|
1238
|
+
key = (self.sample_format, self.bits_per_sample)
|
|
1239
|
+
self.dtype = self._dtype = TIFF_SAMPLE_DTYPES.get(key, None)
|
|
1240
|
+
|
|
1241
|
+
if self.is_stk:
|
|
1242
|
+
planes = tags['mm_uic2'].count
|
|
1243
|
+
# consolidate mm_uci tags
|
|
1244
|
+
self.mm_uic_tags = Record(tags['mm_uic2'].value)
|
|
1245
|
+
for key in ('mm_uic3', 'mm_uic4', 'mm_uic1'):
|
|
1246
|
+
if key in tags:
|
|
1247
|
+
self.mm_uic_tags.update(tags[key].value)
|
|
1248
|
+
if self.planar_configuration == 'contig':
|
|
1249
|
+
self._shape = (planes, 1, self.image_length,
|
|
1250
|
+
self.image_width, self.samples_per_pixel)
|
|
1251
|
+
self.shape = tuple(self._shape[i] for i in (0, 2, 3, 4))
|
|
1252
|
+
self.axes = "PYXS"
|
|
1253
|
+
else:
|
|
1254
|
+
self._shape = (planes, self.samples_per_pixel,
|
|
1255
|
+
self.image_length, self.image_width, 1)
|
|
1256
|
+
self.shape = self._shape[:4]
|
|
1257
|
+
self.axes = "PSYX"
|
|
1258
|
+
elif self.is_palette:
|
|
1259
|
+
self.dtype = self.tags['color_map'].dtype[1]
|
|
1260
|
+
self.color_map = numpy.array(self.color_map, self.dtype)
|
|
1261
|
+
dmax = self.color_map.max()
|
|
1262
|
+
if dmax < 256:
|
|
1263
|
+
self.dtype = numpy.uint8
|
|
1264
|
+
self.color_map = self.color_map.astype(self.dtype)
|
|
1265
|
+
#else:
|
|
1266
|
+
# self.dtype = numpy.uint8
|
|
1267
|
+
# self.color_map >>= 8
|
|
1268
|
+
# self.color_map = self.color_map.astype(self.dtype)
|
|
1269
|
+
self.color_map.shape = (3, -1)
|
|
1270
|
+
self._shape = (1, 1, self.image_length, self.image_width, 1)
|
|
1271
|
+
if self.color_map.shape[1] >= 2**self.bits_per_sample:
|
|
1272
|
+
self.shape = (3, self.image_length, self.image_width)
|
|
1273
|
+
self.axes = "SYX"
|
|
1274
|
+
else:
|
|
1275
|
+
# LSM and FluoView
|
|
1276
|
+
self.shape = (self.image_length, self.image_width)
|
|
1277
|
+
self.axes = "YX"
|
|
1278
|
+
elif self.is_rgb or self.samples_per_pixel > 1:
|
|
1279
|
+
if self.planar_configuration == 'contig':
|
|
1280
|
+
self._shape = (1, 1, self.image_length, self.image_width,
|
|
1281
|
+
self.samples_per_pixel)
|
|
1282
|
+
self.shape = (self.image_length, self.image_width,
|
|
1283
|
+
self.samples_per_pixel)
|
|
1284
|
+
self.axes = "YXS"
|
|
1285
|
+
else:
|
|
1286
|
+
self._shape = (1, self.samples_per_pixel, self.image_length,
|
|
1287
|
+
self.image_width, 1)
|
|
1288
|
+
self.shape = self._shape[1:-1]
|
|
1289
|
+
self.axes = "SYX"
|
|
1290
|
+
if self.is_rgb and 'extra_samples' in self.tags:
|
|
1291
|
+
extra_samples = self.extra_samples
|
|
1292
|
+
if self.tags['extra_samples'].count == 1:
|
|
1293
|
+
extra_samples = (extra_samples, )
|
|
1294
|
+
for exs in extra_samples:
|
|
1295
|
+
if exs in ('unassalpha', 'assocalpha'):
|
|
1296
|
+
if self.planar_configuration == 'contig':
|
|
1297
|
+
self.shape = self.shape[:2] + (4,)
|
|
1298
|
+
else:
|
|
1299
|
+
self.shape = (4,) + self.shape[1:]
|
|
1300
|
+
break
|
|
1301
|
+
else:
|
|
1302
|
+
self._shape = (1, 1, self.image_length, self.image_width, 1)
|
|
1303
|
+
self.shape = self._shape[2:4]
|
|
1304
|
+
self.axes = "YX"
|
|
1305
|
+
|
|
1306
|
+
if not self.compression and not 'strip_byte_counts' in tags:
|
|
1307
|
+
self.strip_byte_counts = numpy.prod(self.shape) * (
|
|
1308
|
+
self.bits_per_sample // 8)
|
|
1309
|
+
|
|
1310
|
+
def asarray(self, squeeze=True, colormapped=True, rgbonly=True):
|
|
1311
|
+
"""Read image data from file and return as numpy array.
|
|
1312
|
+
|
|
1313
|
+
Raise ValueError if format is unsupported.
|
|
1314
|
+
If any argument is False, the shape of the returned array might be
|
|
1315
|
+
different from the page shape.
|
|
1316
|
+
|
|
1317
|
+
Arguments
|
|
1318
|
+
---------
|
|
1319
|
+
|
|
1320
|
+
squeeze : bool
|
|
1321
|
+
If True all length-1 dimensions (except X and Y) are
|
|
1322
|
+
squeezed out from result.
|
|
1323
|
+
|
|
1324
|
+
colormapped : bool
|
|
1325
|
+
If True color mapping is applied for palette-indexed images.
|
|
1326
|
+
|
|
1327
|
+
rgbonly : bool
|
|
1328
|
+
If True return RGB(A) image without additional extra samples.
|
|
1329
|
+
|
|
1330
|
+
"""
|
|
1331
|
+
fd = self.parent._fd
|
|
1332
|
+
if not fd:
|
|
1333
|
+
raise IOError("TIFF file is not open")
|
|
1334
|
+
if self.dtype is None:
|
|
1335
|
+
raise ValueError("data type not supported: %s%i" % (
|
|
1336
|
+
self.sample_format, self.bits_per_sample))
|
|
1337
|
+
if self.compression not in TIFF_DECOMPESSORS:
|
|
1338
|
+
raise ValueError("cannot decompress %s" % self.compression)
|
|
1339
|
+
if ('ycbcr_subsampling' in self.tags and
|
|
1340
|
+
self.tags['ycbcr_subsampling'].value not in (1, (1, 1))):
|
|
1341
|
+
raise ValueError("YCbCr subsampling not supported")
|
|
1342
|
+
tag = self.tags['sample_format']
|
|
1343
|
+
if tag.count != 1 and any((i-tag.value[0] for i in tag.value)):
|
|
1344
|
+
raise ValueError("sample formats don't match %s" % str(tag.value))
|
|
1345
|
+
|
|
1346
|
+
dtype = self._dtype
|
|
1347
|
+
shape = self._shape
|
|
1348
|
+
image_width = self.image_width
|
|
1349
|
+
image_length = self.image_length
|
|
1350
|
+
typecode = self.parent.byte_order + dtype
|
|
1351
|
+
bits_per_sample = self.bits_per_sample
|
|
1352
|
+
|
|
1353
|
+
if self.is_tiled:
|
|
1354
|
+
if 'tile_offsets' in self.tags:
|
|
1355
|
+
byte_counts = self.tile_byte_counts
|
|
1356
|
+
offsets = self.tile_offsets
|
|
1357
|
+
else:
|
|
1358
|
+
byte_counts = self.strip_byte_counts
|
|
1359
|
+
offsets = self.strip_offsets
|
|
1360
|
+
tile_width = self.tile_width
|
|
1361
|
+
tile_length = self.tile_length
|
|
1362
|
+
tw = (image_width + tile_width - 1) // tile_width
|
|
1363
|
+
tl = (image_length + tile_length - 1) // tile_length
|
|
1364
|
+
shape = shape[:-3] + (tl*tile_length, tw*tile_width, shape[-1])
|
|
1365
|
+
tile_shape = (tile_length, tile_width, shape[-1])
|
|
1366
|
+
runlen = tile_width
|
|
1367
|
+
else:
|
|
1368
|
+
byte_counts = self.strip_byte_counts
|
|
1369
|
+
offsets = self.strip_offsets
|
|
1370
|
+
runlen = image_width
|
|
1371
|
+
|
|
1372
|
+
try:
|
|
1373
|
+
offsets[0]
|
|
1374
|
+
except TypeError:
|
|
1375
|
+
offsets = (offsets, )
|
|
1376
|
+
byte_counts = (byte_counts, )
|
|
1377
|
+
if any(o < 2 for o in offsets):
|
|
1378
|
+
raise ValueError("corrupted file")
|
|
1379
|
+
|
|
1380
|
+
if (not self.is_tiled and (self.is_stk or (not self.compression
|
|
1381
|
+
and bits_per_sample in (8, 16, 32, 64)
|
|
1382
|
+
and all(offsets[i] == offsets[i+1] - byte_counts[i]
|
|
1383
|
+
for i in range(len(offsets)-1))))):
|
|
1384
|
+
# contiguous data
|
|
1385
|
+
fd.seek(offsets[0], 0)
|
|
1386
|
+
if not hasattr(fd, 'name'):
|
|
1387
|
+
# handle reading from BytesIO and similar 'file like' objects
|
|
1388
|
+
# np.fromfile memmaps and hence doesn't work for things which aren't a physical file
|
|
1389
|
+
# we look for the name attribute as a python version independent way of telling the difference
|
|
1390
|
+
result = numpy.frombuffer(fd.read(int(numpy.prod(shape)*numpy.dtype(typecode).itemsize)), typecode)
|
|
1391
|
+
else:
|
|
1392
|
+
result = numpy.fromfile(fd, typecode, numpy.prod(shape))
|
|
1393
|
+
|
|
1394
|
+
result = result.astype('=' + dtype)
|
|
1395
|
+
else:
|
|
1396
|
+
if self.planar_configuration == 'contig':
|
|
1397
|
+
runlen *= self.samples_per_pixel
|
|
1398
|
+
if bits_per_sample in (8, 16, 32, 64, 128):
|
|
1399
|
+
if (bits_per_sample * runlen) % 8:
|
|
1400
|
+
raise ValueError("data and sample size mismatch")
|
|
1401
|
+
unpack = lambda x: numpy.fromstring(x, typecode)
|
|
1402
|
+
elif isinstance(bits_per_sample, tuple):
|
|
1403
|
+
unpack = lambda x: unpackrgb(x, typecode, bits_per_sample)
|
|
1404
|
+
else:
|
|
1405
|
+
unpack = lambda x: unpackints(x, typecode, bits_per_sample,
|
|
1406
|
+
runlen)
|
|
1407
|
+
decompress = TIFF_DECOMPESSORS[self.compression]
|
|
1408
|
+
if self.is_tiled:
|
|
1409
|
+
result = numpy.empty(shape, dtype)
|
|
1410
|
+
tw, tl, pl = 0, 0, 0
|
|
1411
|
+
for offset, bytecount in zip(offsets, byte_counts):
|
|
1412
|
+
fd.seek(offset, 0)
|
|
1413
|
+
tile = unpack(decompress(fd.read(bytecount)))
|
|
1414
|
+
tile.shape = tile_shape
|
|
1415
|
+
result[0, pl, tl:tl+tile_length,
|
|
1416
|
+
tw:tw+tile_width, :] = tile
|
|
1417
|
+
del tile
|
|
1418
|
+
tw += tile_width
|
|
1419
|
+
if tw >= shape[-2]:
|
|
1420
|
+
tw, tl = 0, tl + tile_length
|
|
1421
|
+
if tl >= shape[-3]:
|
|
1422
|
+
tl, pl = 0, pl + 1
|
|
1423
|
+
result = result[..., :image_length, :image_width, :]
|
|
1424
|
+
else:
|
|
1425
|
+
result = numpy.empty(shape, dtype).reshape(-1)
|
|
1426
|
+
index = 0
|
|
1427
|
+
for offset, bytecount in zip(offsets, byte_counts):
|
|
1428
|
+
fd.seek(offset, 0)
|
|
1429
|
+
stripe = unpack(decompress(fd.read(bytecount)))
|
|
1430
|
+
size = min(result.size, stripe.size)
|
|
1431
|
+
result[index:index+size] = stripe[:size]
|
|
1432
|
+
del stripe
|
|
1433
|
+
index += size
|
|
1434
|
+
|
|
1435
|
+
result.shape = self._shape
|
|
1436
|
+
|
|
1437
|
+
if self.predictor == 'horizontal':
|
|
1438
|
+
# workaround bug in LSM510 software
|
|
1439
|
+
if not (self.parent.is_lsm and not self.compression):
|
|
1440
|
+
numpy.cumsum(result, axis=3, dtype=dtype, out=result)
|
|
1441
|
+
|
|
1442
|
+
if colormapped and self.is_palette:
|
|
1443
|
+
if self.color_map.shape[1] >= 2**bits_per_sample:
|
|
1444
|
+
# FluoView and LSM might fail here
|
|
1445
|
+
result = numpy.take(self.color_map, result, axis=1)
|
|
1446
|
+
elif rgbonly and self.is_rgb and 'extra_samples' in self.tags:
|
|
1447
|
+
# return only RGB and first alpha channel if exists
|
|
1448
|
+
extra_samples = self.extra_samples
|
|
1449
|
+
if self.tags['extra_samples'].count == 1:
|
|
1450
|
+
extra_samples = (extra_samples, )
|
|
1451
|
+
for i, exs in enumerate(extra_samples):
|
|
1452
|
+
if exs in ('unassalpha', 'assocalpha'):
|
|
1453
|
+
if self.planar_configuration == 'contig':
|
|
1454
|
+
result = result[..., [0, 1, 2, 3+i]]
|
|
1455
|
+
else:
|
|
1456
|
+
result = result[:, [0, 1, 2, 3+i]]
|
|
1457
|
+
break
|
|
1458
|
+
else:
|
|
1459
|
+
if self.planar_configuration == 'contig':
|
|
1460
|
+
result = result[..., :3]
|
|
1461
|
+
else:
|
|
1462
|
+
result = result[:, :3]
|
|
1463
|
+
|
|
1464
|
+
if squeeze:
|
|
1465
|
+
try:
|
|
1466
|
+
result.shape = self.shape
|
|
1467
|
+
except ValueError:
|
|
1468
|
+
pass
|
|
1469
|
+
|
|
1470
|
+
return result
|
|
1471
|
+
|
|
1472
|
+
def __str__(self):
|
|
1473
|
+
"""Return string containing information about page."""
|
|
1474
|
+
s = ', '.join(s for s in (
|
|
1475
|
+
' x '.join(str(i) for i in self.shape),
|
|
1476
|
+
str(numpy.dtype(self.dtype)),
|
|
1477
|
+
'%s bit' % str(self.bits_per_sample),
|
|
1478
|
+
self.photometric,
|
|
1479
|
+
self.compression if self.compression else 'raw',
|
|
1480
|
+
','.join(t[3:] for t in ('is_stk', 'is_lsm', 'is_nih', 'is_ome',
|
|
1481
|
+
'is_fluoview', 'is_reduced', 'is_tiled')
|
|
1482
|
+
if getattr(self, t))) if s)
|
|
1483
|
+
return "Page %i: %s" % (self.index, s)
|
|
1484
|
+
|
|
1485
|
+
def __getattr__(self, name):
|
|
1486
|
+
"""Return tag value."""
|
|
1487
|
+
if name in self.tags:
|
|
1488
|
+
value = self.tags[name].value
|
|
1489
|
+
setattr(self, name, value)
|
|
1490
|
+
return value
|
|
1491
|
+
raise AttributeError(name)
|
|
1492
|
+
|
|
1493
|
+
@lazyattr
|
|
1494
|
+
def is_rgb(self):
|
|
1495
|
+
"""True if page contains a RGB image."""
|
|
1496
|
+
return self.tags['photometric'].value == 2
|
|
1497
|
+
|
|
1498
|
+
@lazyattr
|
|
1499
|
+
def is_palette(self):
|
|
1500
|
+
"""True if page contains a palette-colored image."""
|
|
1501
|
+
return self.tags['photometric'].value == 3
|
|
1502
|
+
|
|
1503
|
+
@lazyattr
|
|
1504
|
+
def is_tiled(self):
|
|
1505
|
+
"""True if page contains tiled image."""
|
|
1506
|
+
return 'tile_width' in self.tags
|
|
1507
|
+
|
|
1508
|
+
@lazyattr
|
|
1509
|
+
def is_reduced(self):
|
|
1510
|
+
"""True if page is a reduced image of another image."""
|
|
1511
|
+
return bool(self.tags['new_subfile_type'].value & 1)
|
|
1512
|
+
|
|
1513
|
+
@lazyattr
|
|
1514
|
+
def is_stk(self):
|
|
1515
|
+
"""True if page contains MM_UIC2 tag."""
|
|
1516
|
+
return 'mm_uic2' in self.tags
|
|
1517
|
+
|
|
1518
|
+
@lazyattr
|
|
1519
|
+
def is_lsm(self):
|
|
1520
|
+
"""True if page contains LSM CZ_LSM_INFO tag."""
|
|
1521
|
+
return 'cz_lsm_info' in self.tags
|
|
1522
|
+
|
|
1523
|
+
@lazyattr
|
|
1524
|
+
def is_fluoview(self):
|
|
1525
|
+
"""True if page contains FluoView MM_STAMP tag."""
|
|
1526
|
+
return 'mm_stamp' in self.tags
|
|
1527
|
+
|
|
1528
|
+
@lazyattr
|
|
1529
|
+
def is_nih(self):
|
|
1530
|
+
"""True if page contains NIH image header."""
|
|
1531
|
+
return 'nih_image_header' in self.tags
|
|
1532
|
+
|
|
1533
|
+
@lazyattr
|
|
1534
|
+
def is_ome(self):
|
|
1535
|
+
"""True if page contains OME-XML in image_description tag."""
|
|
1536
|
+
return ('image_description' in self.tags and self.tags[
|
|
1537
|
+
'image_description'].value.startswith(b'<?xml version='))
|
|
1538
|
+
|
|
1539
|
+
@lazyattr
|
|
1540
|
+
def is_shaped(self):
|
|
1541
|
+
"""True if page contains shape in image_description tag."""
|
|
1542
|
+
return ('image_description' in self.tags and self.tags[
|
|
1543
|
+
'image_description'].value.startswith(b'shape=('))
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
class TIFFtag(object):
|
|
1547
|
+
"""A TIFF tag structure.
|
|
1548
|
+
|
|
1549
|
+
Attributes
|
|
1550
|
+
----------
|
|
1551
|
+
|
|
1552
|
+
name : string
|
|
1553
|
+
Attribute name of tag.
|
|
1554
|
+
|
|
1555
|
+
code : int
|
|
1556
|
+
Decimal code of tag.
|
|
1557
|
+
|
|
1558
|
+
dtype : str
|
|
1559
|
+
Datatype of tag data. One of TIFF_DATA_TYPES.
|
|
1560
|
+
|
|
1561
|
+
count : int
|
|
1562
|
+
Number of values.
|
|
1563
|
+
|
|
1564
|
+
value : various types
|
|
1565
|
+
Tag data. For codes in CUSTOM_TAGS the 4 bytes file content.
|
|
1566
|
+
|
|
1567
|
+
value_offset : int
|
|
1568
|
+
Location of value in file
|
|
1569
|
+
|
|
1570
|
+
All attributes are read-only.
|
|
1571
|
+
|
|
1572
|
+
"""
|
|
1573
|
+
__slots__ = ('code', 'name', 'count', 'dtype', 'value', 'value_offset',
|
|
1574
|
+
'_offset')
|
|
1575
|
+
|
|
1576
|
+
def __init__(self, arg, **kwargs):
|
|
1577
|
+
"""Initialize instance from file or arguments."""
|
|
1578
|
+
self._offset = None
|
|
1579
|
+
if hasattr(arg, '_fd'):
|
|
1580
|
+
self._fromfile(arg, **kwargs)
|
|
1581
|
+
else:
|
|
1582
|
+
self._fromdata(arg, **kwargs)
|
|
1583
|
+
|
|
1584
|
+
def _fromdata(self, code, dtype, count, value, name=None):
|
|
1585
|
+
"""Initialize instance from arguments."""
|
|
1586
|
+
self.code = int(code)
|
|
1587
|
+
self.name = name if name else str(code)
|
|
1588
|
+
self.dtype = TIFF_DATA_TYPES[dtype]
|
|
1589
|
+
self.count = int(count)
|
|
1590
|
+
self.value = value
|
|
1591
|
+
|
|
1592
|
+
def _fromfile(self, parent):
|
|
1593
|
+
"""Read tag structure from open file. Advances file cursor."""
|
|
1594
|
+
fd = parent._fd
|
|
1595
|
+
byte_order = parent.byte_order
|
|
1596
|
+
|
|
1597
|
+
self._offset = fd.tell()
|
|
1598
|
+
self.value_offset = self._offset + parent.offset_size + 4
|
|
1599
|
+
|
|
1600
|
+
fmt, size = {4: ('HHI4s', 12), 8: ('HHQ8s', 20)}[parent.offset_size]
|
|
1601
|
+
data = fd.read(size)
|
|
1602
|
+
code, dtype = struct.unpack(byte_order + fmt[:2], data[:4])
|
|
1603
|
+
count, value = struct.unpack(byte_order + fmt[2:], data[4:])
|
|
1604
|
+
|
|
1605
|
+
if code in TIFF_TAGS:
|
|
1606
|
+
name = TIFF_TAGS[code][0]
|
|
1607
|
+
elif code in CUSTOM_TAGS:
|
|
1608
|
+
name = CUSTOM_TAGS[code][0]
|
|
1609
|
+
else:
|
|
1610
|
+
name = str(code)
|
|
1611
|
+
|
|
1612
|
+
try:
|
|
1613
|
+
dtype = TIFF_DATA_TYPES[dtype]
|
|
1614
|
+
except KeyError:
|
|
1615
|
+
raise ValueError("unknown TIFF tag data type %i" % dtype)
|
|
1616
|
+
|
|
1617
|
+
if not code in CUSTOM_TAGS:
|
|
1618
|
+
fmt = '%s%i%s' % (byte_order, count*int(dtype[0]), dtype[1])
|
|
1619
|
+
size = struct.calcsize(fmt)
|
|
1620
|
+
if size <= parent.offset_size:
|
|
1621
|
+
value = struct.unpack(fmt, value[:size])
|
|
1622
|
+
else:
|
|
1623
|
+
pos = fd.tell()
|
|
1624
|
+
tof = {4: 'I', 8: 'Q'}[parent.offset_size]
|
|
1625
|
+
self.value_offset = struct.unpack(byte_order+tof, value)[0]
|
|
1626
|
+
fd.seek(self.value_offset)
|
|
1627
|
+
value = struct.unpack(fmt, fd.read(size))
|
|
1628
|
+
fd.seek(pos)
|
|
1629
|
+
if len(value) == 1:
|
|
1630
|
+
value = value[0]
|
|
1631
|
+
if dtype == '1s':
|
|
1632
|
+
value = stripnull(value)
|
|
1633
|
+
|
|
1634
|
+
self.code = code
|
|
1635
|
+
self.name = name
|
|
1636
|
+
self.dtype = dtype
|
|
1637
|
+
self.count = count
|
|
1638
|
+
self.value = value
|
|
1639
|
+
|
|
1640
|
+
def __str__(self):
|
|
1641
|
+
"""Return string containing information about tag."""
|
|
1642
|
+
return ' '.join(str(getattr(self, s)) for s in self.__slots__)
|
|
1643
|
+
|
|
1644
|
+
|
|
1645
|
+
class Record(dict):
|
|
1646
|
+
"""Dictionary with attribute access.
|
|
1647
|
+
|
|
1648
|
+
Can also be initialized with numpy.core.records.record.
|
|
1649
|
+
|
|
1650
|
+
"""
|
|
1651
|
+
__slots__ = ()
|
|
1652
|
+
|
|
1653
|
+
def __init__(self, arg=None, **kwargs):
|
|
1654
|
+
if kwargs:
|
|
1655
|
+
arg = kwargs
|
|
1656
|
+
elif arg is None:
|
|
1657
|
+
arg = {}
|
|
1658
|
+
try:
|
|
1659
|
+
dict.__init__(self, arg)
|
|
1660
|
+
except TypeError:
|
|
1661
|
+
for i, name in enumerate(arg.dtype.names):
|
|
1662
|
+
v = arg[i]
|
|
1663
|
+
self[name] = v if v.dtype.char != 'S' else stripnull(v)
|
|
1664
|
+
|
|
1665
|
+
def __getattr__(self, name):
|
|
1666
|
+
return self[name]
|
|
1667
|
+
|
|
1668
|
+
def __setattr__(self, name, value):
|
|
1669
|
+
self.__setitem__(name, value)
|
|
1670
|
+
|
|
1671
|
+
def __str__(self):
|
|
1672
|
+
"""Pretty print Record."""
|
|
1673
|
+
s = []
|
|
1674
|
+
lists = []
|
|
1675
|
+
for k in sorted(self):
|
|
1676
|
+
if k.startswith('_'):
|
|
1677
|
+
continue
|
|
1678
|
+
v = self[k]
|
|
1679
|
+
if isinstance(v, (list, tuple)) and len(v):
|
|
1680
|
+
if isinstance(v[0], Record):
|
|
1681
|
+
lists.append((k, v))
|
|
1682
|
+
continue
|
|
1683
|
+
elif isinstance(v[0], TIFFpage):
|
|
1684
|
+
v = [i.index for i in v if i]
|
|
1685
|
+
s.append(("* %s: %s" % (k, str(v))).split("\n",
|
|
1686
|
+
1)[0][:PRINT_LINE_LEN])
|
|
1687
|
+
for k, v in lists:
|
|
1688
|
+
l = []
|
|
1689
|
+
for i, w in enumerate(v):
|
|
1690
|
+
l.append("* %s[%i]\n %s" % (k, i,
|
|
1691
|
+
str(w).replace("\n", "\n ")))
|
|
1692
|
+
s.append('\n'.join(l))
|
|
1693
|
+
return '\n'.join(s)
|
|
1694
|
+
|
|
1695
|
+
|
|
1696
|
+
class TiffTags(Record):
|
|
1697
|
+
"""Dictionary of TIFFtags with attribute access."""
|
|
1698
|
+
def __str__(self):
|
|
1699
|
+
"""Return string with information about all tags."""
|
|
1700
|
+
s = []
|
|
1701
|
+
#sortbycode = lambda a, b: cmp(a.code, b.code)
|
|
1702
|
+
#for tag in sorted(self.values(), sortbycode):
|
|
1703
|
+
for tag in sorted(self.values(), key=lambda x: x.code):
|
|
1704
|
+
typecode = "%i%s" % (tag.count * int(tag.dtype[0]), tag.dtype[1])
|
|
1705
|
+
line = "* %i %s (%s) %s" % (tag.code, tag.name, typecode,
|
|
1706
|
+
str(tag.value).split('\n', 1)[0])
|
|
1707
|
+
s.append(line[:PRINT_LINE_LEN])
|
|
1708
|
+
return '\n'.join(s)
|
|
1709
|
+
|
|
1710
|
+
|
|
1711
|
+
def read_nih_image_header(fd, byte_order, tag):
|
|
1712
|
+
"""Read NIH_IMAGE_HEADER tag from file and return as dictionary."""
|
|
1713
|
+
fd.seek(12 + struct.unpack(byte_order+'I', tag.value)[0])
|
|
1714
|
+
return {'version': struct.unpack(byte_order+'H', fd.read(2))[0]}
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
def read_mm_header(fd, byte_order, tag):
|
|
1718
|
+
"""Read MM_HEADER tag from file and return as numpy.rec.array."""
|
|
1719
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1720
|
+
return numpy.rec.fromfile(fd, MM_HEADER, 1, byteorder=byte_order)[0]
|
|
1721
|
+
|
|
1722
|
+
|
|
1723
|
+
def read_mm_stamp(fd, byte_order, tag):
|
|
1724
|
+
"""Read MM_STAMP tag from file and return as numpy.array."""
|
|
1725
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1726
|
+
return numpy.fromfile(fd, byte_order+'8f8', 1)[0]
|
|
1727
|
+
|
|
1728
|
+
|
|
1729
|
+
def read_mm_uic1(fd, byte_order, tag):
|
|
1730
|
+
"""Read MM_UIC1 tag from file and return as dictionary."""
|
|
1731
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1732
|
+
t = fd.read(8*tag.count)
|
|
1733
|
+
t = struct.unpack('%s%iI' % (byte_order, 2*tag.count), t)
|
|
1734
|
+
return dict((MM_TAG_IDS[k], v) for k, v in zip(t[::2], t[1::2])
|
|
1735
|
+
if k in MM_TAG_IDS)
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
def read_mm_uic2(fd, byte_order, tag):
|
|
1739
|
+
"""Read MM_UIC2 tag from file and return as dictionary."""
|
|
1740
|
+
result = {'number_planes': tag.count}
|
|
1741
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1742
|
+
values = numpy.fromfile(fd, byte_order+'I', 6*tag.count)
|
|
1743
|
+
result['z_distance'] = values[0::6] // values[1::6]
|
|
1744
|
+
#result['date_created'] = tuple(values[2::6])
|
|
1745
|
+
#result['time_created'] = tuple(values[3::6])
|
|
1746
|
+
#result['date_modified'] = tuple(values[4::6])
|
|
1747
|
+
#result['time_modified'] = tuple(values[5::6])
|
|
1748
|
+
return result
|
|
1749
|
+
|
|
1750
|
+
|
|
1751
|
+
def read_mm_uic3(fd, byte_order, tag):
|
|
1752
|
+
"""Read MM_UIC3 tag from file and return as dictionary."""
|
|
1753
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1754
|
+
t = numpy.fromfile(fd, '%sI' % byte_order, 2*tag.count)
|
|
1755
|
+
return {'wavelengths': t[0::2] // t[1::2]}
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
def read_mm_uic4(fd, byte_order, tag):
|
|
1759
|
+
"""Read MM_UIC4 tag from file and return as dictionary."""
|
|
1760
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1761
|
+
t = struct.unpack(byte_order + 'hI'*tag.count, fd.read(6*tag.count))
|
|
1762
|
+
return dict((MM_TAG_IDS[k], v) for k, v in zip(t[::2], t[1::2])
|
|
1763
|
+
if k in MM_TAG_IDS)
|
|
1764
|
+
|
|
1765
|
+
|
|
1766
|
+
def read_cz_lsm_info(fd, byte_order, tag):
|
|
1767
|
+
"""Read CS_LSM_INFO tag from file and return as numpy.rec.array."""
|
|
1768
|
+
fd.seek(struct.unpack(byte_order+'I', tag.value)[0])
|
|
1769
|
+
result = numpy.rec.fromfile(fd, CZ_LSM_INFO, 1,
|
|
1770
|
+
byteorder=byte_order)[0]
|
|
1771
|
+
{50350412: '1.3', 67127628: '2.0'}[result.magic_number] # validation
|
|
1772
|
+
return result
|
|
1773
|
+
|
|
1774
|
+
|
|
1775
|
+
def read_cz_lsm_time_stamps(fd, byte_order):
|
|
1776
|
+
"""Read LSM time stamps from file and return as list."""
|
|
1777
|
+
size, count = struct.unpack(byte_order+'II', fd.read(8))
|
|
1778
|
+
if size != (8 + 8 * count):
|
|
1779
|
+
raise ValueError("lsm_time_stamps block is too short")
|
|
1780
|
+
return struct.unpack(('%s%dd' % (byte_order, count)),
|
|
1781
|
+
fd.read(8*count))
|
|
1782
|
+
|
|
1783
|
+
|
|
1784
|
+
def read_cz_lsm_event_list(fd, byte_order):
|
|
1785
|
+
"""Read LSM events from file and return as list of (time, type, text)."""
|
|
1786
|
+
count = struct.unpack(byte_order+'II', fd.read(8))[1]
|
|
1787
|
+
events = []
|
|
1788
|
+
while count > 0:
|
|
1789
|
+
esize, etime, etype = struct.unpack(byte_order+'IdI', fd.read(16))
|
|
1790
|
+
etext = stripnull(fd.read(esize - 16))
|
|
1791
|
+
events.append((etime, etype, etext))
|
|
1792
|
+
count -= 1
|
|
1793
|
+
return events
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
def read_cz_lsm_scan_info(fd, byte_order):
|
|
1797
|
+
"""Read LSM scan information from file and return as Record."""
|
|
1798
|
+
block = Record()
|
|
1799
|
+
blocks = [block]
|
|
1800
|
+
unpack = struct.unpack
|
|
1801
|
+
|
|
1802
|
+
if 0x10000000 != struct.unpack(byte_order+"I", fd.read(4))[0]:
|
|
1803
|
+
raise ValueError("not a lsm_scan_info structure")
|
|
1804
|
+
fd.read(8)
|
|
1805
|
+
|
|
1806
|
+
while True:
|
|
1807
|
+
entry, dtype, size = unpack(byte_order+"III", fd.read(12))
|
|
1808
|
+
if dtype == 2:
|
|
1809
|
+
value = stripnull(fd.read(size))
|
|
1810
|
+
elif dtype == 4:
|
|
1811
|
+
value = unpack(byte_order+"i", fd.read(4))[0]
|
|
1812
|
+
elif dtype == 5:
|
|
1813
|
+
value = unpack(byte_order+"d", fd.read(8))[0]
|
|
1814
|
+
else:
|
|
1815
|
+
value = 0
|
|
1816
|
+
|
|
1817
|
+
if entry in CZ_LSM_SCAN_INFO_ARRAYS:
|
|
1818
|
+
blocks.append(block)
|
|
1819
|
+
name = CZ_LSM_SCAN_INFO_ARRAYS[entry]
|
|
1820
|
+
newobj = []
|
|
1821
|
+
setattr(block, name, newobj)
|
|
1822
|
+
block = newobj
|
|
1823
|
+
elif entry in CZ_LSM_SCAN_INFO_STRUCTS:
|
|
1824
|
+
blocks.append(block)
|
|
1825
|
+
newobj = Record()
|
|
1826
|
+
block.append(newobj)
|
|
1827
|
+
block = newobj
|
|
1828
|
+
elif entry in CZ_LSM_SCAN_INFO_ATTRIBUTES:
|
|
1829
|
+
name = CZ_LSM_SCAN_INFO_ATTRIBUTES[entry]
|
|
1830
|
+
setattr(block, name, value)
|
|
1831
|
+
elif entry == 0xffffffff:
|
|
1832
|
+
block = blocks.pop()
|
|
1833
|
+
else:
|
|
1834
|
+
setattr(block, "unknown_%x" % entry, value)
|
|
1835
|
+
|
|
1836
|
+
if not blocks:
|
|
1837
|
+
break
|
|
1838
|
+
return block
|
|
1839
|
+
|
|
1840
|
+
|
|
1841
|
+
def _replace_by(module_function, warn=True):
|
|
1842
|
+
"""Try replace decorated function by module.function."""
|
|
1843
|
+
|
|
1844
|
+
def decorate(func, module_function=module_function, warn=warn):
|
|
1845
|
+
sys.path.append(os.path.dirname(__file__))
|
|
1846
|
+
try:
|
|
1847
|
+
module, function = module_function.split('.')
|
|
1848
|
+
func, oldfunc = getattr(__import__(module), function), func
|
|
1849
|
+
globals()['__old_' + func.__name__] = oldfunc
|
|
1850
|
+
except Exception:
|
|
1851
|
+
if warn:
|
|
1852
|
+
warnings.warn("failed to import %s" % module_function)
|
|
1853
|
+
sys.path.pop()
|
|
1854
|
+
return func
|
|
1855
|
+
|
|
1856
|
+
return decorate
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
@_replace_by('_tifffile.decodepackbits')
|
|
1860
|
+
def decodepackbits(encoded):
|
|
1861
|
+
"""Decompress PackBits encoded byte string.
|
|
1862
|
+
|
|
1863
|
+
PackBits is a simple byte-oriented run-length compression scheme.
|
|
1864
|
+
|
|
1865
|
+
"""
|
|
1866
|
+
func = ord if sys.version[0] == '2' else lambda x: x
|
|
1867
|
+
result = []
|
|
1868
|
+
i = 0
|
|
1869
|
+
try:
|
|
1870
|
+
while True:
|
|
1871
|
+
n = func(encoded[i]) + 1
|
|
1872
|
+
i += 1
|
|
1873
|
+
if n < 129:
|
|
1874
|
+
result.extend(encoded[i:i+n])
|
|
1875
|
+
i += n
|
|
1876
|
+
elif n > 129:
|
|
1877
|
+
result.extend(encoded[i:i+1] * (258-n))
|
|
1878
|
+
i += 1
|
|
1879
|
+
except IndexError:
|
|
1880
|
+
pass
|
|
1881
|
+
return b''.join(result) if sys.version[0] == '2' else bytes(result)
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
@_replace_by('_tifffile.decodelzw')
|
|
1885
|
+
def decodelzw(encoded):
|
|
1886
|
+
"""Decompress LZW (Lempel-Ziv-Welch) encoded TIFF strip (byte string).
|
|
1887
|
+
|
|
1888
|
+
The strip must begin with a CLEAR code and end with an EOI code.
|
|
1889
|
+
|
|
1890
|
+
This is an implementation of the LZW decoding algorithm described in (1).
|
|
1891
|
+
It is not compatible with old style LZW compressed files like quad-lzw.tif.
|
|
1892
|
+
|
|
1893
|
+
"""
|
|
1894
|
+
unpack = struct.unpack
|
|
1895
|
+
|
|
1896
|
+
if sys.version[0] == '2':
|
|
1897
|
+
newtable = [chr(i) for i in range(256)]
|
|
1898
|
+
else:
|
|
1899
|
+
newtable = [bytes([i]) for i in range(256)]
|
|
1900
|
+
newtable.extend((0, 0))
|
|
1901
|
+
|
|
1902
|
+
def next_code():
|
|
1903
|
+
"""Return integer of `bitw` bits at `bitcount` position in encoded."""
|
|
1904
|
+
start = bitcount // 8
|
|
1905
|
+
s = encoded[start:start+4]
|
|
1906
|
+
try:
|
|
1907
|
+
code = unpack('>I', s)[0]
|
|
1908
|
+
except Exception:
|
|
1909
|
+
code = unpack('>I', s + b'\x00'*(4-len(s)))[0]
|
|
1910
|
+
code = code << (bitcount % 8)
|
|
1911
|
+
code = code & mask
|
|
1912
|
+
return code >> shr
|
|
1913
|
+
|
|
1914
|
+
switchbitch = { # code: bit-width, shr-bits, bit-mask
|
|
1915
|
+
255: (9, 23, int(9*'1'+'0'*23, 2)),
|
|
1916
|
+
511: (10, 22, int(10*'1'+'0'*22, 2)),
|
|
1917
|
+
1023: (11, 21, int(11*'1'+'0'*21, 2)),
|
|
1918
|
+
2047: (12, 20, int(12*'1'+'0'*20, 2)), }
|
|
1919
|
+
bitw, shr, mask = switchbitch[255]
|
|
1920
|
+
bitcount = 0
|
|
1921
|
+
|
|
1922
|
+
if len(encoded) < 4:
|
|
1923
|
+
raise ValueError("strip must be at least 4 characters long")
|
|
1924
|
+
|
|
1925
|
+
if next_code() != 256:
|
|
1926
|
+
raise ValueError("strip must begin with CLEAR code")
|
|
1927
|
+
|
|
1928
|
+
code = oldcode = 0
|
|
1929
|
+
result = []
|
|
1930
|
+
while True:
|
|
1931
|
+
code = next_code() # ~5% faster when inlining this function
|
|
1932
|
+
bitcount += bitw
|
|
1933
|
+
if code == 257: # EOI
|
|
1934
|
+
break
|
|
1935
|
+
if code == 256: # CLEAR
|
|
1936
|
+
table = newtable[:]
|
|
1937
|
+
lentable = 258
|
|
1938
|
+
bitw, shr, mask = switchbitch[255]
|
|
1939
|
+
code = next_code()
|
|
1940
|
+
bitcount += bitw
|
|
1941
|
+
if code == 257: # EOI
|
|
1942
|
+
break
|
|
1943
|
+
result.append(table[code])
|
|
1944
|
+
else:
|
|
1945
|
+
if code < lentable:
|
|
1946
|
+
decoded = table[code]
|
|
1947
|
+
newcode = table[oldcode] + decoded[:1]
|
|
1948
|
+
else:
|
|
1949
|
+
newcode = table[oldcode]
|
|
1950
|
+
newcode += newcode[:1]
|
|
1951
|
+
decoded = newcode
|
|
1952
|
+
result.append(decoded)
|
|
1953
|
+
table.append(newcode)
|
|
1954
|
+
lentable += 1
|
|
1955
|
+
oldcode = code
|
|
1956
|
+
if lentable in switchbitch:
|
|
1957
|
+
bitw, shr, mask = switchbitch[lentable]
|
|
1958
|
+
|
|
1959
|
+
if code != 257:
|
|
1960
|
+
raise ValueError("unexpected end of stream (code %i)" % code)
|
|
1961
|
+
|
|
1962
|
+
return b''.join(result)
|
|
1963
|
+
|
|
1964
|
+
|
|
1965
|
+
@_replace_by('_tifffile.unpackints')
|
|
1966
|
+
def unpackints(data, dtype, itemsize, runlen=0):
|
|
1967
|
+
"""Decompress byte string to array of integers of any bit size <= 32.
|
|
1968
|
+
|
|
1969
|
+
data : byte str
|
|
1970
|
+
|
|
1971
|
+
dtype : numpy.dtype or str
|
|
1972
|
+
A numpy boolean or integer type.
|
|
1973
|
+
|
|
1974
|
+
itemsize : int
|
|
1975
|
+
Number of bits per integer.
|
|
1976
|
+
|
|
1977
|
+
runlen : int
|
|
1978
|
+
Number of consecutive integers, after which to start at next byte.
|
|
1979
|
+
|
|
1980
|
+
"""
|
|
1981
|
+
if itemsize == 1: # bitarray
|
|
1982
|
+
data = numpy.fromstring(data, '|B')
|
|
1983
|
+
data = numpy.unpackbits(data)
|
|
1984
|
+
if runlen % 8:
|
|
1985
|
+
data = data.reshape(-1, runlen+(8-runlen%8))
|
|
1986
|
+
data = data[:, :runlen].reshape(-1)
|
|
1987
|
+
return data.astype(dtype)
|
|
1988
|
+
|
|
1989
|
+
dtype = numpy.dtype(dtype)
|
|
1990
|
+
if itemsize in (8, 16, 32, 64):
|
|
1991
|
+
return numpy.fromstring(data, dtype)
|
|
1992
|
+
if itemsize < 1 or itemsize > 32:
|
|
1993
|
+
raise ValueError("itemsize out of range: %i" % itemsize)
|
|
1994
|
+
if dtype.kind not in "biu":
|
|
1995
|
+
raise ValueError("invalid dtype")
|
|
1996
|
+
|
|
1997
|
+
itembytes = next(i for i in (1, 2, 4, 8) if 8 * i >= itemsize)
|
|
1998
|
+
if itembytes != dtype.itemsize:
|
|
1999
|
+
raise ValueError("dtype.itemsize too small")
|
|
2000
|
+
if runlen == 0:
|
|
2001
|
+
runlen = len(data) // itembytes
|
|
2002
|
+
skipbits = runlen*itemsize % 8
|
|
2003
|
+
if skipbits:
|
|
2004
|
+
skipbits = 8 - skipbits
|
|
2005
|
+
shrbits = itembytes*8 - itemsize
|
|
2006
|
+
bitmask = int(itemsize*'1'+'0'*shrbits, 2)
|
|
2007
|
+
dtypestr = '>' + dtype.char # dtype always big endian?
|
|
2008
|
+
|
|
2009
|
+
unpack = struct.unpack
|
|
2010
|
+
l = runlen * (len(data)*8 // (runlen*itemsize + skipbits))
|
|
2011
|
+
result = numpy.empty((l, ), dtype)
|
|
2012
|
+
bitcount = 0
|
|
2013
|
+
for i in range(len(result)):
|
|
2014
|
+
start = bitcount // 8
|
|
2015
|
+
s = data[start:start+itembytes]
|
|
2016
|
+
try:
|
|
2017
|
+
code = unpack(dtypestr, s)[0]
|
|
2018
|
+
except Exception:
|
|
2019
|
+
code = unpack(dtypestr, s + b'\x00'*(itembytes-len(s)))[0]
|
|
2020
|
+
code = code << (bitcount % 8)
|
|
2021
|
+
code = code & bitmask
|
|
2022
|
+
result[i] = code >> shrbits
|
|
2023
|
+
bitcount += itemsize
|
|
2024
|
+
if (i+1) % runlen == 0:
|
|
2025
|
+
bitcount += skipbits
|
|
2026
|
+
return result
|
|
2027
|
+
|
|
2028
|
+
|
|
2029
|
+
def unpackrgb(data, dtype, bitspersample):
|
|
2030
|
+
"""Unpack RGB565 from byte string."""
|
|
2031
|
+
if not (len(bitspersample) == 3
|
|
2032
|
+
and all(i <= 8 for i in bitspersample)
|
|
2033
|
+
and numpy.sum(bitspersample) == 16):
|
|
2034
|
+
raise ValueError("sample size not supported %s" % str(bitspersample))
|
|
2035
|
+
data = numpy.fromstring(data, dtype[0]+'H')
|
|
2036
|
+
r, g, b = bitspersample
|
|
2037
|
+
result = numpy.zeros((data.size, 3), 'uint8')
|
|
2038
|
+
result[:, 0] = ((data >> (r+g)) & (int('0b'+'1'*r, 2))) << (8 - r)
|
|
2039
|
+
result[:, 1] = ((data >> r) & (int('0b'+'1'*g, 2))) << (8 - g)
|
|
2040
|
+
result[:, 2] = (data & (int('0b'+'1'*b, 2))) << (8 - b)
|
|
2041
|
+
return result.reshape(-1)
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
def reorient(image, orientation):
|
|
2045
|
+
"""Return reoriented view of image array.
|
|
2046
|
+
|
|
2047
|
+
image : numpy array
|
|
2048
|
+
Non-squeezed output of asarray() functions.
|
|
2049
|
+
Axes -3 and -2 must be image length and width respectively.
|
|
2050
|
+
|
|
2051
|
+
orientation : int or str
|
|
2052
|
+
One of TIFF_ORIENTATIONS keys or values
|
|
2053
|
+
|
|
2054
|
+
"""
|
|
2055
|
+
o = TIFF_ORIENTATIONS.get(orientation, orientation)
|
|
2056
|
+
if o == 'top_left':
|
|
2057
|
+
return image
|
|
2058
|
+
elif o == 'top_right':
|
|
2059
|
+
return image[..., ::-1, :]
|
|
2060
|
+
elif o == 'bottom_left':
|
|
2061
|
+
return image[..., ::-1, :, :]
|
|
2062
|
+
elif o == 'bottom_right':
|
|
2063
|
+
return image[..., ::-1, ::-1, :]
|
|
2064
|
+
elif o == 'left_top':
|
|
2065
|
+
return numpy.swapaxes(image, -3, -2)
|
|
2066
|
+
elif o == 'right_top':
|
|
2067
|
+
return numpy.swapaxes(image, -3, -2)[..., ::-1, :]
|
|
2068
|
+
elif o == 'left_bottom':
|
|
2069
|
+
return numpy.swapaxes(image, -3, -2)[..., ::-1, :, :]
|
|
2070
|
+
elif o == 'right_bottom':
|
|
2071
|
+
return numpy.swapaxes(image, -3, -2)[..., ::-1, ::-1, :]
|
|
2072
|
+
|
|
2073
|
+
|
|
2074
|
+
def stripnull(string):
|
|
2075
|
+
"""Return string truncated at first null character."""
|
|
2076
|
+
i = string.find(b'\x00')
|
|
2077
|
+
return string if (i < 0) else string[:i]
|
|
2078
|
+
|
|
2079
|
+
|
|
2080
|
+
def datetime_from_timestamp(n, epoch=datetime.datetime.fromordinal(693594)):
|
|
2081
|
+
"""Return datetime object from timestamp in Excel serial format.
|
|
2082
|
+
|
|
2083
|
+
>>> datetime_from_timestamp(40237.029999999795)
|
|
2084
|
+
datetime.datetime(2010, 2, 28, 0, 43, 11, 999982)
|
|
2085
|
+
|
|
2086
|
+
"""
|
|
2087
|
+
return epoch + datetime.timedelta(n)
|
|
2088
|
+
|
|
2089
|
+
|
|
2090
|
+
def test_tifffile(directory='testimages', verbose=True):
|
|
2091
|
+
"""Read all images in directory. Print error message on failure.
|
|
2092
|
+
|
|
2093
|
+
>>> test_tifffile(verbose=False)
|
|
2094
|
+
|
|
2095
|
+
"""
|
|
2096
|
+
import glob
|
|
2097
|
+
|
|
2098
|
+
successful = 0
|
|
2099
|
+
failed = 0
|
|
2100
|
+
start = time.time()
|
|
2101
|
+
for f in glob.glob(os.path.join(directory, '*.*')):
|
|
2102
|
+
if verbose:
|
|
2103
|
+
print("\n%s>\n" % f.lower(), end='')
|
|
2104
|
+
t0 = time.time()
|
|
2105
|
+
try:
|
|
2106
|
+
tif = TIFFfile(f)
|
|
2107
|
+
except Exception as e:
|
|
2108
|
+
if not verbose:
|
|
2109
|
+
print(f, end=' ')
|
|
2110
|
+
print("ERROR:", e)
|
|
2111
|
+
failed += 1
|
|
2112
|
+
continue
|
|
2113
|
+
try:
|
|
2114
|
+
img = tif.asarray()
|
|
2115
|
+
except ValueError:
|
|
2116
|
+
try:
|
|
2117
|
+
img = tif[0].asarray()
|
|
2118
|
+
except Exception as e:
|
|
2119
|
+
if not verbose:
|
|
2120
|
+
print(f, end=' ')
|
|
2121
|
+
print("ERROR:", e)
|
|
2122
|
+
failed += 1
|
|
2123
|
+
continue
|
|
2124
|
+
finally:
|
|
2125
|
+
tif.close()
|
|
2126
|
+
successful += 1
|
|
2127
|
+
if verbose:
|
|
2128
|
+
print("%s, %s %s, %s, %.0f ms" % (str(tif), str(img.shape),
|
|
2129
|
+
img.dtype, tif[0].compression, (time.time()-t0) * 1e3))
|
|
2130
|
+
if verbose:
|
|
2131
|
+
print("\nSuccessfully read %i of %i files in %.3f s\n" % (
|
|
2132
|
+
successful, successful+failed, time.time()-start))
|
|
2133
|
+
|
|
2134
|
+
|
|
2135
|
+
class TIFF_SUBFILE_TYPES(object):
|
|
2136
|
+
def __getitem__(self, key):
|
|
2137
|
+
result = []
|
|
2138
|
+
if key & 1:
|
|
2139
|
+
result.append('reduced_image')
|
|
2140
|
+
if key & 2:
|
|
2141
|
+
result.append('page')
|
|
2142
|
+
if key & 4:
|
|
2143
|
+
result.append('mask')
|
|
2144
|
+
return tuple(result)
|
|
2145
|
+
|
|
2146
|
+
|
|
2147
|
+
TIFF_PHOTOMETRICS = {
|
|
2148
|
+
0: 'miniswhite',
|
|
2149
|
+
1: 'minisblack',
|
|
2150
|
+
2: 'rgb',
|
|
2151
|
+
3: 'palette',
|
|
2152
|
+
4: 'mask',
|
|
2153
|
+
5: 'separated',
|
|
2154
|
+
6: 'cielab',
|
|
2155
|
+
7: 'icclab',
|
|
2156
|
+
8: 'itulab',
|
|
2157
|
+
32844: 'logl',
|
|
2158
|
+
32845: 'logluv'}
|
|
2159
|
+
|
|
2160
|
+
TIFF_COMPESSIONS = {
|
|
2161
|
+
1: None,
|
|
2162
|
+
2: 'ccittrle',
|
|
2163
|
+
3: 'ccittfax3',
|
|
2164
|
+
4: 'ccittfax4',
|
|
2165
|
+
5: 'lzw',
|
|
2166
|
+
6: 'ojpeg',
|
|
2167
|
+
7: 'jpeg',
|
|
2168
|
+
8: 'adobe_deflate',
|
|
2169
|
+
9: 't85',
|
|
2170
|
+
10: 't43',
|
|
2171
|
+
32766: 'next',
|
|
2172
|
+
32771: 'ccittrlew',
|
|
2173
|
+
32773: 'packbits',
|
|
2174
|
+
32809: 'thunderscan',
|
|
2175
|
+
32895: 'it8ctpad',
|
|
2176
|
+
32896: 'it8lw',
|
|
2177
|
+
32897: 'it8mp',
|
|
2178
|
+
32898: 'it8bl',
|
|
2179
|
+
32908: 'pixarfilm',
|
|
2180
|
+
32909: 'pixarlog',
|
|
2181
|
+
32946: 'deflate',
|
|
2182
|
+
32947: 'dcs',
|
|
2183
|
+
34661: 'jbig',
|
|
2184
|
+
34676: 'sgilog',
|
|
2185
|
+
34677: 'sgilog24',
|
|
2186
|
+
34712: 'jp2000'}
|
|
2187
|
+
|
|
2188
|
+
TIFF_DECOMPESSORS = {
|
|
2189
|
+
None: lambda x: x,
|
|
2190
|
+
'adobe_deflate': zlib.decompress,
|
|
2191
|
+
'deflate': zlib.decompress,
|
|
2192
|
+
'packbits': decodepackbits,
|
|
2193
|
+
'lzw': decodelzw}
|
|
2194
|
+
|
|
2195
|
+
TIFF_DATA_TYPES = {
|
|
2196
|
+
1: '1B', # BYTE 8-bit unsigned integer.
|
|
2197
|
+
2: '1s', # ASCII 8-bit byte that contains a 7-bit ASCII code;
|
|
2198
|
+
# the last byte must be NULL (binary zero).
|
|
2199
|
+
3: '1H', # SHORT 16-bit (2-byte) unsigned integer
|
|
2200
|
+
4: '1I', # LONG 32-bit (4-byte) unsigned integer.
|
|
2201
|
+
5: '2I', # RATIONAL Two LONGs: the first represents the numerator of
|
|
2202
|
+
# a fraction; the second, the denominator.
|
|
2203
|
+
6: '1b', # SBYTE An 8-bit signed (twos-complement) integer.
|
|
2204
|
+
7: '1B', # UNDEFINED An 8-bit byte that may contain anything,
|
|
2205
|
+
# depending on the definition of the field.
|
|
2206
|
+
8: '1h', # SSHORT A 16-bit (2-byte) signed (twos-complement) integer.
|
|
2207
|
+
9: '1i', # SLONG A 32-bit (4-byte) signed (twos-complement) integer.
|
|
2208
|
+
10: '2i', # SRATIONAL Two SLONGs: the first represents the numerator
|
|
2209
|
+
# of a fraction, the second the denominator.
|
|
2210
|
+
11: '1f', # FLOAT Single precision (4-byte) IEEE format.
|
|
2211
|
+
12: '1d', # DOUBLE Double precision (8-byte) IEEE format.
|
|
2212
|
+
13: '1I', # IFD unsigned 4 byte IFD offset.
|
|
2213
|
+
#14: '', # UNICODE
|
|
2214
|
+
#15: '', # COMPLEX
|
|
2215
|
+
16: '1Q', # LONG8 unsigned 8 byte integer (BigTiff)
|
|
2216
|
+
17: '1q', # SLONG8 signed 8 byte integer (BigTiff)
|
|
2217
|
+
18: '1Q'} # IFD8 unsigned 8 byte IFD offset (BigTiff)
|
|
2218
|
+
|
|
2219
|
+
TIFF_SAMPLE_FORMATS = {
|
|
2220
|
+
1: 'uint',
|
|
2221
|
+
2: 'int',
|
|
2222
|
+
3: 'float',
|
|
2223
|
+
#4: 'void',
|
|
2224
|
+
#5: 'complex_int',
|
|
2225
|
+
6: 'complex'}
|
|
2226
|
+
|
|
2227
|
+
TIFF_SAMPLE_DTYPES = {
|
|
2228
|
+
('uint', 1): '?', # bitmap
|
|
2229
|
+
('uint', 2): 'B',
|
|
2230
|
+
('uint', 3): 'B',
|
|
2231
|
+
('uint', 4): 'B',
|
|
2232
|
+
('uint', 5): 'B',
|
|
2233
|
+
('uint', 6): 'B',
|
|
2234
|
+
('uint', 7): 'B',
|
|
2235
|
+
('uint', 8): 'B',
|
|
2236
|
+
('uint', 9): 'H',
|
|
2237
|
+
('uint', 10): 'H',
|
|
2238
|
+
('uint', 11): 'H',
|
|
2239
|
+
('uint', 12): 'H',
|
|
2240
|
+
('uint', 13): 'H',
|
|
2241
|
+
('uint', 14): 'H',
|
|
2242
|
+
('uint', 15): 'H',
|
|
2243
|
+
('uint', 16): 'H',
|
|
2244
|
+
('uint', 17): 'I',
|
|
2245
|
+
('uint', 18): 'I',
|
|
2246
|
+
('uint', 19): 'I',
|
|
2247
|
+
('uint', 20): 'I',
|
|
2248
|
+
('uint', 21): 'I',
|
|
2249
|
+
('uint', 22): 'I',
|
|
2250
|
+
('uint', 23): 'I',
|
|
2251
|
+
('uint', 24): 'I',
|
|
2252
|
+
('uint', 25): 'I',
|
|
2253
|
+
('uint', 26): 'I',
|
|
2254
|
+
('uint', 27): 'I',
|
|
2255
|
+
('uint', 28): 'I',
|
|
2256
|
+
('uint', 29): 'I',
|
|
2257
|
+
('uint', 30): 'I',
|
|
2258
|
+
('uint', 31): 'I',
|
|
2259
|
+
('uint', 32): 'I',
|
|
2260
|
+
('uint', 64): 'Q',
|
|
2261
|
+
('int', 8): 'b',
|
|
2262
|
+
('int', 16): 'h',
|
|
2263
|
+
('int', 32): 'i',
|
|
2264
|
+
('int', 64): 'q',
|
|
2265
|
+
('float', 16): 'e',
|
|
2266
|
+
('float', 32): 'f',
|
|
2267
|
+
('float', 64): 'd',
|
|
2268
|
+
('complex', 64): 'F',
|
|
2269
|
+
('complex', 128): 'D',
|
|
2270
|
+
('uint', (5, 6, 5)): 'B'}
|
|
2271
|
+
|
|
2272
|
+
TIFF_ORIENTATIONS = {
|
|
2273
|
+
1: 'top_left',
|
|
2274
|
+
2: 'top_right',
|
|
2275
|
+
3: 'bottom_right',
|
|
2276
|
+
4: 'bottom_left',
|
|
2277
|
+
5: 'left_top',
|
|
2278
|
+
6: 'right_top',
|
|
2279
|
+
7: 'right_bottom',
|
|
2280
|
+
8: 'left_bottom'}
|
|
2281
|
+
|
|
2282
|
+
AXES_LABELS = {
|
|
2283
|
+
'X': 'width',
|
|
2284
|
+
'Y': 'height',
|
|
2285
|
+
'Z': 'depth',
|
|
2286
|
+
'S': 'sample',
|
|
2287
|
+
'P': 'plane',
|
|
2288
|
+
'T': 'time',
|
|
2289
|
+
'C': 'channel', # color, emission wavelength
|
|
2290
|
+
'A': 'angle',
|
|
2291
|
+
'F': 'phase',
|
|
2292
|
+
'R': 'tile', # region
|
|
2293
|
+
'H': 'lifetime', # histogram
|
|
2294
|
+
'E': 'lambda', # excitation wavelength
|
|
2295
|
+
'L': 'exposure', # lux
|
|
2296
|
+
'V': 'event',
|
|
2297
|
+
'O': 'other'}
|
|
2298
|
+
|
|
2299
|
+
AXES_LABELS.update(dict((v, k) for k, v in AXES_LABELS.items()))
|
|
2300
|
+
|
|
2301
|
+
# MetaMorph STK tags
|
|
2302
|
+
MM_TAG_IDS = {
|
|
2303
|
+
0: 'auto_scale',
|
|
2304
|
+
1: 'min_scale',
|
|
2305
|
+
2: 'max_scale',
|
|
2306
|
+
3: 'spatial_calibration',
|
|
2307
|
+
#4: 'x_calibration',
|
|
2308
|
+
#5: 'y_calibration',
|
|
2309
|
+
#6: 'calibration_units',
|
|
2310
|
+
#7: 'name',
|
|
2311
|
+
8: 'thresh_state',
|
|
2312
|
+
9: 'thresh_state_red',
|
|
2313
|
+
11: 'thresh_state_green',
|
|
2314
|
+
12: 'thresh_state_blue',
|
|
2315
|
+
13: 'thresh_state_lo',
|
|
2316
|
+
14: 'thresh_state_hi',
|
|
2317
|
+
15: 'zoom',
|
|
2318
|
+
#16: 'create_time',
|
|
2319
|
+
#17: 'last_saved_time',
|
|
2320
|
+
18: 'current_buffer',
|
|
2321
|
+
19: 'gray_fit',
|
|
2322
|
+
20: 'gray_point_count',
|
|
2323
|
+
#21: 'gray_x',
|
|
2324
|
+
#22: 'gray_y',
|
|
2325
|
+
#23: 'gray_min',
|
|
2326
|
+
#24: 'gray_max',
|
|
2327
|
+
#25: 'gray_unit_name',
|
|
2328
|
+
26: 'standard_lut',
|
|
2329
|
+
27: 'wavelength',
|
|
2330
|
+
#28: 'stage_position',
|
|
2331
|
+
#29: 'camera_chip_offset',
|
|
2332
|
+
#30: 'overlay_mask',
|
|
2333
|
+
#31: 'overlay_compress',
|
|
2334
|
+
#32: 'overlay',
|
|
2335
|
+
#33: 'special_overlay_mask',
|
|
2336
|
+
#34: 'special_overlay_compress',
|
|
2337
|
+
#35: 'special_overlay',
|
|
2338
|
+
36: 'image_property',
|
|
2339
|
+
#37: 'stage_label',
|
|
2340
|
+
#38: 'autoscale_lo_info',
|
|
2341
|
+
#39: 'autoscale_hi_info',
|
|
2342
|
+
#40: 'absolute_z',
|
|
2343
|
+
#41: 'absolute_z_valid',
|
|
2344
|
+
#42: 'gamma',
|
|
2345
|
+
#43: 'gamma_red',
|
|
2346
|
+
#44: 'gamma_green',
|
|
2347
|
+
#45: 'gamma_blue',
|
|
2348
|
+
#46: 'camera_bin',
|
|
2349
|
+
47: 'new_lut',
|
|
2350
|
+
#48: 'image_property_ex',
|
|
2351
|
+
49: 'plane_property',
|
|
2352
|
+
#50: 'user_lut_table',
|
|
2353
|
+
51: 'red_autoscale_info',
|
|
2354
|
+
#52: 'red_autoscale_lo_info',
|
|
2355
|
+
#53: 'red_autoscale_hi_info',
|
|
2356
|
+
54: 'red_minscale_info',
|
|
2357
|
+
55: 'red_maxscale_info',
|
|
2358
|
+
56: 'green_autoscale_info',
|
|
2359
|
+
#57: 'green_autoscale_lo_info',
|
|
2360
|
+
#58: 'green_autoscale_hi_info',
|
|
2361
|
+
59: 'green_minscale_info',
|
|
2362
|
+
60: 'green_maxscale_info',
|
|
2363
|
+
61: 'blue_autoscale_info',
|
|
2364
|
+
#62: 'blue_autoscale_lo_info',
|
|
2365
|
+
#63: 'blue_autoscale_hi_info',
|
|
2366
|
+
64: 'blue_min_scale_info',
|
|
2367
|
+
65: 'blue_max_scale_info'}
|
|
2368
|
+
#66: 'overlay_plane_color',
|
|
2369
|
+
|
|
2370
|
+
# Olymus Fluoview
|
|
2371
|
+
MM_DIMENSION = [
|
|
2372
|
+
('name', 'a16'),
|
|
2373
|
+
('size', 'i4'),
|
|
2374
|
+
('origin', 'f8'),
|
|
2375
|
+
('resolution', 'f8'),
|
|
2376
|
+
('unit', 'a64')]
|
|
2377
|
+
|
|
2378
|
+
MM_HEADER = [
|
|
2379
|
+
('header_flag', 'i2'),
|
|
2380
|
+
('image_type', 'u1'),
|
|
2381
|
+
('image_name', 'a257'),
|
|
2382
|
+
('offset_data', 'u4'),
|
|
2383
|
+
('palette_size', 'i4'),
|
|
2384
|
+
('offset_palette0', 'u4'),
|
|
2385
|
+
('offset_palette1', 'u4'),
|
|
2386
|
+
('comment_size', 'i4'),
|
|
2387
|
+
('offset_comment', 'u4'),
|
|
2388
|
+
('dimensions', MM_DIMENSION, 10),
|
|
2389
|
+
('offset_position', 'u4'),
|
|
2390
|
+
('map_type', 'i2'),
|
|
2391
|
+
('map_min', 'f8'),
|
|
2392
|
+
('map_max', 'f8'),
|
|
2393
|
+
('min_value', 'f8'),
|
|
2394
|
+
('max_value', 'f8'),
|
|
2395
|
+
('offset_map', 'u4'),
|
|
2396
|
+
('gamma', 'f8'),
|
|
2397
|
+
('offset', 'f8'),
|
|
2398
|
+
('gray_channel', MM_DIMENSION),
|
|
2399
|
+
('offset_thumbnail', 'u4'),
|
|
2400
|
+
('voice_field', 'i4'),
|
|
2401
|
+
('offset_voice_field', 'u4')]
|
|
2402
|
+
|
|
2403
|
+
# Carl Zeiss LSM
|
|
2404
|
+
CZ_LSM_INFO = [
|
|
2405
|
+
('magic_number', 'i4'),
|
|
2406
|
+
('structure_size', 'i4'),
|
|
2407
|
+
('dimension_x', 'i4'),
|
|
2408
|
+
('dimension_y', 'i4'),
|
|
2409
|
+
('dimension_z', 'i4'),
|
|
2410
|
+
('dimension_channels', 'i4'),
|
|
2411
|
+
('dimension_time', 'i4'),
|
|
2412
|
+
('dimension_data_type', 'i4'),
|
|
2413
|
+
('thumbnail_x', 'i4'),
|
|
2414
|
+
('thumbnail_y', 'i4'),
|
|
2415
|
+
('voxel_size_x', 'f8'),
|
|
2416
|
+
('voxel_size_y', 'f8'),
|
|
2417
|
+
('voxel_size_z', 'f8'),
|
|
2418
|
+
('origin_x', 'f8'),
|
|
2419
|
+
('origin_y', 'f8'),
|
|
2420
|
+
('origin_z', 'f8'),
|
|
2421
|
+
('scan_type', 'u2'),
|
|
2422
|
+
('spectral_scan', 'u2'),
|
|
2423
|
+
('data_type', 'u4'),
|
|
2424
|
+
('offset_vector_overlay', 'u4'),
|
|
2425
|
+
('offset_input_lut', 'u4'),
|
|
2426
|
+
('offset_output_lut', 'u4'),
|
|
2427
|
+
('offset_channel_colors', 'u4'),
|
|
2428
|
+
('time_interval', 'f8'),
|
|
2429
|
+
('offset_channel_data_types', 'u4'),
|
|
2430
|
+
('offset_scan_information', 'u4'),
|
|
2431
|
+
('offset_ks_data', 'u4'),
|
|
2432
|
+
('offset_time_stamps', 'u4'),
|
|
2433
|
+
('offset_event_list', 'u4'),
|
|
2434
|
+
('offset_roi', 'u4'),
|
|
2435
|
+
('offset_bleach_roi', 'u4'),
|
|
2436
|
+
('offset_next_recording', 'u4'),
|
|
2437
|
+
('display_aspect_x', 'f8'),
|
|
2438
|
+
('display_aspect_y', 'f8'),
|
|
2439
|
+
('display_aspect_z', 'f8'),
|
|
2440
|
+
('display_aspect_time', 'f8'),
|
|
2441
|
+
('offset_mean_of_roi_overlay', 'u4'),
|
|
2442
|
+
('offset_topo_isoline_overlay', 'u4'),
|
|
2443
|
+
('offset_topo_profile_overlay', 'u4'),
|
|
2444
|
+
('offset_linescan_overlay', 'u4'),
|
|
2445
|
+
('offset_toolbar_flags', 'u4')]
|
|
2446
|
+
|
|
2447
|
+
# Import functions for LSM_INFO subrecords
|
|
2448
|
+
CZ_LSM_INFO_READERS = {
|
|
2449
|
+
'scan_information': read_cz_lsm_scan_info,
|
|
2450
|
+
'time_stamps': read_cz_lsm_time_stamps,
|
|
2451
|
+
'event_list': read_cz_lsm_event_list}
|
|
2452
|
+
|
|
2453
|
+
# Map cz_lsm_info.scan_type to dimension order
|
|
2454
|
+
CZ_SCAN_TYPES = {
|
|
2455
|
+
0: 'XYZCT', # x-y-z scan
|
|
2456
|
+
1: 'XYZCT', # z scan (x-z plane)
|
|
2457
|
+
2: 'XYZCT', # line scan
|
|
2458
|
+
3: 'XYTCZ', # time series x-y
|
|
2459
|
+
4: 'XYZTC', # time series x-z
|
|
2460
|
+
5: 'XYTCZ', # time series 'Mean of ROIs'
|
|
2461
|
+
6: 'XYZTC', # time series x-y-z
|
|
2462
|
+
7: 'XYCTZ', # spline scan
|
|
2463
|
+
8: 'XYCZT', # spline scan x-z
|
|
2464
|
+
9: 'XYTCZ', # time series spline plane x-z
|
|
2465
|
+
10: 'XYZCT'} # point mode
|
|
2466
|
+
|
|
2467
|
+
# Map dimension codes to cz_lsm_info attribute
|
|
2468
|
+
CZ_DIMENSIONS = {
|
|
2469
|
+
'X': 'dimension_x',
|
|
2470
|
+
'Y': 'dimension_y',
|
|
2471
|
+
'Z': 'dimension_z',
|
|
2472
|
+
'C': 'dimension_channels',
|
|
2473
|
+
'T': 'dimension_time'}
|
|
2474
|
+
|
|
2475
|
+
# Descriptions of cz_lsm_info.data_type
|
|
2476
|
+
CZ_DATA_TYPES = {
|
|
2477
|
+
0: 'varying data types',
|
|
2478
|
+
2: '12 bit unsigned integer',
|
|
2479
|
+
5: '32 bit float'}
|
|
2480
|
+
|
|
2481
|
+
CZ_LSM_SCAN_INFO_ARRAYS = {
|
|
2482
|
+
0x20000000: "tracks",
|
|
2483
|
+
0x30000000: "lasers",
|
|
2484
|
+
0x60000000: "detectionchannels",
|
|
2485
|
+
0x80000000: "illuminationchannels",
|
|
2486
|
+
0xa0000000: "beamsplitters",
|
|
2487
|
+
0xc0000000: "datachannels",
|
|
2488
|
+
0x13000000: "markers",
|
|
2489
|
+
0x11000000: "timers"}
|
|
2490
|
+
|
|
2491
|
+
CZ_LSM_SCAN_INFO_STRUCTS = {
|
|
2492
|
+
0x40000000: "tracks",
|
|
2493
|
+
0x50000000: "lasers",
|
|
2494
|
+
0x70000000: "detectionchannels",
|
|
2495
|
+
0x90000000: "illuminationchannels",
|
|
2496
|
+
0xb0000000: "beamsplitters",
|
|
2497
|
+
0xd0000000: "datachannels",
|
|
2498
|
+
0x14000000: "markers",
|
|
2499
|
+
0x12000000: "timers"}
|
|
2500
|
+
|
|
2501
|
+
CZ_LSM_SCAN_INFO_ATTRIBUTES = {
|
|
2502
|
+
0x10000001: "name",
|
|
2503
|
+
0x10000002: "description",
|
|
2504
|
+
0x10000003: "notes",
|
|
2505
|
+
0x10000004: "objective",
|
|
2506
|
+
0x10000005: "processing_summary",
|
|
2507
|
+
0x10000006: "special_scan_mode",
|
|
2508
|
+
0x10000007: "oledb_recording_scan_type",
|
|
2509
|
+
0x10000008: "oledb_recording_scan_mode",
|
|
2510
|
+
0x10000009: "number_of_stacks",
|
|
2511
|
+
0x1000000a: "lines_per_plane",
|
|
2512
|
+
0x1000000b: "samples_per_line",
|
|
2513
|
+
0x1000000c: "planes_per_volume",
|
|
2514
|
+
0x1000000d: "images_width",
|
|
2515
|
+
0x1000000e: "images_height",
|
|
2516
|
+
0x1000000f: "images_number_planes",
|
|
2517
|
+
0x10000010: "images_number_stacks",
|
|
2518
|
+
0x10000011: "images_number_channels",
|
|
2519
|
+
0x10000012: "linscan_xy_size",
|
|
2520
|
+
0x10000013: "scan_direction",
|
|
2521
|
+
0x10000014: "time_series",
|
|
2522
|
+
0x10000015: "original_scan_data",
|
|
2523
|
+
0x10000016: "zoom_x",
|
|
2524
|
+
0x10000017: "zoom_y",
|
|
2525
|
+
0x10000018: "zoom_z",
|
|
2526
|
+
0x10000019: "sample_0x",
|
|
2527
|
+
0x1000001a: "sample_0y",
|
|
2528
|
+
0x1000001b: "sample_0z",
|
|
2529
|
+
0x1000001c: "sample_spacing",
|
|
2530
|
+
0x1000001d: "line_spacing",
|
|
2531
|
+
0x1000001e: "plane_spacing",
|
|
2532
|
+
0x1000001f: "plane_width",
|
|
2533
|
+
0x10000020: "plane_height",
|
|
2534
|
+
0x10000021: "volume_depth",
|
|
2535
|
+
0x10000023: "nutation",
|
|
2536
|
+
0x10000034: "rotation",
|
|
2537
|
+
0x10000035: "precession",
|
|
2538
|
+
0x10000036: "sample_0time",
|
|
2539
|
+
0x10000037: "start_scan_trigger_in",
|
|
2540
|
+
0x10000038: "start_scan_trigger_out",
|
|
2541
|
+
0x10000039: "start_scan_event",
|
|
2542
|
+
0x10000040: "start_scan_time",
|
|
2543
|
+
0x10000041: "stop_scan_trigger_in",
|
|
2544
|
+
0x10000042: "stop_scan_trigger_out",
|
|
2545
|
+
0x10000043: "stop_scan_event",
|
|
2546
|
+
0x10000044: "stop_scan_time",
|
|
2547
|
+
0x10000045: "use_rois",
|
|
2548
|
+
0x10000046: "use_reduced_memory_rois",
|
|
2549
|
+
0x10000047: "user",
|
|
2550
|
+
0x10000048: "use_bccorrection",
|
|
2551
|
+
0x10000049: "position_bccorrection1",
|
|
2552
|
+
0x10000050: "position_bccorrection2",
|
|
2553
|
+
0x10000051: "interpolation_y",
|
|
2554
|
+
0x10000052: "camera_binning",
|
|
2555
|
+
0x10000053: "camera_supersampling",
|
|
2556
|
+
0x10000054: "camera_frame_width",
|
|
2557
|
+
0x10000055: "camera_frame_height",
|
|
2558
|
+
0x10000056: "camera_offset_x",
|
|
2559
|
+
0x10000057: "camera_offset_y",
|
|
2560
|
+
# lasers
|
|
2561
|
+
0x50000001: "name",
|
|
2562
|
+
0x50000002: "acquire",
|
|
2563
|
+
0x50000003: "power",
|
|
2564
|
+
# tracks
|
|
2565
|
+
0x40000001: "multiplex_type",
|
|
2566
|
+
0x40000002: "multiplex_order",
|
|
2567
|
+
0x40000003: "sampling_mode",
|
|
2568
|
+
0x40000004: "sampling_method",
|
|
2569
|
+
0x40000005: "sampling_number",
|
|
2570
|
+
0x40000006: "acquire",
|
|
2571
|
+
0x40000007: "sample_observation_time",
|
|
2572
|
+
0x4000000b: "time_between_stacks",
|
|
2573
|
+
0x4000000c: "name",
|
|
2574
|
+
0x4000000d: "collimator1_name",
|
|
2575
|
+
0x4000000e: "collimator1_position",
|
|
2576
|
+
0x4000000f: "collimator2_name",
|
|
2577
|
+
0x40000010: "collimator2_position",
|
|
2578
|
+
0x40000011: "is_bleach_track",
|
|
2579
|
+
0x40000012: "is_bleach_after_scan_number",
|
|
2580
|
+
0x40000013: "bleach_scan_number",
|
|
2581
|
+
0x40000014: "trigger_in",
|
|
2582
|
+
0x40000015: "trigger_out",
|
|
2583
|
+
0x40000016: "is_ratio_track",
|
|
2584
|
+
0x40000017: "bleach_count",
|
|
2585
|
+
0x40000018: "spi_center_wavelength",
|
|
2586
|
+
0x40000019: "pixel_time",
|
|
2587
|
+
0x40000021: "condensor_frontlens",
|
|
2588
|
+
0x40000023: "field_stop_value",
|
|
2589
|
+
0x40000024: "id_condensor_aperture",
|
|
2590
|
+
0x40000025: "condensor_aperture",
|
|
2591
|
+
0x40000026: "id_condensor_revolver",
|
|
2592
|
+
0x40000027: "condensor_filter",
|
|
2593
|
+
0x40000028: "id_transmission_filter1",
|
|
2594
|
+
0x40000029: "id_transmission1",
|
|
2595
|
+
0x40000030: "id_transmission_filter2",
|
|
2596
|
+
0x40000031: "id_transmission2",
|
|
2597
|
+
0x40000032: "repeat_bleach",
|
|
2598
|
+
0x40000033: "enable_spot_bleach_pos",
|
|
2599
|
+
0x40000034: "spot_bleach_posx",
|
|
2600
|
+
0x40000035: "spot_bleach_posy",
|
|
2601
|
+
0x40000036: "spot_bleach_posz",
|
|
2602
|
+
0x40000037: "id_tubelens",
|
|
2603
|
+
0x40000038: "id_tubelens_position",
|
|
2604
|
+
0x40000039: "transmitted_light",
|
|
2605
|
+
0x4000003a: "reflected_light",
|
|
2606
|
+
0x4000003b: "simultan_grab_and_bleach",
|
|
2607
|
+
0x4000003c: "bleach_pixel_time",
|
|
2608
|
+
# detection_channels
|
|
2609
|
+
0x70000001: "integration_mode",
|
|
2610
|
+
0x70000002: "special_mode",
|
|
2611
|
+
0x70000003: "detector_gain_first",
|
|
2612
|
+
0x70000004: "detector_gain_last",
|
|
2613
|
+
0x70000005: "amplifier_gain_first",
|
|
2614
|
+
0x70000006: "amplifier_gain_last",
|
|
2615
|
+
0x70000007: "amplifier_offs_first",
|
|
2616
|
+
0x70000008: "amplifier_offs_last",
|
|
2617
|
+
0x70000009: "pinhole_diameter",
|
|
2618
|
+
0x7000000a: "counting_trigger",
|
|
2619
|
+
0x7000000b: "acquire",
|
|
2620
|
+
0x7000000c: "point_detector_name",
|
|
2621
|
+
0x7000000d: "amplifier_name",
|
|
2622
|
+
0x7000000e: "pinhole_name",
|
|
2623
|
+
0x7000000f: "filter_set_name",
|
|
2624
|
+
0x70000010: "filter_name",
|
|
2625
|
+
0x70000013: "integrator_name",
|
|
2626
|
+
0x70000014: "detection_channel_name",
|
|
2627
|
+
0x70000015: "detection_detector_gain_bc1",
|
|
2628
|
+
0x70000016: "detection_detector_gain_bc2",
|
|
2629
|
+
0x70000017: "detection_amplifier_gain_bc1",
|
|
2630
|
+
0x70000018: "detection_amplifier_gain_bc2",
|
|
2631
|
+
0x70000019: "detection_amplifier_offset_bc1",
|
|
2632
|
+
0x70000020: "detection_amplifier_offset_bc2",
|
|
2633
|
+
0x70000021: "detection_spectral_scan_channels",
|
|
2634
|
+
0x70000022: "detection_spi_wavelength_start",
|
|
2635
|
+
0x70000023: "detection_spi_wavelength_stop",
|
|
2636
|
+
0x70000026: "detection_dye_name",
|
|
2637
|
+
0x70000027: "detection_dye_folder",
|
|
2638
|
+
# illumination_channels
|
|
2639
|
+
0x90000001: "name",
|
|
2640
|
+
0x90000002: "power",
|
|
2641
|
+
0x90000003: "wavelength",
|
|
2642
|
+
0x90000004: "aquire",
|
|
2643
|
+
0x90000005: "detchannel_name",
|
|
2644
|
+
0x90000006: "power_bc1",
|
|
2645
|
+
0x90000007: "power_bc2",
|
|
2646
|
+
# beam_splitters
|
|
2647
|
+
0xb0000001: "filter_set",
|
|
2648
|
+
0xb0000002: "filter",
|
|
2649
|
+
0xb0000003: "name",
|
|
2650
|
+
# data_channels
|
|
2651
|
+
0xd0000001: "name",
|
|
2652
|
+
0xd0000003: "acquire",
|
|
2653
|
+
0xd0000004: "color",
|
|
2654
|
+
0xd0000005: "sample_type",
|
|
2655
|
+
0xd0000006: "bits_per_sample",
|
|
2656
|
+
0xd0000007: "ratio_type",
|
|
2657
|
+
0xd0000008: "ratio_track1",
|
|
2658
|
+
0xd0000009: "ratio_track2",
|
|
2659
|
+
0xd000000a: "ratio_channel1",
|
|
2660
|
+
0xd000000b: "ratio_channel2",
|
|
2661
|
+
0xd000000c: "ratio_const1",
|
|
2662
|
+
0xd000000d: "ratio_const2",
|
|
2663
|
+
0xd000000e: "ratio_const3",
|
|
2664
|
+
0xd000000f: "ratio_const4",
|
|
2665
|
+
0xd0000010: "ratio_const5",
|
|
2666
|
+
0xd0000011: "ratio_const6",
|
|
2667
|
+
0xd0000012: "ratio_first_images1",
|
|
2668
|
+
0xd0000013: "ratio_first_images2",
|
|
2669
|
+
0xd0000014: "dye_name",
|
|
2670
|
+
0xd0000015: "dye_folder",
|
|
2671
|
+
0xd0000016: "spectrum",
|
|
2672
|
+
0xd0000017: "acquire",
|
|
2673
|
+
# markers
|
|
2674
|
+
0x14000001: "name",
|
|
2675
|
+
0x14000002: "description",
|
|
2676
|
+
0x14000003: "trigger_in",
|
|
2677
|
+
0x14000004: "trigger_out",
|
|
2678
|
+
# timers
|
|
2679
|
+
0x12000001: "name",
|
|
2680
|
+
0x12000002: "description",
|
|
2681
|
+
0x12000003: "interval",
|
|
2682
|
+
0x12000004: "trigger_in",
|
|
2683
|
+
0x12000005: "trigger_out",
|
|
2684
|
+
0x12000006: "activation_time",
|
|
2685
|
+
0x12000007: "activation_number"}
|
|
2686
|
+
|
|
2687
|
+
# Map TIFF tag code to attribute name, default value, type, count, validator
|
|
2688
|
+
TIFF_TAGS = {
|
|
2689
|
+
254: ('new_subfile_type', 0, 4, 1, TIFF_SUBFILE_TYPES()),
|
|
2690
|
+
255: ('subfile_type', None, 3, 1,
|
|
2691
|
+
{0: 'undefined', 1: 'image', 2: 'reduced_image', 3: 'page'}),
|
|
2692
|
+
256: ('image_width', None, 4, 1, None),
|
|
2693
|
+
257: ('image_length', None, 4, 1, None),
|
|
2694
|
+
258: ('bits_per_sample', 1, 3, 1, None),
|
|
2695
|
+
259: ('compression', 1, 3, 1, TIFF_COMPESSIONS),
|
|
2696
|
+
262: ('photometric', None, 3, 1, TIFF_PHOTOMETRICS),
|
|
2697
|
+
266: ('fill_order', 1, 3, 1, {1: 'msb2lsb', 2: 'lsb2msb'}),
|
|
2698
|
+
269: ('document_name', None, 2, None, None),
|
|
2699
|
+
270: ('image_description', None, 2, None, None),
|
|
2700
|
+
271: ('make', None, 2, None, None),
|
|
2701
|
+
272: ('model', None, 2, None, None),
|
|
2702
|
+
273: ('strip_offsets', None, 4, None, None),
|
|
2703
|
+
274: ('orientation', 1, 3, 1, TIFF_ORIENTATIONS),
|
|
2704
|
+
277: ('samples_per_pixel', 1, 3, 1, None),
|
|
2705
|
+
278: ('rows_per_strip', 2**32-1, 4, 1, None),
|
|
2706
|
+
279: ('strip_byte_counts', None, 4, None, None),
|
|
2707
|
+
#280: ('min_sample_value', 0, 3, None, None),
|
|
2708
|
+
#281: ('max_sample_value', None, 3, None, None), # 2**bits_per_sample
|
|
2709
|
+
282: ('x_resolution', None, 5, 1, None),
|
|
2710
|
+
283: ('y_resolution', None, 5, 1, None),
|
|
2711
|
+
284: ('planar_configuration', 1, 3, 1, {1: 'contig', 2: 'separate'}),
|
|
2712
|
+
285: ('page_name', None, 2, None, None),
|
|
2713
|
+
296: ('resolution_unit', 2, 4, 1, {1: 'none', 2: 'inch', 3: 'centimeter'}),
|
|
2714
|
+
305: ('software', None, 2, None, None),
|
|
2715
|
+
306: ('datetime', None, 2, None, None),
|
|
2716
|
+
315: ('artist', None, 2, None, None),
|
|
2717
|
+
316: ('host_computer', None, 2, None, None),
|
|
2718
|
+
317: ('predictor', 1, 3, 1, {1: None, 2: 'horizontal'}),
|
|
2719
|
+
320: ('color_map', None, 3, None, None),
|
|
2720
|
+
322: ('tile_width', None, 4, 1, None),
|
|
2721
|
+
323: ('tile_length', None, 4, 1, None),
|
|
2722
|
+
324: ('tile_offsets', None, 4, None, None),
|
|
2723
|
+
325: ('tile_byte_counts', None, 4, None, None),
|
|
2724
|
+
338: ('extra_samples', None, 3, None,
|
|
2725
|
+
{0: 'unspecified', 1: 'assocalpha', 2: 'unassalpha'}),
|
|
2726
|
+
339: ('sample_format', 1, 3, 1, TIFF_SAMPLE_FORMATS),
|
|
2727
|
+
530: ('ycbcr_subsampling', 1, 3, 2, None),
|
|
2728
|
+
531: ('ycbcr_positioning', 1, 3, 1, None),
|
|
2729
|
+
#700: ('xmp', None, 1, None, None),
|
|
2730
|
+
33432: ('copyright', None, 1, None, None),
|
|
2731
|
+
32997: ('image_depth', None, 4, 1, None),
|
|
2732
|
+
32998: ('tile_depth', None, 4, 1, None),
|
|
2733
|
+
34665: ('exif_ifd', None, 4, 1, None)}
|
|
2734
|
+
|
|
2735
|
+
# Map custom TIFF tag codes to attribute names and import functions
|
|
2736
|
+
CUSTOM_TAGS = {
|
|
2737
|
+
33628: ('mm_uic1', read_mm_uic1),
|
|
2738
|
+
33629: ('mm_uic2', read_mm_uic2),
|
|
2739
|
+
33630: ('mm_uic3', read_mm_uic3),
|
|
2740
|
+
33631: ('mm_uic4', read_mm_uic4),
|
|
2741
|
+
34361: ('mm_header', read_mm_header),
|
|
2742
|
+
34362: ('mm_stamp', read_mm_stamp),
|
|
2743
|
+
34386: ('mm_user_block', None),
|
|
2744
|
+
34412: ('cz_lsm_info', read_cz_lsm_info),
|
|
2745
|
+
43314: ('nih_image_header', read_nih_image_header)}
|
|
2746
|
+
|
|
2747
|
+
# Max line length of printed output
|
|
2748
|
+
PRINT_LINE_LEN = 79
|
|
2749
|
+
|
|
2750
|
+
|
|
2751
|
+
def imshow(data, title=None, vmin=0, vmax=None, cmap=None,
|
|
2752
|
+
bitspersample=None, photometric='rgb', interpolation='nearest',
|
|
2753
|
+
dpi=96, figure=None, subplot=111, maxdim=4096, **kwargs):
|
|
2754
|
+
"""Plot n-dimensional images using matplotlib.pyplot.
|
|
2755
|
+
|
|
2756
|
+
Return figure, subplot and plot axis.
|
|
2757
|
+
Requires pyplot already imported ``from matplotlib import pyplot``.
|
|
2758
|
+
|
|
2759
|
+
Arguments
|
|
2760
|
+
---------
|
|
2761
|
+
|
|
2762
|
+
bitspersample : int or None
|
|
2763
|
+
Number of bits per channel in integer RGB images.
|
|
2764
|
+
|
|
2765
|
+
photometric : {'miniswhite', 'minisblack', 'rgb', or 'palette'}
|
|
2766
|
+
The color space of the image data.
|
|
2767
|
+
|
|
2768
|
+
title : str
|
|
2769
|
+
Window and subplot title.
|
|
2770
|
+
|
|
2771
|
+
figure : matplotlib.figure.Figure instance (optional).
|
|
2772
|
+
|
|
2773
|
+
subplot : int
|
|
2774
|
+
A matplotlib.pyplot.subplot axis.
|
|
2775
|
+
|
|
2776
|
+
maxdim : int
|
|
2777
|
+
maximum image size in any dimension.
|
|
2778
|
+
|
|
2779
|
+
kwargs : optional arguments for matplotlib.pyplot.imshow.
|
|
2780
|
+
|
|
2781
|
+
"""
|
|
2782
|
+
#if photometric not in ('miniswhite', 'minisblack', 'rgb', 'palette'):
|
|
2783
|
+
# raise ValueError("Can't handle %s photometrics" % photometric)
|
|
2784
|
+
isrgb = photometric in ('rgb', 'palette')
|
|
2785
|
+
data = numpy.atleast_2d(data.squeeze())
|
|
2786
|
+
data = data[(slice(0, maxdim), ) * len(data.shape)]
|
|
2787
|
+
|
|
2788
|
+
dims = data.ndim
|
|
2789
|
+
if dims < 2:
|
|
2790
|
+
raise ValueError("not an image")
|
|
2791
|
+
elif dims == 2:
|
|
2792
|
+
dims = 0
|
|
2793
|
+
isrgb = False
|
|
2794
|
+
else:
|
|
2795
|
+
if (isrgb and data.shape[-3] in (3, 4)):
|
|
2796
|
+
data = numpy.swapaxes(data, -3, -2)
|
|
2797
|
+
data = numpy.swapaxes(data, -2, -1)
|
|
2798
|
+
elif (not isrgb and data.shape[-1] in (3, 4)):
|
|
2799
|
+
data = numpy.swapaxes(data, -3, -1)
|
|
2800
|
+
data = numpy.swapaxes(data, -2, -1)
|
|
2801
|
+
isrgb = isrgb and data.shape[-1] in (3, 4)
|
|
2802
|
+
dims -= 3 if isrgb else 2
|
|
2803
|
+
|
|
2804
|
+
if photometric == 'palette':
|
|
2805
|
+
datamax = data.max()
|
|
2806
|
+
if datamax > 255:
|
|
2807
|
+
data >>= 8 # possible precision loss
|
|
2808
|
+
data = data.astype('B')
|
|
2809
|
+
elif data.dtype.kind in 'ui':
|
|
2810
|
+
if not isrgb or bitspersample is None:
|
|
2811
|
+
bitspersample = int(math.ceil(math.log(data.max(), 2)))
|
|
2812
|
+
elif not isinstance(bitspersample, int):
|
|
2813
|
+
# bitspersample can be tuple, e.g. (5, 6, 5)
|
|
2814
|
+
bitspersample = data.dtype.itemsize * 8
|
|
2815
|
+
datamax = 2**bitspersample
|
|
2816
|
+
if isrgb:
|
|
2817
|
+
if bitspersample < 8:
|
|
2818
|
+
data <<= 8 - bitspersample
|
|
2819
|
+
elif bitspersample > 8:
|
|
2820
|
+
data >>= bitspersample - 8 # precision loss
|
|
2821
|
+
data = data.astype('B')
|
|
2822
|
+
elif data.dtype.kind == 'f':
|
|
2823
|
+
datamax = data.max()
|
|
2824
|
+
if isrgb and datamax > 1.0:
|
|
2825
|
+
if data.dtype.char == 'd':
|
|
2826
|
+
data = data.astype('f')
|
|
2827
|
+
data /= datamax
|
|
2828
|
+
elif data.dtype.kind == 'b':
|
|
2829
|
+
datamax = 1
|
|
2830
|
+
|
|
2831
|
+
if vmax is None:
|
|
2832
|
+
vmax = datamax
|
|
2833
|
+
if vmin is None:
|
|
2834
|
+
if data.dtype.kind != 'f':
|
|
2835
|
+
vmin = 0
|
|
2836
|
+
|
|
2837
|
+
pyplot = sys.modules['matplotlib.pyplot']
|
|
2838
|
+
|
|
2839
|
+
if figure is None:
|
|
2840
|
+
pyplot.rc('font', family='sans-serif', weight='normal', size=8)
|
|
2841
|
+
figure = pyplot.figure(dpi=dpi, figsize=(10.3, 6.3), frameon=True,
|
|
2842
|
+
facecolor='1.0', edgecolor='w')
|
|
2843
|
+
try:
|
|
2844
|
+
figure.canvas.manager.window.title(title)
|
|
2845
|
+
except Exception:
|
|
2846
|
+
pass
|
|
2847
|
+
pyplot.subplots_adjust(bottom=0.03*(dims+2), top=0.9,
|
|
2848
|
+
left=0.1, right=0.95, hspace=0.05, wspace=0.0)
|
|
2849
|
+
subplot = pyplot.subplot(subplot)
|
|
2850
|
+
|
|
2851
|
+
if title:
|
|
2852
|
+
pyplot.title(title, size=11)
|
|
2853
|
+
|
|
2854
|
+
if cmap is None:
|
|
2855
|
+
if photometric == 'miniswhite':
|
|
2856
|
+
cmap = pyplot.cm.gray_r
|
|
2857
|
+
else:
|
|
2858
|
+
cmap = pyplot.cm.gray
|
|
2859
|
+
|
|
2860
|
+
image = pyplot.imshow(data[(0, ) * dims].squeeze(), vmin=vmin, vmax=vmax,
|
|
2861
|
+
cmap=cmap, interpolation=interpolation, **kwargs)
|
|
2862
|
+
|
|
2863
|
+
if not isrgb:
|
|
2864
|
+
pyplot.colorbar() # panchor=(0.55, 0.5), fraction=0.05
|
|
2865
|
+
|
|
2866
|
+
def format_coord(x, y):
|
|
2867
|
+
# callback function to format coordinate display in toolbar
|
|
2868
|
+
x = int(x + 0.5)
|
|
2869
|
+
y = int(y + 0.5)
|
|
2870
|
+
try:
|
|
2871
|
+
if dims:
|
|
2872
|
+
return "%s @ %s [%4i, %4i]" % (cur_ax_dat[1][y, x],
|
|
2873
|
+
current, x, y)
|
|
2874
|
+
else:
|
|
2875
|
+
return "%s @ [%4i, %4i]" % (data[y, x], x, y)
|
|
2876
|
+
except IndexError:
|
|
2877
|
+
return ""
|
|
2878
|
+
|
|
2879
|
+
pyplot.gca().format_coord = format_coord
|
|
2880
|
+
|
|
2881
|
+
if dims:
|
|
2882
|
+
current = list((0, ) * dims)
|
|
2883
|
+
cur_ax_dat = [0, data[tuple(current)].squeeze()]
|
|
2884
|
+
sliders = [pyplot.Slider(
|
|
2885
|
+
pyplot.axes([0.125, 0.03*(axis+1), 0.725, 0.025]),
|
|
2886
|
+
'Dimension %i' % axis, 0, data.shape[axis]-1, 0, facecolor='0.5',
|
|
2887
|
+
valfmt='%%.0f [%i]' % data.shape[axis]) for axis in range(dims)]
|
|
2888
|
+
for slider in sliders:
|
|
2889
|
+
slider.drawon = False
|
|
2890
|
+
|
|
2891
|
+
def set_image(current, sliders=sliders, data=data):
|
|
2892
|
+
# change image and redraw canvas
|
|
2893
|
+
cur_ax_dat[1] = data[tuple(current)].squeeze()
|
|
2894
|
+
image.set_data(cur_ax_dat[1])
|
|
2895
|
+
for ctrl, index in zip(sliders, current):
|
|
2896
|
+
ctrl.eventson = False
|
|
2897
|
+
ctrl.set_val(index)
|
|
2898
|
+
ctrl.eventson = True
|
|
2899
|
+
figure.canvas.draw()
|
|
2900
|
+
|
|
2901
|
+
def on_changed(index, axis, data=data, current=current):
|
|
2902
|
+
# callback function for slider change event
|
|
2903
|
+
index = int(round(index))
|
|
2904
|
+
cur_ax_dat[0] = axis
|
|
2905
|
+
if index == current[axis]:
|
|
2906
|
+
return
|
|
2907
|
+
if index >= data.shape[axis]:
|
|
2908
|
+
index = 0
|
|
2909
|
+
elif index < 0:
|
|
2910
|
+
index = data.shape[axis] - 1
|
|
2911
|
+
current[axis] = index
|
|
2912
|
+
set_image(current)
|
|
2913
|
+
|
|
2914
|
+
def on_keypressed(event, data=data, current=current):
|
|
2915
|
+
# callback function for key press event
|
|
2916
|
+
key = event.key
|
|
2917
|
+
axis = cur_ax_dat[0]
|
|
2918
|
+
if str(key) in '0123456789':
|
|
2919
|
+
on_changed(key, axis)
|
|
2920
|
+
elif key == 'right':
|
|
2921
|
+
on_changed(current[axis] + 1, axis)
|
|
2922
|
+
elif key == 'left':
|
|
2923
|
+
on_changed(current[axis] - 1, axis)
|
|
2924
|
+
elif key == 'up':
|
|
2925
|
+
cur_ax_dat[0] = 0 if axis == len(data.shape)-1 else axis + 1
|
|
2926
|
+
elif key == 'down':
|
|
2927
|
+
cur_ax_dat[0] = len(data.shape)-1 if axis == 0 else axis - 1
|
|
2928
|
+
elif key == 'end':
|
|
2929
|
+
on_changed(data.shape[axis] - 1, axis)
|
|
2930
|
+
elif key == 'home':
|
|
2931
|
+
on_changed(0, axis)
|
|
2932
|
+
|
|
2933
|
+
figure.canvas.mpl_connect('key_press_event', on_keypressed)
|
|
2934
|
+
for axis, ctrl in enumerate(sliders):
|
|
2935
|
+
ctrl.on_changed(lambda k, a=axis: on_changed(k, a))
|
|
2936
|
+
|
|
2937
|
+
return figure, subplot, image
|
|
2938
|
+
|
|
2939
|
+
|
|
2940
|
+
def _app_show():
|
|
2941
|
+
"""Block the GUI. For use as skimage plugin."""
|
|
2942
|
+
pyplot = sys.modules['matplotlib.pyplot']
|
|
2943
|
+
pyplot.show()
|
|
2944
|
+
|
|
2945
|
+
|
|
2946
|
+
def main(argv=None):
|
|
2947
|
+
"""Command line usage main function."""
|
|
2948
|
+
if float(sys.version[0:3]) < 2.6:
|
|
2949
|
+
print("This script requires Python version 2.6 or better.")
|
|
2950
|
+
print("This is Python version %s" % sys.version)
|
|
2951
|
+
return 0
|
|
2952
|
+
if argv is None:
|
|
2953
|
+
argv = sys.argv
|
|
2954
|
+
|
|
2955
|
+
import re
|
|
2956
|
+
import optparse
|
|
2957
|
+
|
|
2958
|
+
search_doc = lambda r, d: re.search(r, __doc__).group(1) if __doc__ else d
|
|
2959
|
+
parser = optparse.OptionParser(
|
|
2960
|
+
usage="usage: %prog [options] path",
|
|
2961
|
+
description=search_doc("\n\n([^|]*?)\n\n", ''),
|
|
2962
|
+
version="%%prog %s" % search_doc(":Version: (.*)", "Unknown"))
|
|
2963
|
+
opt = parser.add_option
|
|
2964
|
+
opt('-p', '--page', dest='page', type='int', default=-1,
|
|
2965
|
+
help="display single page")
|
|
2966
|
+
opt('-s', '--series', dest='series', type='int', default=-1,
|
|
2967
|
+
help="display series of pages of same shape")
|
|
2968
|
+
opt('--noplot', dest='noplot', action='store_true', default=False,
|
|
2969
|
+
help="don't display images")
|
|
2970
|
+
opt('--interpol', dest='interpol', metavar='INTERPOL', default='bilinear',
|
|
2971
|
+
help="image interpolation method")
|
|
2972
|
+
opt('--dpi', dest='dpi', type='int', default=96,
|
|
2973
|
+
help="set plot resolution")
|
|
2974
|
+
opt('--debug', dest='debug', action='store_true', default=False,
|
|
2975
|
+
help="raise exception on failures")
|
|
2976
|
+
opt('--test', dest='test', action='store_true', default=False,
|
|
2977
|
+
help="try read all images in path")
|
|
2978
|
+
opt('--doctest', dest='doctest', action='store_true', default=False,
|
|
2979
|
+
help="runs the internal tests")
|
|
2980
|
+
opt('-v', '--verbose', dest='verbose', action='store_true', default=True)
|
|
2981
|
+
opt('-q', '--quiet', dest='verbose', action='store_false')
|
|
2982
|
+
|
|
2983
|
+
settings, path = parser.parse_args()
|
|
2984
|
+
path = ' '.join(path)
|
|
2985
|
+
|
|
2986
|
+
if settings.doctest:
|
|
2987
|
+
import doctest
|
|
2988
|
+
doctest.testmod()
|
|
2989
|
+
return 0
|
|
2990
|
+
if not path:
|
|
2991
|
+
parser.error("No file specified")
|
|
2992
|
+
if settings.test:
|
|
2993
|
+
test_tifffile(path, settings.verbose)
|
|
2994
|
+
return 0
|
|
2995
|
+
|
|
2996
|
+
print("Reading file structure...", end=' ')
|
|
2997
|
+
start = time.time()
|
|
2998
|
+
try:
|
|
2999
|
+
tif = TIFFfile(path)
|
|
3000
|
+
except Exception as e:
|
|
3001
|
+
if settings.debug:
|
|
3002
|
+
raise
|
|
3003
|
+
else:
|
|
3004
|
+
print("\n", e)
|
|
3005
|
+
sys.exit(0)
|
|
3006
|
+
print("%.3f ms" % ((time.time()-start) * 1e3))
|
|
3007
|
+
|
|
3008
|
+
if tif.is_ome:
|
|
3009
|
+
settings.norgb = True
|
|
3010
|
+
|
|
3011
|
+
images = [(None, tif[0 if settings.page < 0 else settings.page])]
|
|
3012
|
+
if not settings.noplot:
|
|
3013
|
+
print("Reading image data... ", end=' ')
|
|
3014
|
+
notnone = lambda x: next(i for i in x if i is not None)
|
|
3015
|
+
start = time.time()
|
|
3016
|
+
try:
|
|
3017
|
+
if settings.page >= 0:
|
|
3018
|
+
images = [(tif.asarray(key=settings.page),
|
|
3019
|
+
tif[settings.page])]
|
|
3020
|
+
elif settings.series >= 0:
|
|
3021
|
+
images = [(tif.asarray(series=settings.series),
|
|
3022
|
+
notnone(tif.series[settings.series].pages))]
|
|
3023
|
+
else:
|
|
3024
|
+
images = []
|
|
3025
|
+
for i, s in enumerate(tif.series):
|
|
3026
|
+
try:
|
|
3027
|
+
images.append(
|
|
3028
|
+
(tif.asarray(series=i), notnone(s.pages)))
|
|
3029
|
+
except ValueError as e:
|
|
3030
|
+
images.append((None, notnone(s.pages)))
|
|
3031
|
+
if settings.debug:
|
|
3032
|
+
raise
|
|
3033
|
+
else:
|
|
3034
|
+
print("\n* series %i failed: %s... " % (i, e),
|
|
3035
|
+
end='')
|
|
3036
|
+
print("%.3f ms" % ((time.time()-start) * 1e3))
|
|
3037
|
+
except Exception as e:
|
|
3038
|
+
if settings.debug:
|
|
3039
|
+
raise
|
|
3040
|
+
else:
|
|
3041
|
+
print(e)
|
|
3042
|
+
tif.close()
|
|
3043
|
+
|
|
3044
|
+
print("\nTIFF file:", tif)
|
|
3045
|
+
print()
|
|
3046
|
+
for i, s in enumerate(tif.series):
|
|
3047
|
+
print("Series %i" % i)
|
|
3048
|
+
print(s)
|
|
3049
|
+
print()
|
|
3050
|
+
for i, page in images:
|
|
3051
|
+
print(page)
|
|
3052
|
+
print(page.tags)
|
|
3053
|
+
if page.is_palette:
|
|
3054
|
+
print("\nColor Map:", page.color_map.shape, page.color_map.dtype)
|
|
3055
|
+
for attr in ('cz_lsm_info', 'cz_lsm_scan_information',
|
|
3056
|
+
'mm_uic_tags', 'mm_header', 'nih_image_header'):
|
|
3057
|
+
if hasattr(page, attr):
|
|
3058
|
+
print("", attr.upper(), Record(getattr(page, attr)), sep="\n")
|
|
3059
|
+
print()
|
|
3060
|
+
|
|
3061
|
+
if images and not settings.noplot:
|
|
3062
|
+
try:
|
|
3063
|
+
import matplotlib
|
|
3064
|
+
matplotlib.use('TkAgg')
|
|
3065
|
+
from matplotlib import pyplot
|
|
3066
|
+
except ImportError as e:
|
|
3067
|
+
warnings.warn("failed to import matplotlib.\n%s" % e)
|
|
3068
|
+
else:
|
|
3069
|
+
for img, page in images:
|
|
3070
|
+
if img is None:
|
|
3071
|
+
continue
|
|
3072
|
+
vmin, vmax = None, None
|
|
3073
|
+
if page.is_stk:
|
|
3074
|
+
try:
|
|
3075
|
+
vmin = page.mm_uic_tags['min_scale']
|
|
3076
|
+
vmax = page.mm_uic_tags['max_scale']
|
|
3077
|
+
except KeyError:
|
|
3078
|
+
pass
|
|
3079
|
+
else:
|
|
3080
|
+
if vmax <= vmin:
|
|
3081
|
+
vmin, vmax = None, None
|
|
3082
|
+
title = "%s\n %s" % (str(tif), str(page))
|
|
3083
|
+
imshow(img, title=title, vmin=vmin, vmax=vmax,
|
|
3084
|
+
bitspersample=page.bits_per_sample,
|
|
3085
|
+
photometric=page.photometric,
|
|
3086
|
+
interpolation=settings.interpol,
|
|
3087
|
+
dpi=settings.dpi)
|
|
3088
|
+
pyplot.show()
|
|
3089
|
+
|
|
3090
|
+
|
|
3091
|
+
__version__ = '2012.04.21'
|
|
3092
|
+
__docformat__ = 'restructuredtext en'
|
|
3093
|
+
|
|
3094
|
+
if __name__ == "__main__":
|
|
3095
|
+
sys.exit(main())
|