Пример #1
0
    def doOperation(self):
        """
		Does color merging for the dataset
		"""
        t1 = time.time()
        datasets = []
        alphas = []

        processed = []
        imagelen = len(self.images)
        if not imagelen:
            return None
        self.shift = 0
        self.scale = 0.333
        self.scale /= imagelen

        luminance = 0
        self.shift = 0
        self.scale = 1
        self.merge = vtkbxd.vtkImageColorMerge()
        self.merge.AddObserver("ProgressEvent", lib.messenger.send)
        lib.messenger.connect(self.merge, 'ProgressEvent', self.updateProgress)

        if self.doAlpha:
            self.merge.BuildAlphaOn()
            if self.alphaMode[0] == 0:
                Logging.info("Alpha mode = maximum", kw="processing")
                self.merge.MaximumModeOn()
            elif self.alphaMode[0] == 1:
                Logging.info("Alpha mode = average, threshold = ",
                             self.alphaMode[1],
                             kw="processing")
                self.merge.AverageModeOn()
                self.merge.SetAverageThreshold(self.alphaMode[1])
            elif self.alphaMode[0] == 2:
                self.merge.LuminanceModeOn()
                Logging.info("Alpha mode = luminance", kw="processing")
            else:
                self.merge.BuildAlphaOff()
        else:
            self.merge.BuildAlphaOff()

        images = lib.ImageOperations.castImagesToLargestDataType(self.images)
        for i, image in enumerate(images):
            self.merge.AddInput(image)
            self.merge.AddLookupTable(self.ctfs[i])
            if self.intensityTransferFunctions[i] != None:
                self.merge.AddIntensityTransferFunction(
                    self.intensityTransferFunctions[i])

        #data = self.getLimitedOutput(self.merge)

        data = self.merge.GetOutput()

        t3 = time.time()
        Logging.info("Merging took %.4f seconds" % (t3 - t1), kw="processing")
        #lib.messenger.send(None, "update_progress", 100, "Done.")

        #data.GlobalReleaseDataFlagOn()
        return data
    def doOperation(self):
        """
		Does color merging for the dataset
		"""
        t1 = time.time()
        datasets = []
        alphas = []

        processed = []
        imagelen = len(self.images)
        if not imagelen:
            return None
        self.shift = 0
        self.scale = 0.333
        self.scale /= imagelen

        luminance = 0
        self.shift = 0
        self.scale = 1
        self.merge = vtkbxd.vtkImageColorMerge()
        self.merge.AddObserver("ProgressEvent", lib.messenger.send)
        lib.messenger.connect(self.merge, "ProgressEvent", self.updateProgress)

        if self.doAlpha:
            self.merge.BuildAlphaOn()
            if self.alphaMode[0] == 0:
                Logging.info("Alpha mode = maximum", kw="processing")
                self.merge.MaximumModeOn()
            elif self.alphaMode[0] == 1:
                Logging.info("Alpha mode = average, threshold = ", self.alphaMode[1], kw="processing")
                self.merge.AverageModeOn()
                self.merge.SetAverageThreshold(self.alphaMode[1])
            elif self.alphaMode[0] == 2:
                self.merge.LuminanceModeOn()
                Logging.info("Alpha mode = luminance", kw="processing")
            else:
                self.merge.BuildAlphaOff()
        else:
            self.merge.BuildAlphaOff()

        images = lib.ImageOperations.castImagesToLargestDataType(self.images)
        for i, image in enumerate(images):
            self.merge.AddInput(image)
            self.merge.AddLookupTable(self.ctfs[i])
            if self.intensityTransferFunctions[i] != None:
                self.merge.AddIntensityTransferFunction(self.intensityTransferFunctions[i])

            # data = self.getLimitedOutput(self.merge)

        data = self.merge.GetOutput()

        t3 = time.time()
        Logging.info("Merging took %.4f seconds" % (t3 - t1), kw="processing")
        # lib.messenger.send(None, "update_progress", 100, "Done.")

        # data.GlobalReleaseDataFlagOn()
        return data
