def segCentrosome(imp): IJ.run(imp, "Unsharp Mask...", "radius=20 mask=0.60"); #IJ.run(imp, "FeatureJ Laplacian", "compute smoothing=1.0"); fjimg = FJimage.wrap(imp) fjimglap = Laplacian().run(fjimg, 1.0) imp2 = fjimglap.imageplus() IJ.run(imp2, "Invert", "") IJ.run(imp2, "Unsharp Mask...", "radius=1 mask=0.60") if TESTMODE == True: imp2.show() segip = MaximumFinder().findMaxima( imp2.getProcessor(), MAXFIND_TOLERANCE, ImageProcessor.NO_THRESHOLD, MaximumFinder.SINGLE_POINTS , False, False) #IJ.run(imp2, "Find Maxima...", "noise=1800 output=[Single Points]") return segip
def translate_using_imagescience(imp_tmpstack, dx, dy, dz): translator = Translate() output = translator.run(Image.wrap(imp_tmpstack), dx, dy, dz, Translate.LINEAR) return output.imageplus()
def register_hyperstack_subpixel(imp, channel, shifts, target_folder, virtual): """ Takes the imp, determines the x,y,z drift for each pair of time points, using the preferred given channel, and outputs as a hyperstack. The shifted image is computed using TransformJ allowing for sub-pixel shifts using interpolation. This is quite a bit slower than just shifting the image by full pixels as done in above function register_hyperstack(). However it significantly improves the result by removing pixel jitter. """ # Compute bounds of the new volume, # which accounts for all translations: minx, miny, minz, maxx, maxy, maxz = compute_min_max(shifts) # Make shifts relative to new canvas dimensions # so that the min values become 0,0,0 for shift in shifts: shift.x -= minx shift.y -= miny shift.z -= minz # new canvas dimensions: width = int(imp.width + maxx - minx) height = int(maxy - miny + imp.height) slices = int(maxz - minz + imp.getNSlices()) print "New dimensions:", width, height, slices # prepare stack for final results stack = imp.getStack() if virtual is True: names = [] else: registeredstack = ImageStack(width, height, imp.getProcessor().getColorModel()) # prepare empty slice for padding empty = imp.getProcessor().createProcessor(width, height) IJ.showProgress(0) for frame in range(1, imp.getNFrames()+1): IJ.showProgress(frame / float(imp.getNFrames()+1)) fr = "t" + zero_pad(frame, len(str(imp.getNFrames()))) # for saving files in a virtual stack # init shift = shifts[frame-1] registeredstackthisframe = ImageStack(width, height, imp.getProcessor().getColorModel()) print "frame",frame,"correcting drift",-shift.x-minx,-shift.y-miny,-shift.z-minz IJ.log(" frame "+str(frame)+" correcting drift "+str(round(-shift.x-minx,2))+","+str(round(-shift.y-miny,2))+","+str(round(-shift.z-minz,2))) # Add all slices of this frame stack = imp.getStack() for s in range(1, imp.getNSlices()+1): for ch in range(1, imp.getNChannels()+1): ip = stack.getProcessor(imp.getStackIndex(ch, s, frame)) ip2 = ip.createProcessor(width, height) # potentially larger ip2.insert(ip, 0, 0) registeredstackthisframe.addSlice("", ip2) # Pad the end (in z) of this frame for s in range(imp.getNSlices(), slices): for ch in range(1, imp.getNChannels()+1): registeredstackthisframe.addSlice("", empty) # Set correct dimensions as below Translate() function needs this # ..it is important *not* to set the calibration as Translate() works with units if present registeredstackthisframe_imp = ImagePlus("registered time points", registeredstackthisframe) registeredstackthisframe_imp.setProperty("Info", imp.getProperty("Info")) registeredstackthisframe_imp.setDimensions(imp.getNChannels(), slices, 1) registeredstackthisframe_imp.setOpenAsHyperStack(True) # Translate and set dimensions to translated result translator = Translate() output = translator.run(Image.wrap(registeredstackthisframe_imp),shift.x,shift.y,shift.z,Translate.LINEAR) imp_translated = output.imageplus() imp_translated.setProperty("Info", imp.getProperty("Info")) imp_translated.setDimensions(imp.getNChannels(), slices, 1) imp_translated.setOpenAsHyperStack(True) # Add the translated frame to the final time-series stack = imp_translated.getStack() for s in range(1, imp_translated.getNSlices()+1): ss = "_z" + zero_pad(s, len(str(slices))) for ch in range(1, imp_translated.getNChannels()+1): ip = stack.getProcessor(imp_translated.getStackIndex(ch, s, 1)) if virtual is True: name = fr + ss + "_c" + zero_pad(ch, len(str(imp.getNChannels()))) +".tif" names.append(name) currentslice = ImagePlus("", ip) currentslice.setCalibration(imp.getCalibration().copy()) currentslice.setProperty("Info", imp.getProperty("Info")); FileSaver(currentslice).saveAsTiff(target_folder + "/" + name) else: registeredstack.addSlice("", ip) IJ.showProgress(1) if virtual is True: # Create virtual hyper stack with the result registeredstack = VirtualStack(width, height, None, target_folder) for name in names: registeredstack.addSlice(name) registeredstack_imp = ImagePlus("registered time points", registeredstack) registeredstack_imp.setDimensions(imp.getNChannels(), slices, imp.getNFrames()) registeredstack_imp.setCalibration(imp.getCalibration().copy()) registeredstack_imp.setOpenAsHyperStack(True) else: registeredstack_imp = ImagePlus("registered time points", registeredstack) registeredstack_imp.setCalibration(imp.getCalibration().copy()) registeredstack_imp.setProperty("Info", imp.getProperty("Info")) registeredstack_imp.setDimensions(imp.getNChannels(), slices, imp.getNFrames()) registeredstack_imp.setOpenAsHyperStack(True) if 1 == registeredstack_imp.getNChannels(): return registeredstack_imp #IJ.log("\nHyperstack dimensions: time frames:" + str(registeredstack_imp.getNFrames()) + ", slices: " + str(registeredstack_imp.getNSlices()) + ", channels: " + str(registeredstack_imp.getNChannels())) # Else, as composite mode = CompositeImage.COLOR; if isinstance(imp, CompositeImage): mode = imp.getMode() else: return registeredstack_imp return CompositeImage(registeredstack_imp, mode)