def getManders(self, imp, cell): ### Crop channels according to cell mask channels = self.getCroppedChannels(imp, cell) if channels is None: return None ### Calculate channel thresholds thrs = [] thrimps = [] for c, method in enumerate(self.methods): if method != "None": thr, thrimp = self.getThreshold(channels[c], method) else: thr, thrimp = None, None thrs.append(thr) thrimps.append(thrimp) ### Calculate manders colocalization manders = MandersColocalization() raws = [] thrds = [] for chA, chB in self.pairs: container = self.getContainer(channels[chA - 1], channels[chB - 1]) img1 = container.getSourceImage1() img2 = container.getSourceImage2() mask = container.getMask() cursor = TwinCursor(img1.randomAccess(), img2.randomAccess(), Views.iterable(mask).localizingCursor()) rtype = img1.randomAccess().get().createVariable() raw = manders.calculateMandersCorrelation(cursor, rtype) rthr1 = rtype.copy() rthr2 = rtype.copy() rthr1.set(thrs[chA - 1]) rthr2.set(thrs[chB - 1]) cursor.reset() thrd = manders.calculateMandersCorrelation(cursor, rthr1, rthr2, ThresholdMode.Above) raws.append(raw) thrds.append(thrd) return (channels, thrimps, thrs, raws, thrds)
projector = ZProjector() splitter = ChannelSplitter() imp1 = ImagePlus("CH1", ) width, height, channels, slices, frames = image.getDimensions() chimps = [] for ch in range(1, channels + 1): projector = ZProjector(ImagePlus("C%i" % ch, splitter.getChannel(image, ch))) projector.setMethod(ZProjector.MAX_METHOD) projector.doProjection() proj = projector.getProjection() enhancer.equalize(proj) chimps.append(proj) return RGBStackMerge.mergeChannels(chimps, False) manders = MandersColocalization() results = ResultsTable() for imageFile in os.listdir(inputDir): print "Opening " + imageFile try: images = BF.openImagePlus(inputDir + imageFile) image = images[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()