Beispiel #1
0
    def Project(self, projType):
        import numpy as np
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D
        import os

        if projType == 'mean':        
            filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].mean(2)) for chanNum in range(self.image.data.shape[3])]
        elif projType == 'max':
            filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].max(2)) for chanNum in range(self.image.data.shape[3])]

        fns = os.path.split(self.image.filename)[1]        
        
        im = ImageStack(filt_ims, titleStub = '%s - %s' %(fns, projType))
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        im.mdh['Processing.Projection'] = projType

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        else:
            mode = 'lite'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas)

        #set scaling to (0,1)
        for i in range(im.data.shape[3]):
            dv.do.Gains[i] = 1.0
Beispiel #2
0
    def OnExtractPupil(self, event):
        import numpy as np
        import pylab
        from PYME.PSFGen import fourierHNA
        
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        z_ = np.arange(self.image.data.shape[2])*self.image.mdh['voxelsize.z']*1.e3
        z_ -= z_.mean()  
        
        self.configure_traits(kind='modal')
        
        pupil = fourierHNA.ExtractPupil(np.maximum(self.image.data[:,:,:] - .001, 0), z_, self.image.mdh['voxelsize.x']*1e3, self.wavelength, self.NA, nIters=self.iterations, size=self.pupilSize)
        
        pylab.figure()
        pylab.subplot(121)
        pylab.imshow(np.abs(pupil), interpolation='nearest')
        pylab.subplot(122)
        pylab.imshow(np.angle(pupil)*(np.abs(pupil) > 0), interpolation='nearest')
        
        pupil = pupil*(np.abs(pupil) > 0)
        
        #im = ImageStack([np.abs(pupil), np.angle(pupil)*(np.abs(pupil) > 0)], titleStub = 'Extracted Pupil')
        im = ImageStack(pupil, titleStub = 'Extracted Pupil')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        #im.mdh['Processing.CropROI'] = roi
        mode = 'pupil'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
Beispiel #3
0
    def OnSegmentAnneal(self, event):
        newImages = [np.zeros(self.image.data.shape[:3], "b") for i in range(self.image.data.shape[3])]

        im = ImageStack(newImages)
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh["Parent"] = self.image.filename

        if self.dsviewer.mode == "visGUI":
            mode = "visGUI"
        else:
            mode = "lite"

        self.res = ViewIm3D(im, parent=wx.GetTopLevelParent(self.dsviewer), mode=mode, glCanvas=self.dsviewer.glCanvas)

        self.panAnneal = SegmentationPanel(self.res, self.image, newImages)

        self.pinfo1 = (
            aui.AuiPaneInfo()
            .Name("annealPanel")
            .Left()
            .Caption("Segmentation")
            .DestroyOnClose(True)
            .CloseButton(False)
            .MinimizeButton(True)
            .MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART | aui.AUI_MINIMIZE_POS_RIGHT)
        )  # .MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
        self.res._mgr.AddPane(self.panAnneal, self.pinfo1)
        self.res._mgr.Update()
Beispiel #4
0
    def OnApplyThreshold(self, event):
        import numpy as np
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

       
        filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].squeeze() > self.dsviewer.do.thresholds[chanNum]) for chanNum in range(self.image.data.shape[3])]
        

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        elif self.dsviewer.mode == 'graph':
            mode = 'graph'
            filt_ims = [fi.squeeze() for fi in filt_ims]
        else:
            mode = 'lite'
            
        im = ImageStack(sum(filt_ims) > 0.5, titleStub = 'Thresholded Image')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))

        #set scaling to (0,1)
        for i in range(im.data.shape[3]):
            dv.do.Gains[i] = 1.0
Beispiel #5
0
    def OnLabel(self, event):
        import numpy as np
        from scipy import ndimage
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].squeeze() > self.dsviewer.do.thresholds[chanNum]) for chanNum in range(self.image.data.shape[3])]

        #print sum(filt_ims).shape
        mask = sum(filt_ims) > 0.5
        labs, nlabs = ndimage.label(mask)

        im = ImageStack(labs, titleStub = 'Thresholded Image')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        #im.mdh['Processing.CropROI'] = roi

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        else:
            mode = 'lite'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))

        #set scaling to (0,1)
        for i in range(im.data.shape[3]):
            dv.do.Gains[i] = 1.0
