Пример #1
0
def run():
    srcDir = DirectoryChooser("Choose directory").getDirectory()
    if not srcDir:
        return

    targetDir = DirectoryChooser("Choose target directory").getDirectory()
    if targetDir is None:
        # User canceled the dialog
        return

    sId = ".tiff"

    for root, directories, filenames in os.walk(srcDir):
        for filename in filenames:
            path = os.path.join(root, filename)
            if not (sId in filename):
                continue

            cs = ChannelSeparator()
            cs.setId(path)
            print "cs", cs
            bf = BFVirtualStack(path, cs, False, False, False)
            for sliceIndex in xrange(1, bf.getSize() + 1):
                print "Processing slice", sliceIndex
                ip = bf.getProcessor(sliceIndex)
                sliceFileName = os.path.join(targetDir + filename + "_" +
                                             str(sliceIndex) + ".tiff")
                print "writing ", sliceFileName
                FileSaver(ImagePlus(str(sliceIndex),
                                    ip)).saveAsTiff(sliceFileName)
Пример #2
0
def run():
	index = 0
	# Chose a file to open
	srcDir = DirectoryChooser("Choose directory containing sequence to split").getDirectory()
	# Chose a directory to store each slice as a file
	targetDir = DirectoryChooser("Chose folder in which to save sequence").getDirectory()
	if targetDir is None:
		# User canceled the diolog
		return
	if srcDir is None:
		# User canceled dialog
		return
	#path = os.path.join(srcDir, od.getFileName())
	for f in os.listdir(srcDir):
		path = os.path.join(srcDir, f)
		# Ready:
		cs = ChannelSeparator()
		cs.setId(path)
		bf = BFVirtualStack(path, cs, False, False, False)
		fname = "%06d"%(index-index%200)
		path = os.path.join(targetDir,fname)
		try:
			os.mkdir(path)
		except Exception, e:
			print "Couldn't make directory:",e
		for sliceIndex in xrange(1,bf.getSize() +1):
			print "Well done. Processing slice", sliceIndex
			ip = bf.getProcessor(sliceIndex)
			string = "%06d.tif"%index
			sliceFileName = os.path.join(path, string)
			FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
			index +=1
		print "Finished:",path
def run(FolderName, SaveFolder):
    # Find tiffiles in folder
    onlyfiles = [
        f for f in os.listdir(FolderName) if os.path.isfile(os.path.join(FolderName, f)) and f.lower().endswith(".tif")
    ]

    for ii in xrange(0, len(onlyfiles)):
        path = os.path.join(FolderName, onlyfiles[ii])
        print "Processing file..", path

        # Find stimulus, Block, regions from filename for sorting

        # Get all underscores
        underscores = [m.start() for m in re.finditer("_", onlyfiles[ii])]

        # Fish Name
        findfish = onlyfiles[ii].find("Fish")
        findunderscore = [i for i in underscores if i > findfish][0]
        fishnum = onlyfiles[ii][findfish:findunderscore]

        print "Fish Number..", fishnum

        # Block
        findblock = onlyfiles[ii].find("Block")
        findunderscore = [i for i in underscores if i > findblock][0]
        blocknum = onlyfiles[ii][findblock:findunderscore]

        print "Block Number..", blocknum

        # Stimulus
        findstimulus = onlyfiles[ii].find("Blue")
        findunderscore = [i for i in underscores if i > findstimulus][0]
        stimulustype = onlyfiles[ii][findstimulus:findunderscore]

        print "Stimulus type..", stimulustype

        # Region
        findregion = onlyfiles[ii].find("Hb")
        findunderscore = [i for i in underscores if i > findregion][0]
        region = onlyfiles[ii][findregion - 1 : findunderscore]

        print "Region..", region

        targetDir = os.path.join(SaveFolder, fishnum, region) + filesep
        print "Images will be saved in .....", targetDir

        if not os.path.exists(targetDir):
            os.makedirs(targetDir)

        cs = ChannelSeparator()
        cs.setId(path)
        bf = BFVirtualStack(path, cs, False, False, False)
        for sliceIndex in xrange(1, bf.getSize() + 1):
            print "Processing slice", sliceIndex
            ip = bf.getProcessor(sliceIndex)
            sliceFileName = os.path.join(targetDir, "T=" + str(sliceIndex) + ".tif")
            FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
def run(FolderName, SaveFolder):
    # Find tiffiles in folder
    onlyfiles = [f for f in os.listdir(FolderName) if
                 os.path.isfile(os.path.join(FolderName, f)) and f.lower().endswith('.tif')]

    for ii in xrange(0, len(onlyfiles)):
        path = os.path.join(FolderName, onlyfiles[ii])
        print "Processing file..", path

        # Find stimulus, Block, regions from filename for sorting

        # Get all underscores
        underscores = [m.start() for m in re.finditer('_', onlyfiles[ii])]
		
        # Fish Name
        findfish = onlyfiles[ii].find('Fish')
        findunderscore = [i for i in underscores if i > findfish][0]
        fishnum = onlyfiles[ii][findfish:findunderscore]

        print 'Fish Number..', fishnum

        # Block
        findblock = onlyfiles[ii].find('Block')
        findunderscore = [i for i in underscores if i > findblock][0]
        blocknum = onlyfiles[ii][findblock:findunderscore]

        print 'Block Number..', blocknum

        # Stimulus
        findstimulus = onlyfiles[ii].find('Blue')
        findunderscore = [i for i in underscores if i > findstimulus][0]
        stimulustype = onlyfiles[ii][findstimulus:findunderscore]

        print 'Stimulus type..', stimulustype

        # Region
        findregion = onlyfiles[ii].find('Hb')
        findunderscore = [i for i in underscores if i > findregion][0]
        region = onlyfiles[ii][findregion-1:findunderscore]

        print 'Region..', region

        targetDir = os.path.join(SaveFolder, fishnum, region) + filesep
        print 'Images will be saved in .....', targetDir

        if not os.path.exists(targetDir):
            os.makedirs(targetDir)

        cs = ChannelSeparator()
        cs.setId(path)
        bf = BFVirtualStack(path, cs, False, False, False)
        for sliceIndex in xrange(1,bf.getSize() + 1):
            print "Processing slice", sliceIndex
            ip = bf.getProcessor(sliceIndex)
            sliceFileName = os.path.join(targetDir, "T=" + str(sliceIndex) + ".tif")
            FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
