def create_empty_imp(imp):
    dims = imp.getDimensions()
    depth = imp.getBitDepth()
    dims = list(dims)
    dims.append(depth)
    new_imp = IJ.createHyperStack("new", *dims)

    return new_imp
Esempio n. 2
0
def GenerateGallery(imp, CoordinateList):
    """ Generates a gallery from a list of coordinates:
    input values are:
    a coordinate list (x,y as list of tupels)
    an image from which the gallery is generated (imp),
    Image must (for now) be a 8 or 16 bit composite
    a ROI size for the gallery (roisize)"""
    if CoordinateList != []:
        CellNumber = len(CoordinateList)
        channelnumber = imp.getNChannels()
        slicenumber = imp.getNSlices()
        bitdepth = imp.getBitDepth()
        imp2 = IJ.createHyperStack("Gallery", roisize, roisize, channelnumber,
                                   slicenumber, CellNumber, bitdepth)
        if bitdepth != 24:
            imp2.copyLuts(imp)
        timer = 0
        for cells in CoordinateList:
            timer = timer + 1
            roi2 = Roi(cells[0] - (roisize / 2), cells[1] - roisize / 2,
                       roisize, roisize)
            imp.setC(1)
            imp.setRoi(roi2)
            imp.copy()
            imp2.setT(timer)
            imp2.setC(1)
            imp2.paste()
            if channelnumber > 1:
                imp.setC(2)
                imp.copy()
                imp2.setC(2)
                imp2.paste()
                if channelnumber > 2:
                    imp.setC(3)
                    imp.copy()
                    imp2.setC(3)
                    imp2.paste()
        imp2.show()
        if Label_Gallery:
            timer2 = 0
            for cells in CoordinateList:

                timer2 = timer2 + 1
                imp2.setT(timer2)
                imp2.setC(1)
                ip = imp2.getProcessor()
                Labelfont = Font("Arial", Font.PLAIN, 12)
                ip.setFont(Labelfont)
                ip.setColor(65000)
                ROINumber = str(cells[2])
                ip.drawString(ROINumber[:4], 5, 14)
                imp.updateAndDraw()

        return imp2
Esempio n. 3
0
def concatenateImagePlus(files, outfile):
    """Concatenate images contained in files and save in outfile"""

    options = ImporterOptions()
    options.setId(files[0])
    options.setVirtual(1)
    options.setOpenAllSeries(1)
    options.setQuiet(1)
    images = BF.openImagePlus(options)
    imageG = images[0]
    nrPositions = len(images)
    options.setOpenAllSeries(0)

    nslices = imageG.getNSlices()
    nframes = len(files)
    nchannels = imageG.getNChannels()
    luts = imageG.getLuts()

    for i in range(0, nrPositions):
        concatImgPlus = IJ.createHyperStack(
            "ConcatFile", imageG.getWidth(), imageG.getHeight(),
            imageG.getNChannels(), imageG.getNSlices(),
            len(files), imageG.getBitDepth())


        concatStack = ImageStack(imageG.getWidth(), imageG.getHeight())
        IJ.showStatus("Concatenating files")
        for file_ in files:
            try:
                print '...', basename(file_)
                options.setSeriesOn(i, 1)
                options.setId(file_)
                image = BF.openImagePlus(options)[0]
                imageStack = image.getImageStack()

                sliceNr = imageStack.getSize()
                for j in range(1, sliceNr+1):
                    concatStack.addSlice(imageStack.getProcessor(j))
                image.close()
                options.setSeriesOn(i, 0)
            except Exception, e:
                IJ.log("ERROR")
                IJ.log(file_ + str(e))
                raise
            IJ.showProgress(files.index(file_), len(files))

        concatImgPlus.setStack(concatStack, nchannels, nslices, nframes)
        concatImgPlus.setCalibration(image.getCalibration())
        concatImgPlus.setOpenAsHyperStack(True)
        concatImgPlus.setLuts(luts)
        concatImgPlus.close()
        IJ.saveAs(concatImgPlus, "Tiff",  outfile)
