def SaveCoverFromFs(tiles, newwidth, newheight, cols, rows):

    tilewidth = int(newwidth / cols)
    tileheight = int(newheight / rows)

    newwidth = int(newwidth / tilewidth) * tilewidth
    newheight = int(newheight / tileheight) * tileheight

    hiresoutip = ColorProcessor(newwidth, newheight)
    hiresout = ImagePlus("hi res output", hiresoutip)
    hiresout.show()

    x = 0
    y = -1

    plane = []

    # scale the images
    for i in sorted(tiles.iterkeys()):
        if y < rows - 1:
            y += 1
        else:
            y = 0
            x += 1
        imp = IJ.openImage(str(tiles[i]))
        scale = Scale(imp.getProcessor())
        ipscaled = ScaleImageToSize(scale, tilewidth, tileheight)
        hiresoutip.copyBits(ipscaled, x * tilewidth, y * tileheight, 0)
        hiresout.draw()
Ejemplo n.º 2
0
def SaveCoverFromFs(tiles, newwidth, newheight, cols, rows):

	tilewidth = int(newwidth/cols)
	tileheight = int(newheight/rows)

	newwidth = int(newwidth/tilewidth) * tilewidth
	newheight = int(newheight/tileheight) * tileheight

	hiresoutip = ColorProcessor(newwidth, newheight)
	hiresout = ImagePlus("hi res output", hiresoutip)
	hiresout.show()

	x = 0
	y = -1

	plane = []

	# scale the images
	for i in sorted(tiles.iterkeys()):
		if y < rows-1:
			y += 1
		else:
			y = 0
			x += 1
		imp = IJ.openImage(str(tiles[i]))
		scale = Scale(imp.getProcessor())
		ipscaled = ScaleImageToSize(scale, tilewidth, tileheight)
		hiresoutip.copyBits(ipscaled, x*tilewidth, y*tileheight, 0)
		hiresout.draw()
def SaveCoverFromZip(tileIndex, newwidth, newheight, cols, rows,
                     originalspath):
    baseDir = re.sub(r'\/originals.zip', "", originalspath)

    #print baseDir

    zf = zipfile.ZipFile(originalspath, mode='r')

    tilewidth = int(newwidth / cols)
    tileheight = int(newheight / rows)

    newwidth = int(newwidth / tilewidth) * tilewidth
    newheight = int(newheight / tileheight) * tileheight

    hiresoutip = ColorProcessor(newwidth, newheight)
    hiresout = ImagePlus("hi res output", hiresoutip)
    hiresout.show()

    x = 0
    y = -1

    plane = []

    # scale the images
    for i in sorted(tileIndex.iterkeys()):
        if y < rows - 1:
            y += 1
        else:
            y = 0
            x += 1
        #bi = bir.openImage(tileIndex[i]);
        #ip = ColorProcessor(bi)
        image = zf.read(str(tileIndex[i]) + ".jpeg")
        #IJ.log("Placing image :" + str(tileIndex[i]) + ".jpeg")
        my_file = open(baseDir + 'temporary.jpeg', 'w')
        my_file.write(image)
        my_file.close()
        imp = IJ.openImage(baseDir + "/temporary.jpeg")
        ip = imp.getProcessor()
        scale = Scale(ip)
        ipscaled = ScaleImageToSize(scale, tilewidth, tileheight)
        hiresoutip.copyBits(ipscaled, x * tilewidth, y * tileheight, 0)
        hiresout.draw()
Ejemplo n.º 4
0
def SaveCoverFromZip(tileIndex, newwidth, newheight, cols, rows, originalspath):
	baseDir = re.sub(r'\/originals.zip', "", originalspath)

	#print baseDir

	zf = zipfile.ZipFile(originalspath, mode='r')

	tilewidth = int(newwidth/cols)
	tileheight = int(newheight/rows)

	newwidth = int(newwidth/tilewidth) * tilewidth
	newheight = int(newheight/tileheight) * tileheight

	hiresoutip = ColorProcessor(newwidth, newheight)
	hiresout = ImagePlus("hi res output", hiresoutip)
	hiresout.show()

	x = 0
	y = -1

	plane = []

	# scale the images
	for i in sorted(tileIndex.iterkeys()):
		if y < rows-1:
			y += 1
		else:
			y = 0
			x += 1
		#bi = bir.openImage(tileIndex[i]);
		#ip = ColorProcessor(bi)
		image = zf.read(str(tileIndex[i]) + ".jpeg")
		#IJ.log("Placing image :" + str(tileIndex[i]) + ".jpeg")
		my_file = open(baseDir + 'temporary.jpeg','w')
		my_file.write(image)
		my_file.close()
		imp = IJ.openImage(baseDir + "/temporary.jpeg")
		ip = imp.getProcessor()
		scale = Scale(ip)
		ipscaled = ScaleImageToSize(scale, tilewidth, tileheight)
		hiresoutip.copyBits(ipscaled, x*tilewidth, y*tileheight, 0)
		hiresout.draw()
Ejemplo n.º 5
0
h = ip.getHeight()

u = int(0.99 * 255)
l = int(0.5 * 255)

def gray2rgb(value):
	return (value << 16) | (value << 8) | value

