def OnPlotProfile(self, event=None): #lx, ly, hx, hy = self.do.GetSliceSelection() pts = np.array(self.do.selection_trace) w = int(np.floor(0.5 * self.do.selectionWidth)) try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % d for d in range(self.image.data.shape[3])] try: voxx = self.image.mdh.getEntry('voxelsize.x') except: voxx = 1 plots = [] t = np.arange(np.ceil(len(pts))) for chanNum in range(self.image.data.shape[3]): p = ndimage.map_coordinates( self.image.data[:, :, self.do.zp, chanNum].squeeze(), pts.T) plots.append(p.reshape(-1, 1, 1)) #pylab.legend(names) im = ImageStack(plots, titleStub='New Profile') im.xvals = t * voxx if not voxx == 1: im.xlabel = 'Distance [um]' else: im.xlabel = 'Distance [pixels]' im.ylabel = 'Intensity' im.defaultExt = '.txt' im.mdh['voxelsize.x'] = voxx im.mdh['ChannelNames'] = names im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel #im.mdh['Profile.StartX'] = lx #im.mdh['Profile.StartY'] = ly #im.mdh['Profile.EndX'] = hx #im.mdh['Profile.EndY'] = hy #im.mdh['Profile.Width'] = 2*w + 1 im.mdh['OriginalImage'] = self.image.filename ViewIm3D(im, mode='graph')
def OnPlotProfile(self, event=None): #lx, ly, hx, hy = self.do.GetSliceSelection() pts = np.array(self.do.selection_trace) w = int(np.floor(0.5*self.do.selectionWidth)) try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % d for d in range(self.image.data.shape[3])] try: voxx = self.image.mdh.getEntry('voxelsize.x') except: voxx=1 plots = [] t = np.arange(np.ceil(len(pts))) for chanNum in range(self.image.data.shape[3]): p = ndimage.map_coordinates(self.image.data[:,:, self.do.zp, chanNum].squeeze(), pts.T) plots.append(p.reshape(-1, 1,1)) #pylab.legend(names) im = ImageStack(plots, titleStub='New Profile') im.xvals = t*voxx if not voxx == 1: im.xlabel = 'Distance [um]' else: im.xlabel = 'Distance [pixels]' im.ylabel = 'Intensity' im.defaultExt = '.txt' im.mdh['voxelsize.x'] = voxx im.mdh['ChannelNames'] = names im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel #im.mdh['Profile.StartX'] = lx #im.mdh['Profile.StartY'] = ly #im.mdh['Profile.EndX'] = hx #im.mdh['Profile.EndY'] = hy #im.mdh['Profile.Width'] = 2*w + 1 im.mdh['OriginalImage'] = self.image.filename ViewIm3D(im, mode='graph')
def OnPlotProfile(self, event=None): try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % d for d in range(self.image.data.shape[3])] #print lx, hx, ly, hy #pylab.figure() plots = [] for chanNum in range(self.image.data.shape[3]): tmin = self.do.Offs[chanNum] tmax = tmin + 1./self.do.Gains[chanNum] d = self.image.data[:,:,:,chanNum].squeeze() trange = np.linspace(tmin, tmax) p = np.array([ndimage.label(d > t)[1] for t in trange]) plots.append(p.reshape(-1, 1,1)) #pylab.legend(names) im = ImageStack(plots, titleStub='New Threshold Range') im.xvals = trange im.xlabel = 'Threshold' im.ylabel = 'Num Objects' im.defaultExt = '.txt' #im.mdh['voxelsize.x'] = voxx im.mdh['ChannelNames'] = names im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel im.mdh['OriginalImage'] = self.image.filename ViewIm3D(im, mode='graph', parent=wx.GetTopLevelParent(self.dsviewer))
def OnPlotProfile(self, event=None): try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % d for d in range(self.image.data.shape[3])] #print lx, hx, ly, hy #pylab.figure() plots = [] for chanNum in range(self.image.data.shape[3]): tmin = self.do.Offs[chanNum] tmax = tmin + 1. / self.do.Gains[chanNum] d = self.image.data[:, :, :, chanNum].squeeze() trange = np.linspace(tmin, tmax) p = np.array([ndimage.label(d > t)[1] for t in trange]) plots.append(p.reshape(-1, 1, 1)) #pylab.legend(names) im = ImageStack(plots, titleStub='New Threshold Range') im.xvals = trange im.xlabel = 'Threshold' im.ylabel = 'Num Objects' im.defaultExt = '.txt' #im.mdh['voxelsize.x'] = voxx im.mdh['ChannelNames'] = names im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel im.mdh['OriginalImage'] = self.image.filename ViewIm3D(im, mode='graph', parent=wx.GetTopLevelParent(self.dsviewer))
def OnColoc(self, event): from PYME.Analysis.Colocalisation import correlationCoeffs, edtColoc voxelsize = [1e3*self.image.mdh.getEntry('voxelsize.x') ,1e3*self.image.mdh.getEntry('voxelsize.y'), 1e3*self.image.mdh.getEntry('voxelsize.z')] try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % n for n in range(self.image.data.shape[3])] dlg = ColocSettingsDialog(self.dsviewer, voxelsize[0], names) dlg.ShowModal() bins = dlg.GetBins() chans = dlg.GetChans() dlg.Destroy() #assume we have exactly 2 channels #FIXME - add a selector #grab image data imA = self.image.data[:,:,:,chans[0]].squeeze() imB = self.image.data[:,:,:,chans[1]].squeeze() #assume threshold is half the colour bounds - good if using threshold mode tA = self.do.Offs[chans[0]] + .5/self.do.Gains[chans[0]] #pylab.mean(self.ivps[0].clim) tB = self.do.Offs[chans[1]] + .5/self.do.Gains[chans[1]] #pylab.mean(self.ivps[0].clim) nameA = names[chans[0]] nameB = names[chans[1]] voxelsize = voxelsize[:imA.ndim] #trunctate to number of dimensions print('Calculating Pearson and Manders coefficients ...') pearson = correlationCoeffs.pearson(imA, imB) MA, MB = correlationCoeffs.thresholdedManders(imA, imB, tA, tB) print('Performing distance transform ...') bnA, bmA, binsA = edtColoc.imageDensityAtDistance(imB, imA > tA, voxelsize, bins) print('Performing distance transform (reversed) ...') bnB, bmB, binsB = edtColoc.imageDensityAtDistance(imA, imB > tB, voxelsize, bins) #print binsB, bmB plots = [] pnames = [] pylab.figure() pylab.figtext(.1, .95, 'Pearson: %2.2f M1: %2.2f M2: %2.2f' % (pearson, MA, MB)) pylab.subplot(211) p = bmA/bmA.sum() #print p pylab.bar(binsA[:-1], p, binsA[1] - binsA[0]) pylab.xlabel('Distance from edge of %s [nm]' % nameA) pylab.ylabel('Density of %s' % nameB) plots.append(p.reshape(-1, 1,1)) pnames.append('Dens. %s from %s' % (nameB, nameA)) pylab.subplot(212) p = bmB/bmB.sum() pylab.bar(binsB[:-1], p, binsB[1] - binsB[0]) pylab.xlabel('Distance from edge of %s [nm]' % nameB) pylab.ylabel('Density of %s' % nameA) plots.append(p.reshape(-1, 1,1)) pnames.append('Dens. %s from %s' % (nameA, nameB)) pylab.figure() pylab.figtext(.1, .95, 'Pearson: %2.2f M1: %2.2f M2: %2.2f' % (pearson, MA, MB)) pylab.subplot(211) fA = bmA*bnA p = fA/fA.sum() pylab.bar(binsA[:-1], p, binsA[1] - binsA[0]) pylab.xlabel('Distance from edge of %s [nm]' % nameA) pylab.ylabel('Fraction of %s' % nameB) plots.append(p.reshape(-1, 1,1)) pnames.append('Frac. %s from %s' % (nameB, nameA)) pylab.subplot(212) fB = bmB*bnB p = fB/fB.sum() pylab.bar(binsB[:-1], p, binsB[1] - binsB[0]) pylab.xlabel('Distance from edge of %s [nm]' % nameB) pylab.ylabel('Fraction of %s' % nameA) plots.append(p.reshape(-1, 1,1)) pnames.append('Frac. %s from %s' % (nameA, nameB)) pylab.show() im = ImageStack(plots, titleStub='Radial Distribution') im.xvals = bins[:-1] im.xlabel = 'Distance [nm]' im.ylabel = 'Fraction' im.defaultExt = '.txt' im.mdh['voxelsize.x'] = (bins[1] - bins[0])*1e-3 im.mdh['ChannelNames'] = pnames im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel im.mdh['Colocalisation.Channels'] = names im.mdh['Colocalisation.Thresholds'] = [tA, tB] im.mdh['Colocalisation.Pearson'] = pearson im.mdh['Colocalisation.Manders'] = [MA, MB] im.mdh['OriginalImage'] = self.image.filename ViewIm3D(im, mode='graph')
def OnPlotProfile(self, event=None): lx, ly, hx, hy = self.do.GetSliceSelection() w = int(np.floor(0.5*self.do.selectionWidth)) try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % d for d in range(self.image.data.shape[3])] try: voxx = self.image.mdh.getEntry('voxelsize.x') except: voxx=1 Dx = hx - lx Dy = hy - ly l = np.sqrt((Dx**2 + Dy**2)) dx = Dx/l dy = Dy/l if Dx == 0 and Dy == 0: #special case - profile is orthogonal to current plane d_x = w d_y = w else: d_x = w*abs(dy) d_y = w*abs(dx) #print lx, hx, ly, hy #pylab.figure() plots = [] t = np.arange(np.ceil(l)) for chanNum in range(self.image.data.shape[3]): x_0 = min(lx, hx) y_0 = min(ly, hy) d__x = abs(d_x) + 1 d__y = abs(d_y) + 1 print((dx, dy, d__x, d__y, w)) if(self.do.slice == self.do.SLICE_XY): ims = self.image.data[(min(lx, hx) - d__x):(max(lx,hx)+d__x+1), (min(ly, hy)-d__y):(max(ly,hy)+d__y+1), self.do.zp, chanNum].squeeze() splf = ndimage.spline_filter(ims) p = np.zeros(len(t)) x_c = t*dx + lx - x_0 y_c = t*dy + ly - y_0 print((splf.shape)) for i in range(-w, w+1): #print np.vstack([x_c + d__x +i*dy, y_c + d__y + i*dx]) p += ndimage.map_coordinates(splf, np.vstack([x_c + d__x +i*dy, y_c + d__y - i*dx]), prefilter=False) p = p/(2*w + 1) plots.append(p.reshape(-1, 1,1)) #pylab.legend(names) im = ImageStack(plots, titleStub='New Profile') im.xvals = t*voxx if not voxx == 1: im.xlabel = 'Distance [um]' else: im.xlabel = 'Distance [pixels]' im.ylabel = 'Intensity' im.defaultExt = '.txt' im.mdh['voxelsize.x'] = voxx im.mdh['ChannelNames'] = names im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel im.mdh['Profile.StartX'] = lx im.mdh['Profile.StartY'] = ly im.mdh['Profile.EndX'] = hx im.mdh['Profile.EndY'] = hy im.mdh['Profile.Width'] = 2*w + 1 im.mdh['OriginalImage'] = self.image.filename ViewIm3D(im, mode='graph', parent=wx.GetTopLevelParent(self.dsviewer))
def OnPlotAxialProfile(self, event=None): lx, ly, hx, hy = self.do.GetSliceSelection() try: names = self.image.mdh.getEntry('ChannelNames') except: names = ['Channel %d' % d for d in range(self.image.data.shape[3])] plots = [] t = np.arange(self.image.data.shape[2]) try: stack = (self.image.mdh['AcquisitionType'] == 'Stack') except: stack = False if stack: dt = self.image.mdh['voxelsize.z'] else: try: dt = self.image.mdh['Camera.CycleTime'] except: dt = 1 for chanNum in range(self.image.data.shape[3]): plots.append(np.zeros((len(t), 1, 1))) dlg = wx.ProgressDialog('Extracting Axial Profile', 'Progress', len(t) - 1) for i in t: for chanNum in range(self.image.data.shape[3]): plots[chanNum][i] = self.image.data[lx:hx, ly:hy, i, chanNum].mean() if (i % 10) == 0: dlg.Update(i, '%d of %d frames' % (i, t.size)) dlg.Destroy() #pylab.legend(names) im = ImageStack(plots, titleStub='New Profile') im.xvals = t*dt if stack: im.xlabel = 'Position [um]' elif not dt == 1: im.xlabel = 'Time [s]' else: im.xlabel = 'Time [frames]' im.ylabel = 'Intensity' im.defaultExt = '.txt' im.mdh['voxelsize.x'] = dt im.mdh['ChannelNames'] = names im.mdh['Profile.XValues'] = im.xvals im.mdh['Profile.XLabel'] = im.xlabel im.mdh['Profile.YLabel'] = im.ylabel im.mdh['Profile.X1'] = lx im.mdh['Profile.Y1'] = ly im.mdh['Profile.X2'] = hx im.mdh['Profile.Y2'] = hy im.mdh['OriginalImage'] = self.image.filename im.parent = self.image ViewIm3D(im, mode='graph')