Пример #3
0
r1 = vtkbxd.vtkLSMReader()
r1.SetFileName(D)
r1.SetUpdateChannel(0)

d1 = r1.GetOutput()

itf1 = vtkbxd.vtkIntensityTransferFunction()
itf1.SetBrightness(50.0)

ctf1 = vtkbxd.vtkColorTransferFunction()
ctf1.AddRGBPoint(0, 0, 0, 0)
ctf1.AddRGBPoint(255.0, 0, 1.0, 0)

print "Feeding channels to merge ", elapsed()
merge = vtkbxd.vtkImageColorMerge()
#merge.SetNumberOfThreads(5)
merge.AddInput(d1)
merge.AddLookupTable(ctf1)
merge.AddIntensityTransferFunction(itf1)

itfmap = vtkbxd.vtkImageMapToIntensities()
itfmap.SetInput(d1)
itfmap.SetIntensityTransferFunction(itf1)

maptocolor = vtk.vtkImageMapToColors()
maptocolor.SetOutputFormatToRGB()
maptocolor.SetInput(itfmap.GetOutput())
maptocolor.SetLookupTable(ctf1)

mip = vtkbxd.vtkImageSimpleMIP()
Пример #4
0
    def doPreview(self, depth, renew, timePoint=0):
        """
		Makes a two-dimensional preview using the class-specific combination function
		Parameters: depth		The preview depth
					renew		Flag indicating, whether the preview should be 
								regenerated or if a stored image can be reused
					timePoint	The timepoint from which to generate the preview
								Defaults to 0
		"""
        Logging.info("Creating preview", kw="dataunit")
        preview = None
        if timePoint > self.getNumberOfTimepoints():
            timepoint = self.getNumberOfTimepoints() - 1

        self.oldAlphaStatus = scripting.wantAlphaChannel

        if depth == scripting.WHOLE_DATASET_NO_ALPHA:
            scripting.wantAlphaChannel = 0
        # If the previously requested preview was a "show original" preview
        # then we can just restore the preview before that without any
        # processing
        showOrig = self.settings.get("ShowOriginal")

        # If the requested output channels have been specified,
        # then we map those through their corresponding ctf's
        # to be merged to the output
        n = len(self.sourceunits)
        merged = []
        if self.outputChannels:
            for i, unit in enumerate(self.sourceunits):
                if i in self.outputChannels and self.outputChannels[i]:
                    data = unit.getTimepoint(timePoint)
                    merged.append((data, unit.getColorTransferFunction()))

            if n not in self.outputChannels:
                self.outputChannels[n] = 0
        # If either no output channels have been specified (in which case
        # we return just the normal preview) or the combined result
        # (n = last chl+1) has	been requested

        if self.merging or not self.outputChannels or (
                n in self.outputChannels and self.outputChannels[n]):
            # If the renew flag is true, we need to regenerate the preview
            if renew:
                Logging.info("Renewing preview", kw="dataunit")
                # We then tell the module to reset itself and
                # initialize it again
                self.module.reset()
                # Go through all the source datasets for the module
                self.module.setSettings(self.settings)
                self.module.setTimepoint(timePoint)
                images = []

                for dataunit in self.sourceunits:
                    Logging.info("Adding source image data from %d dataunits" %
                                 len(self.sourceunits),
                                 kw="dataunit")
                    image = dataunit.getTimepoint(timePoint)
                    x, y, z = image.GetDimensions()

                    # If a whole volume is requested, but the data is acquired with an update
                    # extent selecting only a single slice, then reset the update extent
                    if depth < 0 and z <= 1:
                        image.SetUpdateExtent(image.GetWholeExtent())
                        image.Update()
                    elif depth >= 0 and not (x or y):
                        # If a dataset has not been updated yet, then set the appropriate
                        # update extent
                        ex0, ex1, ey0, ey1, ez0, ez1 = image.GetWholeExtent()
                        image.SetUpdateExtent(ex0, ex1, ey0, ey1, depth, depth)
                        image.Update()
                    self.module.addInput(dataunit, image)
            Logging.info("Getting preview from module %s" % str(self.module),
                         kw="dataunit")
            preview = self.module.getPreview(depth)
            if type(preview) == types.TupleType:
                preview = preview[0]

        if preview is not None:
            isMultiComponent = preview.GetNumberOfScalarComponents(
            ) > 1  # doesn't work when preview isn't updated
        else:
            isMultiComponent = False

        if not isMultiComponent:
            for unit in self.sourceunits:
                isMultiComponent = unit.getBitDepth(
                ) > unit.getSingleComponentBitDepth()
                if isMultiComponent:
                    break

        if not self.merging and self.outputChannels:
            if preview:
                merged.append((preview, self.getColorTransferFunction()))

            if len(merged) > 1:
                Logging.info("Merging the output channels", kw="dataunit")
                if not self.merge:
                    self.merge = vtkbxd.vtkImageColorMerge()
                else:
                    self.merge.RemoveAllInputs()
                    self.merge.RemoveLookupTables()
                images = [x[0] for x in merged]
                images = lib.ImageOperations.castImagesToLargestDataType(
                    images)
                for i, (data, ctf) in enumerate(merged):
                    image = images[i]
                    self.merge.AddInput(image)
                    self.merge.AddLookupTable(ctf)
                preview = self.merge.GetOutput()

            elif len(merged
                     ) == 1 and scripting.preferRGB and not isMultiComponent:
                Logging.info("Mapping the output to color", kw="dataunit")
                data, ctf = merged[0]
                if not self.maptocolor:
                    self.maptocolor = vtk.vtkImageMapToColors()
                    self.maptocolor.SetNumberOfThreads(1)
                    self.maptocolor.SetOutputFormatToRGB()
                else:
                    self.maptocolor.RemoveAllInputs()
                self.maptocolor.SetInput(data)
                self.maptocolor.SetLookupTable(ctf)
                preview = self.maptocolor.GetOutput()

        scripting.wantAlphaChannel = self.oldAlphaStatus
        if not showOrig and not self.doOrig:
            self.origPreview = preview
        elif showOrig:
            self.doOrig = 1
        return preview
