def binarize(f): Prefs.blackBackground = True imp = IJ.openImage(f) if imp: binimp = imp.duplicate() bs = BackgroundSubtracter() ip = binimp.getProcessor() bs.rollingBallBackground(ip, 15, False, False, False, True, True) IJ.run(binimp, "Unsharp Mask...", "radius=2 mask=0.9") def smooth(n=1): for i in range(n): IJ.run(binimp, "Smooth", "") smooth(10) IJ.setAutoThreshold(binimp, "Moments dark") IJ.run(binimp, "Make Binary", "thresholded remaining") smooth(12) IJ.setAutoThreshold(binimp, "Moments white") IJ.run(binimp, "Make Binary", "thresholded remaining") IJ.run(binimp, "Erode", "") IJ.run(binimp, "Dilate", "") IJ.run(binimp, "Analyze Particles...", "size=250-Infinity circularity=0.2-1.00 exclude clear add") binimp.close() else: pass
def apply_rollingball(imp, radius=30, createBackground=False, lightBackground=False, useParaboloid=False, doPresmooth=True, correctCorners=False): # Create BackgroundSubtracter instance bs = BackgroundSubtracter() stack = imp.getStack() # get the stack within the ImagePlus nslices = stack.getSize() # get the number of slices for index in range(1, nslices + 1): ip = stack.getProcessor(index) # Run public method rollingBallBackground bs.rollingBallBackground(ip, radius, createBackground, lightBackground, useParaboloid, doPresmooth, correctCorners) return imp
def process(Destination_Directory, Current_Directory, filename, parameters): """ Rolling ball method. """ print "Processing:" # Opening the image print "Open image file", filename imp = IJ.openImage(os.path.join(Current_Directory, filename)) ip = imp.getProcessor() # Parameters: Image processor, Rolling Ball Radius, Create background, # light background, use parabaloid, do pre smoothing (3x3), # correct corners b = BackgroundSubtracter() b.rollingBallBackground(ip, float(parameters["ballsize"]), ast.literal_eval(parameters["create_b"]), ast.literal_eval(parameters["light_b"]), ast.literal_eval(parameters["parab"]), ast.literal_eval(parameters["smooth"]), ast.literal_eval(parameters["corners"]) ) print "Saving to", Destination_Directory IJ.saveAs(imp, "Tiff", os.path.join(Destination_Directory, filename)) imp.close()
def back_substraction(ip1, ip2, radius_background): bgs=BackgroundSubtracter() bgs.rollingBallBackground(ip1, radius_background, False, False, True, True, True) bgs.rollingBallBackground(ip2, radius_background, False, False, True, True, True) imp1 = ImagePlus("ch1 back sub", ip1) imp2 = ImagePlus("ch2 back sub", ip2) return imp1, imp2
return SpotDetectionLog(imgBgs32, data, ops, thresholdmethod, dimensions2D, factory) def SpotDetection2(imp): imp=Duplicator().run(imp) # subtract background bgs=BackgroundSubtracter()
def back_substraction(ip1, ip2, radius_background): bgs=BackgroundSubtracter() bgs.rollingBallBackground(ip1, radius_background, False, False, True, True, True) bgs.rollingBallBackground(ip2, radius_background, False, False, True, True, True) imp1 = ImagePlus("ch1 back sub", ip1) imp2 = ImagePlus("ch2 back sub", ip2) IJ.run(imp1, "Enhance Contrast", "saturated=0.35") IJ.run(imp2, "Enhance Contrast", "saturated=0.35") return imp1, imp2
IJ.run(imp, "Auto Threshold", "method=Triangle white"); return imp def SpotDetection3(imp, invert=False): # operate on a duplicate as not to change the original imp=Duplicator().run(imp) if (invert): IJ.run(imp, "Invert", ""); # subtract background bgs=BackgroundSubtracter() bgs.rollingBallBackground(imp.getProcessor(), 50.0, False, False, True, True, True)
def apply_rollingball(imp, rolling_ball, createBackground, lightBackground, useParaboloid, doPresmooth, correctCorners): ## taken from https://forum.image.sc/t/run-fiji-python-script-with-parameters-on-windows/6162/9 print 'Substracting Background - Radius:', rolling_ball # Create BackgroundSubtracter instance bs = BackgroundSubtracter() # get the stacks stack, nslices = getImageStack(imp) for index in range(1, nslices + 1): ip = stack.getProcessor(index) # Run public method rollingBallBackground bs.rollingBallBackground(ip, rolling_ball, createBackground, lightBackground, useParaboloid, doPresmooth, correctCorners) return imp
def SpotDetectionGray(gray, data, display, ops, invert): # get the dimensions dimensions2D = array([gray.dimension(0), gray.dimension(1)], 'l') factory = gray.getImg().factory() # wrap as ImagePlus imp = ImageJFunctions.wrap(gray, "wrapped") # create and call background subtractor bgs = BackgroundSubtracter() bgs.rollingBallBackground(imp.getProcessor(), 50.0, False, False, True, True, True) # wrap the result of background subtraction as Img and display it iplus = ImagePlus("bgs", imp.getProcessor()) # if (invert==True): # iplus.getProcessor().invert() imgBgs = ImageJFunctions.wrapByte(iplus) display.createDisplay("back_sub", data.create(ImgPlus(imgBgs))) # convert the background subtracted image to 32 bit temp = ops.run("createimg", factory, FloatType(), dimensions2D) imgBgs32 = ImgPlus(temp) ops.convert(imgBgs32, imgBgs, ConvertPixCopy()) #display.createDisplay("back_sub 32", data.create(ImgPlus(imgBgs32))) # create the Laplacian of Gaussian filter kernel = DetectionUtils.createLoGKernel(3.0, 2, array([1.0, 1.0], 'd')) # apply the log filter and display the result log = ImgPlus(ops.run("createimg", factory, FloatType(), dimensions2D)) ops.convolve(log, imgBgs32, kernel) #display.createDisplay("log", data.create(ImgPlus(log))) # apply the threshold operation #thresholded=ops.run("threshold", ops.create( dimensions2D, BitType()), log, Triangle()) thresholded = ops.run("triangle", log) return ImgPlus(thresholded)
from jarray import array from fiji.plugin.trackmate.detection import DetectionUtils from net.imagej.ops.convert import ConvertPixCopy ############################################################### # Step 1: Rolling ball background subtraction (still uses IJ1) ############################################################### # wrap as ImagePlus imp = ImageJFunctions.wrap(inputData, "wrapped") # create and call background subtractor bgs = BackgroundSubtracter() bgs.rollingBallBackground(imp.getProcessor(), 50.0, False, False, True, True, True) # wrap the result of background subtraction as Img iplus = ImagePlus("bgs", imp.getProcessor()) imgBgs = ImageJFunctions.wrapShort(iplus) ############################################################### # Step 2: Laplacian of Gaussian Filtering ############################################################### # convert to 32 bit imgBgs32 = ops.run("createimg", imgBgs, FloatType()) ops.convert(imgBgs32, imgBgs, ConvertPixCopy())
# Perform median filtering processor = frame.getProcessor() filters = RankFilters() filters.setup("median", frame) filters.rank(processor, filter_window, filters.MEDIAN) # Perform gamma correction processor.gamma(gamma) frame = ImagePlus("Frame " + str(frame_i), processor) # Rolling ball background subtraction processor = frame.getProcessor() bg_subtractor = BackgroundSubtracter() bg_subtractor.setup("", frame) bg_subtractor.rollingBallBackground(processor, rolling_ball_size/pixel_size, False, False, False, False, True) frame = ImagePlus("Frame " + str(frame_i), processor) # Calibrate pixels calibration = Calibration() calibration.setUnit("pixel") calibration.pixelWidth = pixel_size calibration.pixelHeight = pixel_size calibration.pixelDepth = 1.0 frame.setCalibration(calibration) # Save to output dir