def OnUnmixMax(self, event): #unmix and take brightest channel #from PYME.Analysis import deTile from PYME.DSView import ViewIm3D, ImageStack usds = self._getUSDataSources() fns = os.path.split(self.image.filename)[1] zm = usds[0].shape[2] / 2 maxs = [u[:, :, zm].max() for u in usds] im = ImageStack(usds[np.argmax(maxs)], titleStub='%s - unsplit' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
def OnUnmix(self, event): #from PYME.Analysis import deTile from PYME.DSView import ViewIm3D, ImageStack usds = self._getUSDataSources() fns = os.path.split(self.image.filename)[1] im = ImageStack(usds, titleStub='%s - unsplit' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename # grab events from the first data source TODO - do this need to be smarter? try: im.events = usds[0].getEvents() except: logger.warning('No Events found when coalescing UnsplitDataSource') if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' print(im.data[:, :, 1, 1].shape) dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
def OnApplyShiftmap(self, event): """apply a vectorial correction for chromatic shift to an image - this is a generic vectorial shift compensation, rather than the secial case correction used with the splitter.""" from scipy import ndimage import numpy as np from PYME.DSView import ImageStack, ViewIm3D from PYME.IO.MetaDataHandler import get_camera_roi_origin dlg = ShiftmapSelectionDialog(self.dsviewer, self.image) succ = dlg.ShowModal() if (succ == wx.ID_OK): #self.ds = example.CDataStack(fdialog.GetPath().encode()) #self.ds = ds = [] shiftFiles = {} X, Y, Z = np.mgrid[0:self.image.data.shape[0], 0:self.image.data.shape[1], 0:self.image.data.shape[2]] vx, vy, vz = self.image.voxelsize_nm roi_x0, roi_y0 = get_camera_roi_origin(self.image.mdh) for ch in range(self.image.data.shape[3]): sfFilename = dlg.GetChanFilename(ch) shiftFiles[ch] = sfFilename data = self.image.data[:,:,:, ch] if os.path.exists(sfFilename): spx, spy, dz = np.load(sfFilename) dx = spx.ev(vx*(X+roi_x0), vy*(Y+roi_y0))/vx dy = spy.ev(vx*(X+roi_x0), vy*(Y+roi_y0))/vy dz = dz/vz ds.append(ndimage.map_coordinates(data, [X+dx, Y+dy, Z+dz], mode='nearest')) else: ds.append(data) fns = os.path.split(self.image.filename)[1] im = ImageStack(ds, titleStub = '%s - corrected' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename im.mdh.setEntry('ChromaCorrection.ShiftFilenames', shiftFiles) if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer)) dlg.Destroy()
def OnUnmixMax(self, event): #unmix and take brightest channel #from PYME.Analysis import deTile from PYME.DSView import ViewIm3D, ImageStack mdh = self.image.mdh if 'chroma.dx' in mdh.getEntryNames(): sf = (mdh['chroma.dx'], mdh['chroma.dy']) elif global_shiftfield: sf = global_shiftfield else: #self.OnSetShiftField() #sf = (mdh['chroma.dx'], mdh['chroma.dy']) sf = None flip = True if 'Splitter.Flip' in mdh.getEntryNames() and not mdh['Splitter.Flip']: flip = False ROIX1 = mdh.getEntry('Camera.ROIPosX') ROIY1 = mdh.getEntry('Camera.ROIPosY') ROIX2 = ROIX1 + mdh.getEntry('Camera.ROIWidth') ROIY2 = ROIY1 + mdh.getEntry('Camera.ROIHeight') um0 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 0, flip, sf) um1 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 1, flip, sf) fns = os.path.split(self.image.filename)[1] zm = um0.shape[2] / 2 if um0[:, :, zm].max() > um1[:, :, zm].max(): im = ImageStack(um0, titleStub='%s - unsplit' % fns) else: im = ImageStack(um1, titleStub='%s - unsplit' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
def OnUnmixMax(self, event): #unmix and take brightest channel #from PYME.Analysis import deTile from PYME.DSView import ViewIm3D, ImageStack mdh = self.image.mdh if 'chroma.dx' in mdh.getEntryNames(): sf = (mdh['chroma.dx'], mdh['chroma.dy']) elif global_shiftfield: sf = global_shiftfield else: #self.OnSetShiftField() #sf = (mdh['chroma.dx'], mdh['chroma.dy']) sf = None flip = True if 'Splitter.Flip' in mdh.getEntryNames() and not mdh['Splitter.Flip']: flip = False ROIX1 = mdh.getEntry('Camera.ROIPosX') ROIY1 = mdh.getEntry('Camera.ROIPosY') ROIX2 = ROIX1 + mdh.getEntry('Camera.ROIWidth') ROIY2 = ROIY1 + mdh.getEntry('Camera.ROIHeight') um0 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 0, flip, sf) um1 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 1 , flip, sf) fns = os.path.split(self.image.filename)[1] zm = um0.shape[2]/2 if um0[:,:,zm].max() > um1[:,:,zm].max(): im = ImageStack(um0, titleStub = '%s - unsplit' % fns) else: im = ImageStack(um1, titleStub = '%s - unsplit' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
def OnUnmix(self, event): #from PYME.Analysis import deTile from PYME.DSView import ViewIm3D, ImageStack mdh = self.image.mdh if 'chroma.dx' in mdh.getEntryNames(): sf = (mdh['chroma.dx'], mdh['chroma.dy']) elif global_shiftfield: sf = global_shiftfield else: sf = None flip = True if 'Splitter.Flip' in mdh.getEntryNames() and not mdh['Splitter.Flip']: flip = False chanROIs = None if 'Splitter.Channel0ROI' in mdh.getEntryNames(): chanROIs = [mdh['Splitter.Channel0ROI'],mdh['Splitter.Channel1ROI']] ROIX1 = mdh.getEntry('Camera.ROIPosX') ROIY1 = mdh.getEntry('Camera.ROIPosY') ROIX2 = ROIX1 + mdh.getEntry('Camera.ROIWidth') ROIY2 = ROIY1 + mdh.getEntry('Camera.ROIHeight') um0 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 0, flip, sf, chanROIs=chanROIs, voxelsize=self.image.voxelsize) um1 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 1 , flip, sf, chanROIs=chanROIs, voxelsize=self.image.voxelsize) fns = os.path.split(self.image.filename)[1] im = ImageStack([um0, um1], titleStub = '%s - unsplit' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' #print im.data[:,:,1,1].shape dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
def OnUnmix(self, event): #from PYME.Analysis import deTile from PYME.DSView import ViewIm3D, ImageStack mdh = self.image.mdh if 'chroma.dx' in mdh.getEntryNames(): sf = (mdh['chroma.dx'], mdh['chroma.dy']) elif global_shiftfield: sf = global_shiftfield else: sf = None flip = True if 'Splitter.Flip' in mdh.getEntryNames() and not mdh['Splitter.Flip']: flip = False chanROIs = None if 'Splitter.Channel0ROI' in mdh.getEntryNames(): chanROIs = [ mdh['Splitter.Channel0ROI'], mdh['Splitter.Channel1ROI'] ] ROIX1 = mdh.getEntry('Camera.ROIPosX') ROIY1 = mdh.getEntry('Camera.ROIPosY') ROIX2 = ROIX1 + mdh.getEntry('Camera.ROIWidth') ROIY2 = ROIY1 + mdh.getEntry('Camera.ROIHeight') um0 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 0, flip, sf, chanROIs=chanROIs, voxelsize=self.image.voxelsize) um1 = UnsplitDataSource.DataSource(self.image.data, [ROIX1, ROIY1, ROIX2, ROIY2], 1, flip, sf, chanROIs=chanROIs, voxelsize=self.image.voxelsize) fns = os.path.split(self.image.filename)[1] im = ImageStack([um0, um1], titleStub='%s - unsplit' % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh['Parent'] = self.image.filename if 'fitResults' in dir(self.image): im.fitResults = self.image.fitResults #im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == 'visGUI': mode = 'visGUI' else: mode = 'lite' #print im.data[:,:,1,1].shape dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
def OnApplyShiftmap(self, event): """apply a vectorial correction for chromatic shift to an image - this is a generic vectorial shift compensation, rather than the secial case correction used with the splitter.""" from scipy import ndimage import numpy as np from PYME.DSView import ImageStack, ViewIm3D dlg = ShiftmapSelectionDialog(self.dsviewer, self.image) succ = dlg.ShowModal() if succ == wx.ID_OK: # self.ds = example.CDataStack(fdialog.GetPath().encode()) # self.ds = ds = [] shiftFiles = {} X, Y, Z = np.mgrid[0 : self.image.data.shape[0], 0 : self.image.data.shape[1], 0 : self.image.data.shape[2]] vx = self.image.mdh["voxelsize.x"] * 1e3 vy = self.image.mdh["voxelsize.y"] * 1e3 vz = self.image.mdh["voxelsize.z"] * 1e3 x0 = 1 y0 = 1 if "Camera.ROIPosX" in self.image.mdh.getEntryNames(): x0 = self.image.mdh["Camera.ROIPosX"] y0 = self.image.mdh["Camera.ROIPosY"] for ch in range(self.image.data.shape[3]): sfFilename = dlg.GetChanFilename(ch) shiftFiles[ch] = sfFilename data = self.image.data[:, :, :, ch] if os.path.exists(sfFilename): spx, spy, dz = np.load(sfFilename) dx = spx.ev(vx * (X + x0 - 1), vy * (Y + y0 - 1)) / vx dy = spy.ev(vx * (X + x0 - 1), vy * (Y + y0 - 1)) / vy dz = dz / vz ds.append(ndimage.map_coordinates(data, [X + dx, Y + dy, Z + dz], mode="nearest")) else: ds.append(data) fns = os.path.split(self.image.filename)[1] im = ImageStack(ds, titleStub="%s - corrected" % fns) im.mdh.copyEntriesFrom(self.image.mdh) im.mdh["Parent"] = self.image.filename im.mdh.setEntry("ChromaCorrection.ShiftFilenames", shiftFiles) if "fitResults" in dir(self.image): im.fitResults = self.image.fitResults # im.mdh['Processing.GaussianFilter'] = sigmas if self.dsviewer.mode == "visGUI": mode = "visGUI" else: mode = "lite" dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer)) dlg.Destroy()