def prepare_image_stacks(image_dir): """ For each stack directory in image_dir, load the image sequence as a stack and spatially calibrate the stack. Returns: images (list): The list containing the calibrated image stacks. Args: image_dir (str): The directory containing the image stack directories. """ images = [] for stack_dir in os.listdir(image_dir): stack_dir_full_path = str(image_dir) + '/' + stack_dir imp = FolderOpener.open(stack_dir_full_path) cal = Calibration() cal.setUnit('um') cal.pixelWidth = 0.3296485 cal.pixelHeight = 0.3296485 cal.pixelDepth = 0.998834955 imp.setCalibration(cal) imp.setTitle( stack_dir) # name the image after its directory, e.g. OP_1 images.append(imp) return images
def set_xyz_calibration(imp, dx, dy, dz, unit): cal = Calibration(imp) cal.setUnit(unit) cal.pixelWidth = dx cal.pixelHeight = dy cal.pixelDepth = dz imp.setCalibration(cal) return imp
def setSpatialCalibration(img, xwidth, unit="micron"): """ img is an image object from openImage() xwidth is the width of the image in units (default micron) """ if xwidth <= 0: # If spatial calibration is not given. Do not try to set it. return pixelSize = xwidth / (1.0*img.getWidth()) cal = Calibration(img) cal.pixelWidth = pixelSize cal.pixelHeight = pixelSize cal.setUnit(unit) img.setCalibration(cal) return img
n_channels = 1 n_slices = 1 # Z slices n_frames = 1 # time frames # Get current image image = IJ.getImage() # Check that we have correct dimensions stack_size = image.getImageStackSize() # raw number of images in the stack if n_channels * n_slices * n_frames == stack_size: image.setDimensions(n_channels, n_slices, n_frames) else: IJ.log('The product of channels (' + str(n_channels) + '), slices (' + str(n_slices) + ')') IJ.log('and frames (' + str(n_frames) + ') must equal the stack size (' + str(stack_size) + ').') # Set calibration pixel_width = 1 pixel_height = 1 pixel_depth = 1 space_unit = 'µm' frame_interval = 1 time_unit = 's' calibration = Calibration() # new empty calibration calibration.pixelWidth = pixel_width calibration.pixelHeight = pixel_height calibration.pixelDepth = pixel_depth calibration.frameInterval = frame_interval calibration.setUnit(space_unit) calibration.setTimeUnit(time_unit) image.setCalibration(calibration) image.repaintWindow()
# Set dimensions n_channels = 1 n_slices = 1 # Z slices n_frames = 1 # time frames # Get current image image = IJ.getImage() # Check that we have correct dimensions stack_size = image.getImageStackSize() # raw number of images in the stack if n_channels * n_slices * n_frames == stack_size: image.setDimensions(n_channels, n_slices, n_frames) else: IJ.log('The product of channels ('+str(n_channels)+'), slices ('+str(n_slices)+')') IJ.log('and frames ('+str(n_frames)+') must equal the stack size ('+str(stack_size)+').') # Set calibration pixel_width = 1 pixel_height = 1 pixel_depth = 1 space_unit = 'µm' frame_interval = 1 time_unit = 's' calibration = Calibration() # new empty calibration calibration.pixelWidth = pixel_width calibration.pixelHeight = pixel_height calibration.pixelDepth = pixel_depth calibration.frameInterval = frame_interval calibration.setUnit(space_unit) calibration.setTimeUnit(time_unit) image.setCalibration(calibration) image.repaintWindow()
log_info += 'track_start: ' + str(track_start) + '\n' # Get image and calibrate imps = BF.openImagePlus(input_file) imp = imps[0] imp.setDisplayMode(IJ.COLOR) imp.setC(color) # imp.setDisplayRange(0.0, 3.0) # imp.show() log_info += 'frames: ' + str(imp.getNFrames()) + '\n' log_info += 'width: ' + str(imp.getWidth()) + '\n' log_info += 'height: ' + str(imp.getHeight()) + '\n' cal = Calibration() cal.setUnit('micron') cal.pixelHeight = resolution cal.pixelWidth = resolution cal.pixelDepth = 0. cal.fps = 1 cal.frameInterval = 1 imp.setCalibration(cal) #------------------------- # Instantiate model object #------------------------- model = Model() model.setPhysicalUnits('micron', 'frames') # Set logger
def set_calibration_obj(metadata_dict): cal = Calibration() cal.setUnit(metadata_dict["unit"]) cal.pixelWidth = 1 / metadata_dict["xpix"] cal.pixelHeight = 1 / metadata_dict["ypix"] return cal
def setScale(self, distCm, distPixel): cal = Calibration() cal.setUnit("cm") cal.pixelWidth = distCm / distPixel cal.pixelHeight = distCm / distPixel ImagePlus().setGlobalCalibration(cal)
# call template=make_template(well, data_dir) here. use_template = True template = None #or make_template('B1', '10X_c2-SBS-2_2') data_dirs = ['test'] # usually xyzct, except on bad days when it's xyczt(default) # order = 'xyzct' order = 'xyczt(default)' rows = 'ABH' columns = [str(x) for x in range(1, 13)] wells = [row + column for row in rows for column in columns] wells = ['A1'] cal = Calibration() cal.setUnit('um') cal.pixelWidth = pixel_width cal.pixelHeight = pixel_width def savename(well, data_dir): # TODO better naming convention, use Site_0? return home_dir + data_dir + '_MMStack_' + well + '.stitched.tif' def tile_config_name(well, data_dir): return def macro_dir(s): """Wrap directory string so ImageJ macro accepts it as parameter.
def make_calibration(magnification): cal = Calibration() cal.setUnit('um') cal.pixelWidth = args.magnification cal.pixelHeight = cal.pixelWidth return cal
if True: # osx, unix filesep = '/' home_dir = '/broad/blainey_lab/David/lasagna/20150817 6 round/data/' home_dir = '/Users/feldman/Downloads/20151209/' else: # windows home_dir = 'D:\\User Folders\\David\\lasagna\\20151122_96W-G020\\' # home_dir = '\\\\neon-cifs\\blainey_lab\\David\\lasagna\\20150817 6 round\\analysis\\calibrated\\raw\\' filesep = '\\' data_dirs = ['stack'] cal = Calibration() cal.setUnit('um') cal.pixelWidth = pixel_width cal.pixelHeight = pixel_width def savename(well, data_dir): # TODO better naming convention, use Site_0? return home_dir + data_dir + '_MMStack_' + well + '.stitched.tif' def stitch_cmd_file(directory, layout_file): s = """type=[Positions from file] order=[Defined by TileConfiguration] directory=%s layout_file=%s fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 computation_parameters=[Save computation time (but use more RAM)] image_output=[Fuse and display]""" return s % (directory, layout_file) for data_dir in data_dirs: print home_dir + data_dir + filesep + '*.registered.tif' files = glob(home_dir + data_dir + filesep + '*.registered.txt')
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 file_name = output_dir + "/" + str(frame_i).zfill(4) + ".tif" FileSaver(frame).saveAsTiff(file_name) frame_i = frame_i + 1