# This is a trick: make a 1xh image (because calculation is slow in Python) and resize it to wxh
from jarray import array
maskPixels = array([gray2rgb(int(u + (l + 1 - u) * i / (h))) for i in range(0, h)], 'i')
mask = ColorProcessor(1, h, maskPixels).resize(w, h)

# "blend" mask with original image

mask.copyBits(ip, 0, 0, Blitter.MAX)
mask.flipVertical()

# instantiate the 3D viewer

univ = Image3DUniverse()
univ.show()

# add the images

cImage = univ.addOrthoslice(ImagePlus("screenshot", ip), \
		None, "image", 0, [1, 1, 1], 1)
dy = -int(h/8)
cImage.setTransform(Transform3D([1.0, 0.0, 0.0, 0.0, \
		0.0, 1.0, 0.0, dy, \
		0.0, 0.0, 1.0, 0.0, \
def CreateCover(ip, width, height, dbpath):
    # split input image into appropriate tiles
    stackt = SplitImage(ip, width, height)
    impt = ImagePlus("template", stackt)
    nSlicestmp = impt.getNSlices()

    # open the preprocessed database
    print dbpath
    impd = IJ.openImage(dbpath)
    stackd = impd.getImageStack()
    nSlicesdb = impd.getNSlices()

    #associate index with image names
    imageNames = impd.getProperty('Info')
    imageList = imageNames.split(';')

    # set up preview output
    outputip = ColorProcessor(ip.width, ip.height)
    outputimp = ImagePlus("output", outputip)
    outputimp.show()

    cols = ip.width / width
    rows = ip.height / height

    print str(cols) + "," + str(rows)

    x = 0
    y = 0

    arrays = [None, None]  # a list of two elements
    cruncher = Inline(arrays)
    tileNames = {}
    tileIndex = {}
    placed = {}
    used = {}

    while len(placed) < nSlicestmp:
        randomTileIndex = random.randint(1, nSlicestmp)
        if randomTileIndex in placed:
            continue
        # transform to row adn column coordinate
        if randomTileIndex % rows == 0:
            y = rows - 1
            x = (randomTileIndex / rows) - 1
        else:
            y = (randomTileIndex % rows) - 1
            x = int(randomTileIndex / rows)

        pixelst = stackt.getPixels(randomTileIndex)
        minimum = Float.MAX_VALUE
        #iterate through database images
        j = 1
        indexOfBestMatch = 0
        arrays[0] = pixelst
        while j < nSlicesdb:
            if j in used:
                j += 1
                continue
            arrays[1] = stackd.getPixels(j)
            diff = cruncher.call()
            if diff < minimum:
                minimum = diff
                indexOfBestMatch = j
            j += 1
        ip = stackd.getProcessor(indexOfBestMatch)
        outputip.copyBits(ip, x * width, y * height, 0)
        used[indexOfBestMatch] = 1
        tileNames[randomTileIndex] = imageList[indexOfBestMatch - 1]
        tileIndex[randomTileIndex] = indexOfBestMatch - 1
        outputimp.draw()
        placed[randomTileIndex] = 1

    return tileNames, tileIndex, cols, rows
Ejemplo n.º 7
0
def CreateCover(ip, width, height, dbpath):
	# split input image into appropriate tiles
	stackt = SplitImage(ip, width, height)
	impt = ImagePlus("template", stackt)
	nSlicestmp = impt.getNSlices()

	# open the preprocessed database
	print dbpath
	impd = IJ.openImage(dbpath)
	stackd = impd.getImageStack()
	nSlicesdb = impd.getNSlices()

	#associate index with image names
	imageNames = impd.getProperty('Info')
	imageList = imageNames.split(';')

	# set up preview output
	outputip = ColorProcessor(ip.width, ip.height)
	outputimp = ImagePlus("output", outputip)
	outputimp.show()

	cols = ip.width/width
	rows = ip.height/height

	print str(cols) + "," + str(rows)

	x = 0
	y = 0

	arrays = [None, None] # a list of two elements
	cruncher = Inline(arrays)
	tileNames = {}
	tileIndex = {}
	placed = {}
	used = {}

	while len(placed) < nSlicestmp:
		randomTileIndex = random.randint(1, nSlicestmp)
		if randomTileIndex in placed:
			continue
		# transform to row adn column coordinate
		if randomTileIndex%rows == 0:
			y = rows-1
			x = (randomTileIndex/rows)-1
		else:
			y = (randomTileIndex%rows)-1
			x = int(randomTileIndex/rows)

		pixelst = stackt.getPixels(randomTileIndex)
		minimum = Float.MAX_VALUE
		#iterate through database images
		j = 1
		indexOfBestMatch = 0
		arrays[0] = pixelst
		while j < nSlicesdb:
			if j in used:
				j +=1
				continue
			arrays[1] = stackd.getPixels(j)
			diff = cruncher.call()
			if diff < minimum:
				minimum = diff
				indexOfBestMatch = j
			j += 1
		ip = stackd.getProcessor(indexOfBestMatch)
		outputip.copyBits(ip, x*width, y*height, 0)
		used[indexOfBestMatch] = 1
		tileNames[randomTileIndex] = imageList[indexOfBestMatch-1]
		tileIndex[randomTileIndex] = indexOfBestMatch-1
		outputimp.draw()
		placed[randomTileIndex] = 1

	return tileNames, tileIndex, cols, rows