r1.SetFileName(D)
r1.SetUpdateChannel(0)

d1=r1.GetOutput()


itf1=vtkbxd.vtkIntensityTransferFunction()
itf1.SetBrightness(50.0)

ctf1=vtkbxd.vtkColorTransferFunction()
ctf1.AddRGBPoint(0,0,0,0)
ctf1.AddRGBPoint(255.0,0,1.0,0)


print "Feeding channels to merge ",elapsed()
merge = vtkbxd.vtkImageColorMerge()
#merge.SetNumberOfThreads(5)
merge.AddInput(d1)
merge.AddLookupTable(ctf1)
merge.AddIntensityTransferFunction(itf1)

itfmap = vtkbxd.vtkImageMapToIntensities()
itfmap.SetInput(d1)
itfmap.SetIntensityTransferFunction(itf1)

maptocolor=vtk.vtkImageMapToColors()
maptocolor.SetOutputFormatToRGB()
maptocolor.SetInput(itfmap.GetOutput())
maptocolor.SetLookupTable(ctf1)

	def doPreview(self, depth, renew, timePoint = 0):
		"""
		Makes a two-dimensional preview using the class-specific combination function
		Parameters: depth		The preview depth
					renew		Flag indicating, whether the preview should be 
								regenerated or if a stored image can be reused
					timePoint	The timepoint from which to generate the preview
								Defaults to 0
		"""
		Logging.info("Creating preview",kw="dataunit")
		preview = None
		if timePoint > self.getNumberOfTimepoints():
			timepoint = self.getNumberOfTimepoints() - 1
		
		self.oldAlphaStatus = scripting.wantAlphaChannel
		
		if depth == scripting.WHOLE_DATASET_NO_ALPHA:
			scripting.wantAlphaChannel = 0
		# If the previously requested preview was a "show original" preview
		# then we can just restore the preview before that without any
		# processing
		showOrig = self.settings.get("ShowOriginal")

		# If the requested output channels have been specified,
		# then we map those through their corresponding ctf's
		# to be merged to the output
		n = len(self.sourceunits)
		merged = []
		if self.outputChannels:
			for i, unit in enumerate(self.sourceunits):
				if i in self.outputChannels and self.outputChannels[i]:
					data = unit.getTimepoint(timePoint)
					merged.append((data, unit.getColorTransferFunction()))
					
			if n not in self.outputChannels:
				self.outputChannels[n] = 0
		# If either no output channels have been specified (in which case
		# we return just the normal preview) or the combined result
		# (n = last chl+1) has	been requested

		if self.merging or not self.outputChannels or (n in self.outputChannels and self.outputChannels[n]):
			# If the renew flag is true, we need to regenerate the preview
			if renew:
				Logging.info("Renewing preview", kw="dataunit")
				# We then tell the module to reset itself and
				# initialize it again
				self.module.reset()
				# Go through all the source datasets for the module
				self.module.setSettings(self.settings)
				self.module.setTimepoint(timePoint)
				images = []
				
				for dataunit in self.sourceunits:
					Logging.info("Adding source image data from %d dataunits"%len(self.sourceunits), kw = "dataunit")
					image = dataunit.getTimepoint(timePoint)
					x, y, z = image.GetDimensions()
					
					# If a whole volume is requested, but the data is acquired with an update
					# extent selecting only a single slice, then reset the update extent
					if depth < 0 and z <= 1:
						image.SetUpdateExtent(image.GetWholeExtent())
						image.Update()
					elif depth >= 0 and not (x or y):
						# If a dataset has not been updated yet, then set the appropriate
						# update extent
						ex0, ex1, ey0, ey1, ez0, ez1 = image.GetWholeExtent()
						image.SetUpdateExtent(ex0, ex1, ey0, ey1, depth, depth)
						image.Update()
					self.module.addInput(dataunit, image)
			Logging.info("Getting preview from module %s"%str(self.module), kw="dataunit")
			preview = self.module.getPreview(depth)
			if type(preview) == types.TupleType:
				preview = preview[0]

		if preview is not None:
			isMultiComponent = preview.GetNumberOfScalarComponents() > 1 # doesn't work when preview isn't updated
		else:
			isMultiComponent = False
		
		if not isMultiComponent:
			for unit in self.sourceunits:
				isMultiComponent = unit.getBitDepth() > unit.getSingleComponentBitDepth()
				if isMultiComponent:
					break

		if not self.merging and self.outputChannels:
			if preview:
				merged.append((preview, self.getColorTransferFunction()))
			
			if len(merged) > 1:
				Logging.info("Merging the output channels", kw="dataunit")
				if not self.merge:
					self.merge = vtkbxd.vtkImageColorMerge()
				else:
					self.merge.RemoveAllInputs()
					self.merge.RemoveLookupTables()
				images = [x[0] for x in merged]
				images = lib.ImageOperations.castImagesToLargestDataType(images)
				for i, (data, ctf) in enumerate(merged):
					image = images[i]
					self.merge.AddInput(image)
					self.merge.AddLookupTable(ctf)
				preview = self.merge.GetOutput()
				
			elif len(merged) == 1 and scripting.preferRGB and not isMultiComponent:
				Logging.info("Mapping the output to color",kw="dataunit")
				data, ctf = merged[0]
				if not self.maptocolor:
					self.maptocolor = vtk.vtkImageMapToColors()
					self.maptocolor.SetNumberOfThreads(1)
					self.maptocolor.SetOutputFormatToRGB()
				else:
					self.maptocolor.RemoveAllInputs()
				self.maptocolor.SetInput(data)
				self.maptocolor.SetLookupTable(ctf)
				preview = self.maptocolor.GetOutput()
				
		scripting.wantAlphaChannel = self.oldAlphaStatus
		if not showOrig and not self.doOrig:
			self.origPreview = preview
		elif showOrig:
			self.doOrig = 1
		return preview