Beispiel #6
0
    def OnPSFFromPupil(self, event):
        import numpy as np
        #import pylab
        from PYME.PSFGen import fourierHNA

        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        self.configure_traits(kind='modal')

        z_ = np.arange(self.sizeZ) * float(self.zSpacing)
        z_ -= z_.mean()

        ps = fourierHNA.PsfFromPupil(
            self.image.data[:, :], z_, self.image.mdh['voxelsize.x'] * 1e3,
            self.wavelength)  #, shape = [self.sizeX, self.sizeX])

        ps = ps / ps[:, :, self.sizeZ / 2].sum()

        im = ImageStack(ps, titleStub='Generated PSF')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        #im.mdh['Processing.CropROI'] = roi
        mode = 'psf'

        dv = ViewIm3D(im,
                      mode=mode,
                      glCanvas=self.dsviewer.glCanvas,
                      parent=wx.GetTopLevelParent(self.dsviewer))
Beispiel #7
0
    def OnGaussianFilter(self, event):
        import numpy as np
        from scipy.ndimage import gaussian_filter
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        dlg = wx.TextEntryDialog(self.dsviewer, 'Blur size [pixels]:', 'Gaussian Blur', '[1,1,1]')

        if dlg.ShowModal() == wx.ID_OK:
            sigmas = eval(dlg.GetValue())
            #print sigmas
            #print self.images[0].img.shape
            filt_ims = [np.atleast_3d(gaussian_filter(self.image.data[:,:,:,chanNum].squeeze(), sigmas)) for chanNum in range(self.image.data.shape[3])]
            
            im = ImageStack(filt_ims, titleStub = 'Filtered Image')
            im.mdh.copyEntriesFrom(self.image.mdh)
            im.mdh['Parent'] = self.image.filename
            im.mdh['Processing.GaussianFilter'] = sigmas

            if self.dsviewer.mode == 'visGUI':
                mode = 'visGUI'
            else:
                mode = 'lite'

            dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas)

            #set scaling to (0,1)
            for i in range(im.data.shape[3]):
                dv.do.Gains[i] = 1.0

            

        dlg.Destroy()
Beispiel #8
0
    def OnSubtractBackground(self, event):
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D
        from PYME.PSFEst import extractImages

        d_bg = extractImages.backgroundCorrectPSFWF(self.image.data[:,:,:])
        
        
        
        im = ImageStack(d_bg, titleStub = 'Filtered Image')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        
        dv = ViewIm3D(im, mode='psf', glCanvas=self.dsviewer.glCanvas)
Beispiel #9
0
 def filter(self, image):
     if self.processFramesIndividually:
         filt_ims = []
         for chanNum in range(image.data.shape[3]):
             filt_ims.append(np.concatenate([np.atleast_3d(self.applyFilter(image.data[:,:,i,chanNum].squeeze().astype('f'), chanNum, i, image)) for i in range(image.data.shape[2])], 2))
     else:
         filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
         
     im = ImageStack(filt_ims, titleStub = self.outputName)
     im.mdh.copyEntriesFrom(image.mdh)
     im.mdh['Parent'] = image.filename
     
     self.completeMetadata(im)
     
     return im
Beispiel #10
0
    def OnDiagSplit(self, event):
        import numpy as np
        #from scipy.ndimage import gaussian_filter
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        #dlg = wx.TextEntryDialog(self.dsviewer, 'Blur size [pixels]:', 'Gaussian Blur', '[1,1,1]')

        #if dlg.ShowModal() == wx.ID_OK:
            #sigmas = eval(dlg.GetValue())
            #print sigmas
            #print self.images[0].img.shape

        x0, x1, y0, y1 = [self.do.selection_begin_x, self.do.selection_end_x, self.do.selection_begin_y, self.do.selection_end_y]
        
        dx = x1 - x0
        dy = y1 - y0
        
        m = dy/dx
        c = y0 - m*x0
        
        d = self.image.data
        
        X, Y = np.ogrid[:d.shape[0], :d.shape[1]]
        
        msk = Y > (m*X + c)

        #filt_ims = [np.atleast_3d(self.image.data[roi[0][0]:roi[0][1],roi[1][0]:roi[1][1],:,chanNum].squeeze()) for chanNum in range(self.image.data.shape[3])]
        imn = (d[:,:,:, 0] - self.do.Offs[0])*self.do.Gains[0]*msk[:,:, None] + (d[:,:,:,1]- self.do.Offs[1])*self.do.Gains[1]*(1-msk)[:,:,None]

        im = ImageStack(imn, titleStub = 'Cropped Image')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        #im.mdh['Processing.CropROI'] = roi

          

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        else:
            mode = 'lite'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))

        #set scaling to (0,1)
        for i in range(im.data.shape[3]):
            dv.do.Gains[i] = 1.0
