Beispiel #1
0
def createContainer(roi, imgA, imgB):
	rect = roi.getBounds()
	ipmask = roi.getMask()
	offset = [rect.x, rect.y]
	size = [rect.width, rect.height]
	if (ipmask != None):
		ipslice = ipmask.createProcessor(imgA.getWidth(), imgA.getHeight())
		ipslice.setValue(0.0)
		ipslice.fill()
		ipslice.copyBits(ipmask, rect.x, rect.y, Blitter.COPY)
		impmask = ImagePlus("Mask", ipslice)
		ipamask = ImagePlusAdapter.wrap(impmask)
		container = DataContainer(imgA, imgB, 1, 1, "imageA", "imageB", ipamask, offset, size)
	else:
		container = DataContainer(imgA, imgB, 1, 1, "imageA", "imageB", offset, size)

	return container
Beispiel #2
0
	def getContainer(self, impA, impB):
		imgA = ImagePlusAdapter.wrap(impA)
		imgB = ImagePlusAdapter.wrap(impB)
		return DataContainer(imgA, imgB, 1, 1, "imageA", "imageB")
Beispiel #3
0
from ij import WindowManager
from ij import IJ
from net.imglib2.img import ImagePlusAdapter
from net.imglib2.img.display.imagej import ImageJFunctions
from fiji.process import Image_Expression_Parser
from spimopener import Rename
from ij import measure
listt = []
listt_2 = []
for i in range(0, 3):
    listt.append(WindowManager.getImage(i + 1))
    listt_2.append(ImagePlusAdapter.wrap(listt[i]))
map = {'A': listt_2[0], 'B': listt_2[1], 'C': listt_2[2]}
expression = '(A+B+C)/3'
# Instantiate plugin
parser = Image_Expression_Parser()
# Configure & execute
parser.setImageMap(map)
parser.setExpression(expression)
parser.process()
result = parser.getResult()  # is an ImgLib image

result_imp = ImageJFunctions.show(result)
IJ.run('Rename...', 'title=AverageIMG')
result_img = ImagePlusAdapter.wrap(result_imp)
mean_average = result_imp.getStatistics()
mean_average = mean_average.mean
scaled_list = []
for i in range(0, 3):
    imp = listt[i]
    img = listt_2[i]
Beispiel #4
0
	except UnknownFormatException:
		continue
	preview = getPreview(image)
	preview.show()
	rm = RoiManager()
	dialog = WaitForUserDialog("Action required", "Please select regions of interest in this image. Click OK when done.")
	dialog.show()
	rm.close()
	splitter = ChannelSplitter()
	imp1 = ImagePlus("CH1", splitter.getChannel(image, imageA))
	imp2 = ImagePlus("CH2", splitter.getChannel(image, imageB))
	title = image.getTitle()
	title = title[:title.rfind('.')]
	image.close()
	preview.close()
	ch1 = ImagePlusAdapter.wrap(imp1)
	ch2 = ImagePlusAdapter.wrap(imp2)

	for roi in rm.getRoisAsArray():
		container = createContainer(roi, ch1, ch2)
		img1 = container.getSourceImage1()
		img2 = container.getSourceImage2()
		mask = container.getMask()
		
		thr1, thrimp1 = calculateThreshold(imp1, roi, methods[0])
		thr2, thrimp2 = calculateThreshold(imp2, roi, methods[1])
		
		cursor = TwinCursor(img1.randomAccess(), img2.randomAccess(), Views.iterable(mask).localizingCursor())
		rtype = img1.randomAccess().get().createVariable()
		raw = manders.calculateMandersCorrelation(cursor, rtype)
		rthr1 = rtype.copy()
        this_file_name = os.path.realpath( inspect.getfile( lambda : None ) ) # inspect.getfile requires method, class, ... as input and returns the file in which input was defined
        shutil.copyfile( this_file_name, '%s/%s' % ( home.rstrip('/'), this_file_name.split('/')[-1] ) )
        

             
             
        start = 1
        stop  = img.getStack().getSize()
        if False and stackMin != None:
            start = stackMin
        if False and stackMax != None:
            stop  = stackMax
        startingCoordinates = range( start - 1, stop )

        wrappedImage = ImagePlusAdapter.wrap( img )
        radii  = [ [ width, height ], [ 50, 50 ], [ 20, 20 ], [ 7, 7 ], [ 7, 7 ] ] #,[ 75, 75 ] ]#, [ 30, 30 ], [ 15, 15 ], [ 7, 7 ] ]#, [ 15, 15 ] ]
        steps  = [ [ width, height ], [ 50, 50 ], [ 20, 20 ], [ 7, 7 ], [ 1, 1 ] ] #,[ 75, 75 ] ]#, [ 30, 30 ], [ 15, 15 ], [ 3, 3 ] ]#, [ 1, 1 ] ]
        ranges = [ int( scaleZBy*max(x) ) for x in radii ]
        opt = [options]
        ratio = 1.0
        for idx in xrange(len(radii)-1):
            tmpOptions = options2.clone()
            tmpOptions.windowRange = int( opt[idx].windowRange * ratio )
            opt.append( tmpOptions )
        # opt    = [ options, options2, options2, options2, options2 ]#, options2 ]

        visitor = ListMultiScaleVisitor( ArrayList() )

        bp = home.rstrip('/') + '/transformed/%02d.tif'
        imageVisitor = RenderImageMultiScaleVisitor( wrappedImage, bp )
            # ImagePlus("", ip2a).show()
            
            imp1a = ImagePlus("%s" % patch, Filter.scale(ip1a, scaleFactor))
            imp1b = ImagePlus("%s" % overlays[patch], ip1b.resize(Math.round( scaleFactor*ip1b.getWidth() ), Math.round( scaleFactor*ip1b.getHeight() ) ) )
            imp2a = ImagePlus("%s" % match[0], Filter.scale(ip2a, scaleFactor))
            imp2b = ImagePlus("%s" % overlays[match[0]], ip2b.resize(Math.round( scaleFactor*ip2b.getWidth() ), Math.round( scaleFactor*ip2b.getHeight() ) ) ) 

            # show images for debugging purposes
            # imp1a.show()
            # imp1b.show()
            # imp2a.show()
            # imp2b.show()

            

            img1a = ImagePlusAdapter.wrap(imp1a)
            img1b = ImagePlusAdapter.wrap(imp1b)
            img2a = ImagePlusAdapter.wrap(imp2a)
            img2b = ImagePlusAdapter.wrap(imp2b)

            pointMatchGenerator.generate(img1a, img2a, img1b, img2b)
            pointHashMap = pointMatchGenerator.getPointMatches()

            for entryset in pointHashMap.entrySet():
                pointMatches = entryset.getValue()

                # connect tile at patch/grid position to tile at match/grid position with appropriate pointMatches
                # remove outliers first (ransac)

                pairWiseModel = AffineModel1D()
                inliers       = ArrayList()