コード例 #1
0
ファイル: fijipytools.py プロジェクト: soyers/OAD
    def setproperties(imp,
                      scaleX=1.0,
                      scaleY=1.0,
                      scaleZ=1.0,
                      unit="micron",
                      sizeC=1,
                      sizeZ=1,
                      sizeT=1):
        """Set properties of image in Fiji

        :param imp: Image
        :type imp: ImgPlus
        :param scaleX: scaleX, defaults to 1.0
        :type scaleX: float, optional
        :param scaleY: scaleY, defaults to 1.0
        :type scaleY: float, optional
        :param scaleZ: scaleZ, defaults to 1.0
        :type scaleZ: float, optional
        :param unit: scale unit, defaults to "micron"
        :type unit: str, optional
        :param sizeC: sizeC, defaults to 1
        :type sizeC: int, optional
        :param sizeZ: sizeZ, defaults to 1
        :type sizeZ: int, optional
        :param sizeT: sizeT, defaults to 1
        :type sizeT: int, optional
        :return: Image
        :rtype: ImgPlus
        """        

        # check if scaleZ has a valid value to call modify the properties
        if scaleZ is None:
            scaleZ = 1

        # run the image properties tool
        IJ.run(imp, "Properties...", "channels=" + str(sizeC) +
               " slices=" + str(sizeZ)
               + " frames=" + str(sizeT)
               + " unit=" + unit
               + " pixel_width=" + str(scaleX)
               + " pixel_height=" + str(scaleY)
               + " voxel_depth=" + str(scaleZ))

        # create new Calibration object
        newCal = Calibration()

        # set the new paramters
        newCal.pixelWidth = scaleX
        newCal.pixelHeight = scaleY
        newCal.pixelDepth = scaleZ

        # set the correct unit fro the scaling
        newCal.setXUnit(unit)
        newCal.setYUnit(unit)
        newCal.setZUnit(unit)

        # apply the new calibration
        imp.setCalibration(newCal)

        return imp
コード例 #2
0
    def setscale(imp,
                 scaleX=1.0,
                 scaleY=1.0,
                 scaleZ=1.0,
                 unit="micron"):

        # check if scaleZ has a valid value to call modify the scaling
        if scaleZ is None:
            scaleZ = 1.0

        # create new Calibration object
        newCal = Calibration()

        # set the new paramters
        newCal.pixelWidth = scaleX
        newCal.pixelHeight = scaleY
        newCal.pixelDepth = scaleZ

        # set the correct unit fro the scaling
        newCal.setXUnit(unit)
        newCal.setYUnit(unit)
        newCal.setZUnit(unit)

        # apply the new calibration
        imp.setCalibration(newCal)

        return imp
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
ファイル: fijipytools.py プロジェクト: soyers/OAD
    def setscale(imp,
                 scaleX=1.0,
                 scaleY=1.0,
                 scaleZ=1.0,
                 unit="micron"):
        """Set new scaling for image.

        :param imp: image
        :type imp: ImgPlus
        :param scaleX: scaleX, defaults to 1.0
        :type scaleX: float, optional
        :param scaleY: scaleY, defaults to 1.0
        :type scaleY: float, optional
        :param scaleZ: scaleZ, defaults to 1.0
        :type scaleZ: float, optional
        :param unit: scaling unit, defaults to "micron"
        :type unit: str, optional
        :return: image
        :rtype: ImgPlus
        """  


        # check if scaleZ has a valid value to call modify the scaling
        if scaleZ is None:
            scaleZ = 1.0

        # create new Calibration object
        newCal = Calibration()

        # set the new paramters
        newCal.pixelWidth = scaleX
        newCal.pixelHeight = scaleY
        newCal.pixelDepth = scaleZ

        # set the correct unit fro the scaling
        newCal.setXUnit(unit)
        newCal.setYUnit(unit)
        newCal.setZUnit(unit)

        # apply the new calibratiion
        imp.setCalibration(newCal)

        return imp
コード例 #6
0
    def setproperties(imp,
                      scaleX=1.0,
                      scaleY=1.0,
                      scaleZ=1.0,
                      unit="micron",
                      sizeC=1,
                      sizeZ=1,
                      sizeT=1):

        # check if scaleZ has a valid value to call modify the properties
        if scaleZ is None:
            scaleZ = 1

        # run the image properties tool
        IJ.run(imp, "Properties...", "channels=" + str(sizeC)
               + " slices=" + str(sizeZ)
               + " frames=" + str(sizeT)
               + " unit=" + unit
               + " pixel_width=" + str(scaleX)
               + " pixel_height=" + str(scaleY)
               + " voxel_depth=" + str(scaleZ))

        # create new Calibration object
        newCal = Calibration()

        # set the new paramters
        newCal.pixelWidth = scaleX
        newCal.pixelHeight = scaleY
        newCal.pixelDepth = scaleZ

        # set the correct unit fro the scaling
        newCal.setXUnit(unit)
        newCal.setYUnit(unit)
        newCal.setZUnit(unit)

        # apply the new calibration
        imp.setCalibration(newCal)

        return imp
コード例 #7
0
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()
コード例 #8
0
# 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()

コード例 #9
0
                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
                model.setLogger(Logger.IJ_LOGGER)

                #------------------------
コード例 #10
0
########## END EDITING

# Iterate over input files.
for input_file in input_files:

    # Get image and calibrate
    imps = BF.openImagePlus(input_file)
    imp = imps[0]
    imp.setDisplayMode(IJ.COLOR)
    imp.show()

    cal = Calibration()
    cal.setUnit('micron')
    cal.pixelHeight = resolution
    cal.pixelWidth = resolution
    cal.pixelDepth = 2**16
    cal.fps = 10
    cal.frameInterval = 1
    imp.setCalibration(cal)

    #-------------------------
    # Instantiate model object
    #-------------------------

    model = Model()
    model.setPhysicalUnits('micron', 'frames')

    # Set logger
    model.setLogger(Logger.IJ_LOGGER)

    #------------------------
コード例 #11
0
  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