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()
예제 #2
0
파일: Cover_Maker.py 프로젝트: Cersad/fiji
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()
예제 #4
0
파일: Cover_Maker.py 프로젝트: Cersad/fiji
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()
예제 #5
0
# make a gradient image

ip = screenshot.getProcessor()
w = ip.getWidth()
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)
예제 #6
0
파일: plot.py 프로젝트: mwinding/scripts
def chartAsImagePlus(chart, frame):
    """ Given a JFreeChart and its JFrame, return an ImagePlus of type COLOR_RGB. """
    panel = frame.getContentPane().getComponent(0)  # a ChartPanel
    dimensions = panel.getSize()
    bimg = chart.createBufferedImage(dimensions.width, dimensions.height)
    return ImagePlus(str(chart.getTitle()), ColorProcessor(bimg))
예제 #7
0
# Open the Drosophila larval brain sample RGB image stack
#imp = IJ.openImage("https://samples.imagej.net/samples/first-instar-brain.zip")
imp = IJ.getImage()
stack1 = imp.getStack()  # of ColorProcessor

# Scale up by 1.5x
scale = 1.5
model = AffineModel2D()
model.set(scale, 0, 0, scale, 0, 0)
# An arbitrary affine, obtained from Plugins - Transform - Interactive Affine (push enter key to print it)
#model.set(1.16, 0.1484375, -0.375, 1.21875, 38.5, -39.5)

# New stack, larger
stack2 = ImageStack(int(imp.getWidth() * scale), int(imp.getHeight() * scale))
for index in xrange(1, stack1.getSize() + 1):
    stack2.addSlice(ColorProcessor(stack2.getWidth(), stack2.getHeight()))
imp2 = ImagePlus("larger (push)", stack2)

# Map data from stack to stack2 using the model transform
position = zeros(2, 'd')
"""

# First approach: push (WRONG!)
width1, height1 = stack1.getWidth(), stack1.getHeight()

for index in xrange(1, 3): #stack1.size() + 1):
  cp1 = stack1.getProcessor(index)
  cp2 = stack2.getProcessor(index)
  for y in xrange(height1):
    for x in xrange(width1):
      position[1] = y
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
예제 #9
0
from ij.process import ColorProcessor
from java.awt.image import BufferedImage as BI
from java.lang import Thread

f = ImagePlus.getDeclaredField("listeners")
f.setAccessible(True)
listeners = f.get(None)

imp = IJ.getImage()
canvas = imp.getWindow().getCanvas()

# Define range of slices to capture
slices = xrange(1, imp.getNSlices() + 1)

w, h = canvas.getWidth(), canvas.getHeight()

capture = ImageStack(w, h)

for i in slices:
  imp.setSlice(i)
  for l in listeners:
    l.imageUpdated(imp)
  Thread.sleep(50) # wait for repaints to happen, triggered by listeners, if any.
  bi = BI(w, h, BI.TYPE_INT_ARGB)
  g = bi.createGraphics()
  canvas.paint(g)
  g.dispose()
  capture.addSlice(ColorProcessor(bi))
  bi.flush()

ImagePlus("capture", capture).show()
예제 #10
0
파일: Cover_Maker.py 프로젝트: Cersad/fiji
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
# # print 'fitGoodness', cv.getFitGoodness()
# # print 'formula', cv.getFormula()
# # fit_params = cv.getParams()
# # print 'fit_params', fit_params

# print all_pc
# print 'mean_cc', sum(all_pc)/len(all_pc)

# Create the 2D visualization of the fit plots
stack_w, stack_h = plot_images[0].getWidth(), plot_images[0].getHeight()
stack_plot = ImageStack(stack_w, stack_h)

# add all the plots in a stack
for id, plot_image in enumerate(plot_images):
    for i in range(HEXAGON_SPACINGS[id]):
        stack_plot.addSlice(
            'plot_' + str(id).zfill(2),
            ImagePlus('empty', ColorProcessor(stack_w,
                                              stack_h)).getProcessor())
    stack_plot.addSlice('plot_' + str(id).zfill(2), plot_image.getProcessor())

imp = ImagePlus('Plot_stack', stack_plot)

montageMaker = MontageMaker()
montage = montageMaker.makeMontage2(imp, 17, 9, 1, 1, imp.getNSlices(), 1, 3,
                                    False)

IJ.save(montage, fit_montage_path)

montage.show()
IJ.log('Done')