Beispiel #11
0
def loadInput(filename):
    '''Load input data from a file
    
    Currently only handles images (anything you can open in dh5view). TODO - 
    extend to other types.
    '''
    #modify this to allow for different file types - currently only supports images
    return ImageStack(filename=filename, haveGUI=False)
Beispiel #12
0
def View3D(data, titleStub='Untitled Image', mdh = None, mode='lite', 
           parent=None, glCanvas=None):
    im = ImageStack(data = data, mdh = mdh, titleStub=titleStub)
    dvf = DSViewFrame(im, mode=mode, size=(500, 500), 
                      parent=parent, glCanvas=glCanvas)
    dvf.SetSize((500,500))
    dvf.Show()
    return dvf
Beispiel #13
0
    def OnGaussianFilter(self, event):
        import numpy as np
        from scipy.ndimage import gaussian_filter1d, convolve1d
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        #dlg = wx.TextEntryDialog(self.dsviewer, 'Blur size [pixels]:', 'Gaussian Blur', '[1,1,1]')

        if True: #dlg.ShowModal() == wx.ID_OK:
            #sigmas = eval(dlg.GetValue())
            #print sigmas
            #print self.images[0].img.shape
            #filt_ims = [np.atleast_3d(gaussian_filter(self.image.data[:,:,:,chanNum].squeeze(), sigmas)) for chanNum in range(self.image.data.shape[3])]
            ims = self.image.data[:,:,0,0].astype('f')
            
            ims = ims - np.median(ims, 0)
            
            ims = gaussian_filter1d(ims, 2, 1)
            ims = convolve1d(ims, np.ones(10), 0)
            
            ims = np.rollaxis(ims, 0, 3)
            
            #ims = (ims - ims.min()).astype('uint16')
            
            im = ImageStack(ims, titleStub = 'Filtered Image')
            im.mdh.copyEntriesFrom(self.image.mdh)
            im.mdh['Parent'] = self.image.filename
            #im.mdh['Processing.'] = sigmas

            if self.dsviewer.mode == 'visGUI':
                mode = 'visGUI'
            else:
                mode = 'lite'

            dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas)

            #set scaling to (0,1)
            for i in range(im.data.shape[3]):
                dv.do.Gains[i] = 1.0

            #imfc = MultiChannelImageViewFrame(self.parent, self.parent.glCanvas, filt_ims, self.image.names, title='Filtered Image - %3.1fnm bins' % self.image.pixelSize)

            #self.parent.generatedImages.append(imfc)
            #imfc.Show()

        dlg.Destroy()
Beispiel #14
0
    def OnSegmentAnneal(self, event):
        newImages = [np.zeros(self.image.data.shape[:3], 'b') for i in range(self.image.data.shape[3])]

        im = ImageStack(newImages)
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        else:
            mode = 'lite'

        self.res = ViewIm3D(im, parent=wx.GetTopLevelParent(self.dsviewer), mode = mode, glCanvas = self.dsviewer.glCanvas)

        self.panAnneal = SegmentationPanel(self.res, self.image, newImages)

        self.pinfo1 = aui.AuiPaneInfo().Name("annealPanel").Left().Caption('Segmentation').DestroyOnClose(True).CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
        self.res._mgr.AddPane(self.panAnneal, self.pinfo1)
        self.res._mgr.Update()
Beispiel #15
0
    def _fetchMap(self, md, mapName):
        '''retrive a map, with a given name. First try and get it from the Queue,
        then try finding it locally'''
        try:
            varmap = md.taskQueue.getQueueData(md.dataSourceID, 'MAP',  mapName)
        except:
            fn = getFullExistingFilename(mapName)
            varmap = ImageStack(filename=fn).data[:,:,0].squeeze() #this should handle .tif, .h5, and a few others

        return varmap