Esempio n. 4
0
def ExtractChannel(imp, channel):
    imp_height = imp.getHeight()
    imp_width = imp.getWidth()
    channelnumber = imp.getNChannels()
    slicenumber = imp.getNSlices()
    timepoints = imp.getNFrames()
    imp2 = IJ.createHyperStack("Gallery",imp_width, imp_height, channelnumber, slicenumber, timepoints, 16)
    imp2.copyLuts(imp)
    for frame in range(1,timepoints+1):
            imp.setT(frame)
            imp.setC(channel)
            imp.copy()
            imp2.setT(frame)
            imp2.setC(channel)
            imp2.paste()
    return imp2
Esempio n. 5
0
def concatenateImagePlus(files, outfile):
	"""concatenate images contained in files and save in outfile"""
	'''
	if len(files) == 1:
		IJ.log(files[0] + " has only one time point! Nothing to concatenate!")
		return
	'''
	options = ImporterOptions()
	options.setId(files[0])
	options.setVirtual(1)
	options.setOpenAllSeries(1)
	options.setQuiet(1)
	images = BF.openImagePlus(options)
	imageG = images[0]
	nrPositions = len(images)
	options.setOpenAllSeries(0)

	for i in range(0, nrPositions):
		concatImgPlus = IJ.createHyperStack("ConcatFile", imageG.getWidth(), imageG.getHeight(), imageG.getNChannels(), imageG.getNSlices(), len(files), imageG.getBitDepth())
		concatStack = ImageStack(imageG.getWidth(), imageG.getHeight())
		IJ.showStatus("Concatenating files")
		for file in files:
			try:
				IJ.log("	Add file " + file)
				options.setSeriesOn(i,1)
				options.setId(file)
				image = BF.openImagePlus(options)[0]
				imageStack = image.getImageStack()
				sliceNr = imageStack.getSize()
				for j in range(1, sliceNr+1):
					concatStack.addSlice(imageStack.getProcessor(j))
				image.close()
				options.setSeriesOn(i,0)
			except:
				traceback.print_exc()
				IJ.log(file + " failed to concatenate!")
			IJ.showProgress(files.index(file), len(files))
		concatImgPlus.setStack(concatStack)
		concatImgPlus.setCalibration(image.getCalibration())
		if len(images) > 1:
			outfileP = addPositionName(i+1,outfile)
			IJ.saveAs(concatImgPlus, "Tiff",  outfileP)
		else:
			IJ.saveAs(concatImgPlus, "Tiff",  outfile)
		concatImgPlus.close()
Esempio n. 6
0
            imp2.paste()
    return imp2

def dist(p0, p1):
    """ Calculates the  distance between two xy coordinates, each
    each coordinated supplied by a tupel"""
    return math.sqrt((p0[0] - p1[0])**2 + (p0[1] - p1[1])**2)


## Generates a gallery from multiple point ROIs
imp = IJ.getImage()
roinumber = RoiManager.getInstance().getCount()
channelnumber = imp.getNChannels()
slicenumber = imp.getNSlices()
timer = 0
imp2 = IJ.createHyperStack("Gallery",GalleryROI, GalleryROI, channelnumber, slicenumber, roinumber, 16)
imp2.copyLuts(imp)
MeanChannel1 = []
MeanChannel2 = []
MeanChannel3 = []
XYCoordinates = []
Distance = []
#print roinumber
#for roi in RoiManager.getInstance().getRoisAsArray(): ## Does not work for time, since only xz coordinates are returned
movietime = []
Lastcoordinates = (0,0)
for roi5 in range(roinumber):
    #print roi5
    RoiManager().getInstance().select(imp, roi5)
    roi = imp.getRoi()
    movietime.append(imp.getT())
Esempio n. 7
0
from ij import IJ, ImagePlus

# create a empty image with the same dimensions, bitdepth
imp = IJ.getImage()
dims = imp.getDimensions()
depth = imp.getBitDepth()
dims = list(dims)
dims.append(depth)

new_imp = IJ.createHyperStack("new", *dims)
new_imp.show()