Пример #5
0
def dimensionsOf(path):
    fr = None
    try:
        fr = ChannelSeparator()
        fr.setGroupFiles(False)
        fr.setId(path)
        return fr.getSizeX(), fr.getSizeY()
    except:
        print sys.exc_info()
    finally:
        fr.close()
def bit_tester(image_name):
    ## gets the number of bits for an image, error if not 8 or 16 bit. ##
    dest = IJ.getDirectory("image")
    filepath = dest + image_name
    fr = ChannelSeparator()
    fr.setId(filepath)
    bitDepth = fr.getBitsPerPixel()
    if int(bitDepth) in (8, 16):
        if int(bitDepth) == 8:
            bit_depth = 2**(bitDepth)-1
        if int(bitDepth) == 16:
            bit_depth = 2**(bitDepth)-1
        return bit_depth
    elif int(bitDepth) not in (8, 16):
        print("Error image is not 8 or 16 bit")
        quit()
Пример #7
0
def run():
	# Chose a file to open
	od = OpenDialog("Chose File to Split", None)
	srcDir = od.getDirectory()
	if srcDir is None:
		# User canceled dialog
		return
	path = os.path.join(srcDir, od.getFileName())
	# Chose a directory to store each slice as a file
	targetDir = DirectoryChooser("Chose folder in which to save").getDirectory()
	if targetDir is None:
		# User canceled the diolog
		return
	# Ready:
	cs = ChannelSeparator()
	cs.setId(path)
	bf = BFVirtualStack(path, cs, False, False, False)
	for sliceIndex in xrange(1,bf.getSize() +1):
		print "Well done. Processing slice", sliceIndex
		ip = bf.getProcessor(sliceIndex)
		sliceFileName = os.path.join(targetDir, str(sliceIndex) + ".tif")
		FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
Пример #8
0
def run():
    # Choose a file to open
    od = OpenDialog("Choose multi-image file", None)
    srcDir = od.getDirectory()
    if srcDir is None:
        # User canceled the dialog
        return
    path = os.path.join(srcDir, od.getFileName())
    # Choose a directory to store each slice as a file
    targetDir = DirectoryChooser("Choose target directory").getDirectory()
    if targetDir is None:
        # User canceled the dialog
        return
    # Ready:
    cs = ChannelSeparator()
    cs.setId(path)
    print "cs", cs
    bf = BFVirtualStack(path, cs, False, False, False)
    for sliceIndex in xrange(1, bf.getSize() + 1):
        print "Processing slice", sliceIndex
        ip = bf.getProcessor(sliceIndex)
        sliceFileName = os.path.join(targetDir, str(sliceIndex) + ".tif")
        FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
from loci.formats import ChannelSeparator
import os, sys

# Read the dimensions of the image at path by parsing the file header only,
# thanks to the LOCI Bioformats library

filepath = "/home/albert/Desktop/t2/bat-cochlea-volume.tif"

try:
    fr = ChannelSeparator()
    fr.setGroupFiles(False)
    fr.setId(filepath)
    width, height, nSlices = fr.getSizeX(), fr.getSizeY(), fr.getSizeZ()
    n_pixels = width * height * nSlices
    bitDepth = fr.getBitsPerPixel()
    fileSize = os.path.getsize(filepath)
    headerSize = fileSize - (n_pixels * bitDepth / 8)  # 8 bits in 1 byte
    print "Dimensions:", width, height, nSlices
    print "Bit depth: %i-bit" % bitDepth
    print "Likely header size, in number of bytes:", headerSize
except:
    # Print the error, if any
    print sys.exc_info()
finally:
    fr.close()  # close the file handle safely and always

# For parsing TIFF file headers
from java.io import RandomAccessFile
from java.math import BigInteger

Пример #10
0
	targetDir = os.path.join(srcDir,"sequence\\")
	print targetDir
	if targetDir is None:
		# User canceled the diolog
		return
	if srcDir is None:
		# User canceled dialog
		return
	try:
		os.mkdir(targetDir)
	except Exception, e:
		print "Couldn't make directory:",e
	for f in os.listdir(srcDir):
		path = os.path.join(srcDir, f)
		# Ready:
		cs = ChannelSeparator()
		cs.setId(path)
		bf = BFVirtualStack(path, cs, False, False, False)
		fname = "%06d"%(index-index%200)
		path = os.path.join(targetDir,fname)
		try:
			os.mkdir(path)
		except Exception, e:
			print "Couldn't make directory:",e
		for sliceIndex in xrange(1,bf.getSize() +1):
			print "Well done. Processing slice", sliceIndex
			ip = bf.getProcessor(sliceIndex)
			string = "%06d.tif"%index
			sliceFileName = os.path.join(path, string)
			FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
			index +=1