Beispiel #16
0
    def OnLabelWatershed(self, event):
        import numpy as np
        from PYME.cpmath import watershed
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D
        
        nChans = self.image.data.shape[3]
    
        filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].squeeze()) for chanNum in range(nChans)]
        
        img = (-sum([im/im.max() for im in filt_ims])*(2**15)/nChans).astype('int16')
        
        mask = (sum([filt_ims[chanNum] > self.do.thresholds[chanNum] for chanNum in range(nChans)]) > .5).astype('int16')
        
        #self.image.labelThresholds = [(self.dsviewer.do.Offs[chanNum] + 0.5/self.dsviewer.do.Gains[chanNum]) for chanNum in range(self.image.data.shape[3])]

        #print sum(filt_ims).shape
        
        labs = watershed.fast_watershed(img, self.image.labels.astype('int16'), mask=mask)
            
        #store a copy in the image for measurements etc ...
        self.image.labels = labs
        
        im = ImageStack(labs, titleStub = 'Labelled Image')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        
        im.mdh['Labelling.WatershedThresholds'] = self.do.thresholds
        
        #im.mdh['Labelling.MinSize'] = rSize
        #im.mdh['Labelling.Thresholds'] = self.image.labelThresholds
        #im.mdh['Processing.CropROI'] = roi

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        else:
            mode = 'lite'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))

        #set scaling to (0,1)
        for i in range(im.data.shape[3]):
            dv.do.Gains[i] = 1.0
Beispiel #17
0
    def OnCrop(self, event):
        import numpy as np
        #from scipy.ndimage import gaussian_filter
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        #dlg = wx.TextEntryDialog(self.dsviewer, 'Blur size [pixels]:', 'Gaussian Blur', '[1,1,1]')

        #if dlg.ShowModal() == wx.ID_OK:
            #sigmas = eval(dlg.GetValue())
            #print sigmas
            #print self.images[0].img.shape

        roi = [[self.do.selection_begin_x, self.do.selection_end_x + 1],[self.do.selection_begin_y, self.do.selection_end_y +1], [0, self.image.data.shape[2]]]

        filt_ims = [np.atleast_3d(self.image.data[roi[0][0]:roi[0][1],roi[1][0]:roi[1][1],:,chanNum].squeeze()) for chanNum in range(self.image.data.shape[3])]

        im = ImageStack(filt_ims, titleStub = 'Cropped Image')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        im.mdh['Processing.CropROI'] = roi

        vx, vy, vz = self.image.voxelsize
        ox, oy, oz = self.image.origin
        
        im.mdh['Origin.x'] = ox + roi[0][0]*vx
        im.mdh['Origin.y'] = oy + roi[1][0]*vy
        im.mdh['Origin.z'] = oz

        if self.dsviewer.mode == 'visGUI':
            mode = 'visGUI'
        else:
            mode = 'lite'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))

        #set scaling to (0,1)
        for i in range(im.data.shape[3]):
            dv.do.Gains[i] = 1.0
Beispiel #18
0
    def OnInit(self):
        import sys
        from optparse import OptionParser

        op = OptionParser(usage = 'usage: %s [options] [filename]' % sys.argv[0])

        op.add_option('-m', '--mode', dest='mode', help="mode (or personality), as defined in PYME/DSView/modules/__init__.py")
        op.add_option('-q', '--queueURI', dest='queueURI', help="the Pyro URI of the task queue - to avoid having to use the nameserver lookup")
        op.add_option('-t', '--test', dest='test', help="Show a test image", action="store_true", default=False)

        options, args = op.parse_args()
        
        if options.test:
            import pylab
            im = ImageStack(pylab.randn(100,100))
        elif len (args) > 0:
            im = ImageStack(filename=args[0], queueURI=options.queueURI)
        else:
            im = ImageStack(queueURI=options.queueURI)

        if options.mode == None:
            mode = im.mode
        else:
            mode = options.mode

        vframe = DSViewFrame(im, None, im.filename, mode = mode)

        self.SetTopWindow(vframe)
        vframe.Show(1)
        
        if len(args) > 1:
            for fn in args[1:]:
                im = ImageStack(filename=fn)
                ViewIm3D(im)

        return 1
Beispiel #19
0
    def OnPSFFromPupil(self, event):
        import numpy as np
        #import pylab
        from PYME.PSFGen import fourierHNA
        
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D
        
        self.configure_traits(kind='modal')

        z_ = np.arange(self.sizeZ)*float(self.zSpacing)
        z_ -= z_.mean()        
        
        ps = fourierHNA.PsfFromPupil(self.image.data[:,:], z_, self.image.mdh['voxelsize.x']*1e3, self.wavelength)#, shape = [self.sizeX, self.sizeX])
        
        ps = ps/ps[:,:,self.sizeZ/2].sum()
        
        im = ImageStack(ps, titleStub = 'Generated PSF')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        #im.mdh['Processing.CropROI'] = roi
        mode = 'psf'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
