Exemple #1
0
def merge_kymographs(kym1_imp, kym2_imp, params):
    """Merge two kymographs"""
    mrg_imp = RGBStackMerge().mergeChannels([kym1_imp, kym2_imp], True)
    mrg_imp.setTitle("Merged " + params.labeled_species +
                     " intensity and curvature kymograph")
    mrg_imp.show()
    return mrg_imp
Exemple #2
0
def makemontage(imp, hsize=5, vsize=5, increment=1):
    """Makes a montage of a multichannel ImagePlus object.

    Args:
        imp (ImagePlus): An ImagePlus object.
        hsize (int, optional): Size of the horizontal axis. Defaults to 5.
        vsize (int, optional): Size of the vertical axis. Defaults to 5.
        increment (int, optional): The increment between images. Allows for dropping of e.g. every second frame. Defaults to 1.

    Returns:
        ImagePlus: The montage as ImagePlus object.
    """
    gridsize = hsize * vsize

    def _listProduct(inlist):
        """Calculates the product of all elements in a list.

        Args:
            inlist (list): A list of numbers.

        Returns:
            int or double: The product of all list elements.
        """
        product = 1

        for element in inlist:
            if isinstance(element, (int, float)):
                product = element * product

        return product

    def _channelmontage(_imp):
        """Makes a montage of a single channel ImagePlus object.

        Args:
            _imp (ImagePlus): A single channel ImagePlus object.

        Returns:
            ImagePlus: A montage of the one input channel.
        """
        dims = _imp.getDimensions(
        )  # width, height, nChannels, nSlices, nFrames
        frames = _listProduct(dims[2:])
        if frames > gridsize: frames = gridsize
        _montage = MontageMaker().makeMontage2(_imp, hsize, vsize, 1.00, 1,
                                               frames, increment, 0, True)
        return _montage

    name = imp.getTitle()
    channels = ChannelSplitter().split(imp)
    montages = [_channelmontage(channel) for channel in channels]
    montage = RGBStackMerge().mergeChannels(montages, False)
    montage.setTitle(name)
    return montage
Exemple #3
0
# for each channel.
channels = {}
for image_file in image_files:
	channel = re.search('channel(\d+)_', image_file).group(1)
	if channel in channels:
		channels[channel] += 1
	else:
		channels[channel] = 1

if len(channels) > 7:
	print 'Images with more than 7 channels are not currently supported by the Merge Channels operation.'
	sys.exit(1)

# Open an image sequence for each channel.
stacks = []
for channel in channels:
	num_frames = channels[channel]

	IJ.run('Image Sequence...', 'open=%s file=channel%s sort' % (image_files[0], channel))
	stack = IJ.getImage()
	stack.setTitle(channel)
	stack.setDimensions(1, 1, num_frames)  # TODO Don't hardcode the number of slices
	stacks.append(stack)

merged_image = RGBStackMerge().mergeChannels(stacks, False)
merged_image.setTitle(dir_name)

# TODO Alternatively, we could upload directly to OMERO. But that probably
# would not work in headless mode.
IJ.run(merged_image, 'OME-TIFF...', 'save=%s.ome.tif compression=Uncompressed' % image_dir_path)