Beispiel #20
0
    def getQueueData(self, fieldName, *args):
        '''Get data, defined by fieldName and potntially additional arguments,  ascociated with queue'''
        if fieldName == 'FitResults':
            startingAt, = args
            with self.fileResultsLock.rlock:
                if self.h5ResultsFile.__contains__('/FitResults'):
                    res = self.h5ResultsFile.root.FitResults[startingAt:]
                else:
                    res = []

            return res
        elif fieldName == 'MAP':
            mapName, = args
            from PYME.ParallelTasks.relativeFiles import getFullExistingFilename
            from PYME.DSView.image import ImageStack

            fn = getFullExistingFilename(mapName)
            varmap = ImageStack(filename=fn).data[:, :, 0].squeeze(
            )  #this should handle .tif, .h5, and a few others

            return varmap
        else:
            return None
Beispiel #21
0
 def OnDropFiles(self, x, y, filenames):
     print(filenames)
     
     for filename in filenames:
         im = ImageStack(filename=filename)
         ViewIm3D(im)
Beispiel #22
0
 def OnOpen(self, event=None):
     ViewIm3D(ImageStack())
Beispiel #23
0
 def _pickChannel(self, image):
     chan = image.data[:,:,:,self.channelToExtract]
     
     im = ImageStack(chan, titleStub = 'Filtered Image')
     im.mdh.copyEntriesFrom(self.image.mdh)
     im.mdh['Parent'] = self.image.filename
Beispiel #24
0
    def OnLabelSizeThreshold(self, event):
        import numpy as np
        from scipy import ndimage
        from PYME.DSView.image import ImageStack
        from PYME.DSView import ViewIm3D

        #dlg = wx.TextEntryDialog(self.dsviewer, 'Blur size [pixels]:', 'Gaussian Blur', '[1,1,1]')

        #if dlg.ShowModal() == wx.ID_OK:
            #sigmas = eval(dlg.GetValue())
            #print sigmas
            #print self.images[0].img.shape

        #roi = [[self.do.selection_begin_x, self.do.selection_end_x + 1],[self.do.selection_begin_y, self.do.selection_end_y +1], [0, self.image.data.shape[2]]]

        #filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].squeeze() > self.dsviewer.do.Offs[chanNum]) for chanNum in range(self.image.data.shape[3])]

        dlg = wx.TextEntryDialog(self.dsviewer, 'Minimum region size [pixels]:', 'Labelling', '1')

        if dlg.ShowModal() == wx.ID_OK:
            rSize = int(dlg.GetValue())
            
            
            self.image.labelThresholds = self.do.thresholds
        
            #filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].squeeze() > (self.dsviewer.do.Offs[chanNum] + 0.5/self.dsviewer.do.Gains[chanNum])) for chanNum in range(self.image.data.shape[3])]
            filt_ims = [np.atleast_3d(self.image.data[:,:,:,chanNum].squeeze() > self.image.labelThresholds[chanNum]) for chanNum in range(self.image.data.shape[3])]
            
            #self.image.labelThresholds = [(self.dsviewer.do.Offs[chanNum] + 0.5/self.dsviewer.do.Gains[chanNum]) for chanNum in range(self.image.data.shape[3])]
    
            #print sum(filt_ims).shape
            mask = sum(filt_ims) > 0.5
            labs, nlabs = ndimage.label(mask)
            
            if rSize > 1:
                m2 = 0*mask
                objs = ndimage.find_objects(labs)
                for i, o in enumerate(objs):
                    r = labs[o] == i+1
                    #print r.shape
                    if r.sum() > rSize:
                        m2[o] = r
                        
                labs, nlabs = ndimage.label(m2)
                
            #store a copy in the image for measurements etc ...
            self.image.labels = labs
            
            im = ImageStack(labs, titleStub = 'Labelled Image')
            im.mdh.copyEntriesFrom(self.image.mdh)
            im.mdh['Parent'] = self.image.filename
            
            im.mdh['Labelling.MinSize'] = rSize
            im.mdh['Labelling.Thresholds'] = self.image.labelThresholds
            #im.mdh['Processing.CropROI'] = roi
    
            if self.dsviewer.mode == 'visGUI':
                mode = 'visGUI'
            else:
                mode = 'lite'
    
            dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))
    
            #set scaling to (0,1)
            for i in range(im.data.shape[3]):
                dv.do.Gains[i] = 1.0