本文整理汇总了Python中vtk.vtkImageShiftScale函数的典型用法代码示例。如果您正苦于以下问题:Python vtkImageShiftScale函数的具体用法?Python vtkImageShiftScale怎么用?Python vtkImageShiftScale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkImageShiftScale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Execute
def Execute(self):
if self.Image == None:
self.PrintError('Error: No input image.')
if self.MapRanges:
if self.InputRange == [0.0,0.0]:
self.InputRange = self.Image.GetScalarRange()
if self.InputRange[1] == self.InputRange[0]:
self.PrintError('Error: Input range has zero width. Cannot map values')
self.Shift = -self.InputRange[0]
self.Scale = (self.OutputRange[1] - self.OutputRange[0]) / (self.InputRange[1] - self.InputRange[0])
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInput(self.Image)
shiftScale.SetShift(self.Shift)
shiftScale.SetScale(self.Scale)
if self.OutputType == 'double':
shiftScale.SetOutputScalarTypeToDouble()
elif self.OutputType == 'uchar':
shiftScale.SetOutputScalarTypeToUnsignedChar()
elif self.OutputType == 'char':
shiftScale.SetOutputScalarTypeToChar()
elif self.OutputType == 'ushort':
shiftScale.SetOutputScalarTypeToUnsignedShort()
elif self.OutputType == 'short':
shiftScale.SetOutputScalarTypeToShort()
elif self.OutputType == 'ulong':
shiftScale.SetOutputScalarTypeToUnsignedLong()
elif self.OutputType == 'long':
shiftScale.SetOutputScalarTypeToLong()
elif self.OutputType == 'uint':
shiftScale.SetOutputScalarTypeToUnsignedInt()
elif self.OutputType == 'int':
shiftScale.SetOutputScalarTypeToInt()
elif self.OutputType == 'float':
shiftScale.SetOutputScalarTypeToFloat()
if self.OutputType != 'unchanged':
if self.ClampOverflowOn:
shiftScale.ClampOverflowOn()
shiftScale.ClampOverflowOff()
shiftScale.Update()
self.Image = shiftScale.GetOutput()
if self.MapRanges and self.OutputRange[0] != 0.0:
shiftScale2 = vtk.vtkImageShiftScale()
shiftScale2.SetInput(self.Image)
shiftScale2.SetShift(self.OutputRange[0])
shiftScale2.SetScale(1.0)
shiftScale2.Update()
self.Image = shiftScale2.GetOutput()
示例2: __init__
def __init__(self, comedi, cfg_dict):
self._comedi = comedi
self._cfg = cfg_dict
# we'll store our local bindings here
self._d1 = None
self._d2m = None
self._conf = None
self._cmap_range = [-1024, 3072]
self._cmap_type = CMAP_BLUE_TO_YELLOW_PL
# color scales thingy
self._color_scales = vtk_kit.color_scales.ColorScales()
# instantiate us a slice viewer
rwi,ren = comedi.get_compvis_vtk()
self._sv = comedi_utils.CMSliceViewer(rwi, ren)
# now make our own MapToColors
ct = 32
lut = self._sv.ipws[0].GetLookupTable()
self._cmaps = [vtktudoss.vtkCVImageMapToColors() for _ in range(3)]
for i,cmap in enumerate(self._cmaps):
cmap.SetLookupTable(lut)
cmap.SetConfidenceThreshold(ct)
self._sv.ipws[i].SetColorMap(cmap)
self._set_confidence_threshold_ui(ct)
comedi.sync_slice_viewers.add_slice_viewer(self._sv)
# now build up the VTK pipeline #############################
# we'll use these to scale data between 0 and max.
self._ss1 = vtk.vtkImageShiftScale()
self._ss1.SetOutputScalarTypeToShort()
self._ss2 = vtk.vtkImageShiftScale()
self._ss2.SetOutputScalarTypeToShort()
# we have to cast the confidence to shorts as well
self._ssc = vtk.vtkImageShiftScale()
self._ssc.SetOutputScalarTypeToShort()
self._iac = vtk.vtkImageAppendComponents()
# data1 will form the context
self._iac.SetInput(0, self._ss1.GetOutput())
# subtraction will form the focus
self._iac.SetInput(1, self._ss2.GetOutput())
# third input will be the confidence
self._iac.SetInput(2, self._ssc.GetOutput())
# event bindings ############################################
self._bind_events()
示例3: SetupTextureMapper
def SetupTextureMapper(self):
if not self.GetInput():
return
mapper3D = vtk.vtkVolumeTextureMapper3D.SafeDownCast(self.__VolumeTextureMapper)
if mapper3D and not self.GetRenderWindow().GetNeverRendered():
if not mapper3D.IsRenderSupported(self.__VolumeProperty):
# try the ATI fragment program implementation
mapper3D.SetPreferredMethodToFragmentProgram()
if not mapper3D.IsRenderSupported(self.__VolumeProperty):
print "Warning: 3D texture volume rendering is not supported by your hardware, switching to 2D texture rendering."
newMapper = vtk.vtkVolumeTextureMapper2D()
newMapper.CroppingOn()
newMapper.SetCroppingRegionFlags (0x7ffdfff)
range = self.GetInput().GetScalarRange()
shift = 0 - range[0]
scale = 65535.0 / (range[1]-range[0])
scaler = vtk.vtkImageShiftScale()
scaler.SetInput(self.GetInput())
scaler.SetShift(shift)
scaler.SetScale(scale)
scaler.SetOutputScalarTypeToUnsignedShort()
scaler.Update()
newMapper.SetInput(scaler.GetOutput())
# del scaler
self.__Callback.SetVolumeMapper(newMapper)
self.__VolumeMapper = newMapper
self.__VolumeMapper.SetMapper(newMapper)
示例4: WritePNGImageFile
def WritePNGImageFile(self):
if self.OutputFileName == "":
self.PrintError("Error: no OutputFileName.")
self.PrintLog("Writing PNG image file.")
outputImage = self.Image
if self.Image.GetScalarTypeAsString() != "unsigned char":
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInput(self.Image)
if self.WindowLevel[0] == 0.0:
scalarRange = self.Image.GetScalarRange()
shiftScale.SetShift(-scalarRange[0])
shiftScale.SetScale(255.0 / (scalarRange[1] - scalarRange[0]))
else:
shiftScale.SetShift(-(self.WindowLevel[1] - self.WindowLevel[0] / 2.0))
shiftScale.SetScale(255.0 / self.WindowLevel[0])
shiftScale.SetOutputScalarTypeToUnsignedChar()
shiftScale.ClampOverflowOn()
shiftScale.Update()
outputImage = shiftScale.GetOutput()
writer = vtk.vtkPNGWriter()
writer.SetInput(outputImage)
if self.Image.GetDimensions()[2] == 1:
writer.SetFileName(self.OutputFileName)
else:
writer.SetFilePrefix(self.OutputFileName)
writer.SetFilePattern("%s%04d.png")
writer.Write()
示例5: execute
def execute(self, inputs, update = 0, last = 0):
"""
Execute the filter with given inputs and return the output
"""
if not lib.ProcessingFilter.ProcessingFilter.execute(self, inputs):
return None
image = self.getInput(1)
self.vtkfilter.SetInput(image)
self.vtkfilter.SetConsiderAnisotropy(self.parameters["ConsiderAnisotropy"])
self.vtkfilter.SetAlgorithm(self.parameters["Algorithm"])
data = self.vtkfilter.GetOutput()
if self.parameters["CastToUnsignedChar"]:
self.vtkfilter.Update()
cast = vtk.vtkImageShiftScale()
x0, x1 = data.GetScalarRange()
print data
print "Scalar range=",x0,x1
cast.SetInput(self.vtkfilter.GetOutput())
cast.SetOutputScalarTypeToUnsignedChar()
#cast.SetClampOverflow(1)
cast.SetScale(255.0/x1)
print "Setting scale to ", 255.0/x1
data = cast.GetOutput()
if update:
self.vtkfilter.Update()
return data
示例6: getIntensityScaledData
def getIntensityScaledData(self, data):
"""
Return the data shifted and scaled to appropriate intensity range
"""
if not self.explicitScale:
return data
if self.intensityScale == -1:
return data
if not self.shift:
self.shift = vtk.vtkImageShiftScale()
self.shift.SetOutputScalarTypeToUnsignedChar()
self.shift.SetClampOverflow(1)
self.shift.SetInputConnection(data.GetProducerPort())
# Need to call this or it will remember the whole extent it got from resampling
self.shift.UpdateWholeExtent()
if self.intensityScale:
self.shift.SetScale(self.intensityScale)
currScale = self.intensityScale
else:
minval, maxval = self.originalScalarRange
scale = 255.0 / maxval
self.shift.SetScale(scale)
currScale = scale
self.shift.SetShift(self.intensityShift)
Logging.info("Intensity shift = %d, scale = %f"%(self.intensityShift, currScale), kw="datasource")
return self.shift.GetOutput()
示例7: Execute
def Execute(self):
if self.Image == None:
self.PrintError('Error: No input image.')
if self.OutputType == 'uchar' and self.ShiftScale:
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInputData(self.Image)
if self.WindowLevel[0] == 0.0:
scalarRange = self.Image.GetScalarRange()
scale = 255.0
if (scalarRange[1]-scalarRange[0]) > 0.0:
scale = 255.0/(scalarRange[1]-scalarRange[0])
shiftScale.SetShift(-scalarRange[0])
shiftScale.SetScale(scale)
else:
shiftScale.SetShift(-(self.WindowLevel[1]-self.WindowLevel[0]/2.0))
shiftScale.SetScale(255.0/self.WindowLevel[0])
shiftScale.SetOutputScalarTypeToUnsignedChar()
shiftScale.ClampOverflowOn()
shiftScale.Update()
self.Image = shiftScale.GetOutput()
else:
cast = vtk.vtkImageCast()
cast.SetInputData(self.Image)
if self.OutputType == 'float':
cast.SetOutputScalarTypeToFloat()
elif self.OutputType == 'double':
cast.SetOutputScalarTypeToDouble()
elif self.OutputType == 'uchar':
cast.SetOutputScalarTypeToUnsignedChar()
elif self.OutputType == 'short':
cast.SetOutputScalarTypeToShort()
cast.Update()
self.Image = cast.GetOutput()
示例8: getMIP
def getMIP(imageData, color):
"""
A function that will take a volume and do a simple
maximum intensity projection that will be converted to a
wxBitmap
"""
maxval = imageData.GetScalarRange()[1]
imageData.SetUpdateExtent(imageData.GetWholeExtent())
if maxval > 255:
shiftscale = vtk.vtkImageShiftScale()
shiftscale.SetInputConnection(imageData.GetProducerPort())
shiftscale.SetScale(255.0 / maxval)
shiftscale.SetOutputScalarTypeToUnsignedChar()
imageData = shiftscale.GetOutput()
mip = vtkbxd.vtkImageSimpleMIP()
mip.SetInputConnection(imageData.GetProducerPort())
if color == None:
output = optimize.execute_limited(mip)
return output
if mip.GetOutput().GetNumberOfScalarComponents() == 1:
ctf = getColorTransferFunction(color)
maptocolor = vtk.vtkImageMapToColors()
maptocolor.SetInputConnection(mip.GetOutputPort())
maptocolor.SetLookupTable(ctf)
maptocolor.SetOutputFormatToRGB()
imagedata = optimize.execute_limited(maptocolor)
else:
imagedata = output = optimize.execute_limited(mip)
return imagedata
示例9: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkImageShiftScale(), 'Processing.',
('vtkImageData',), ('vtkImageData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例10: Execute
def Execute(self):
if self.Image == None:
self.PrintError("Error: No input image.")
if self.OutputType == "uchar" and self.ShiftScale:
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInput(self.Image)
if self.WindowLevel[0] == 0.0:
scalarRange = self.Image.GetScalarRange()
shiftScale.SetShift(-scalarRange[0])
shiftScale.SetScale(255.0 / (scalarRange[1] - scalarRange[0]))
else:
shiftScale.SetShift(-(self.WindowLevel[1] - self.WindowLevel[0] / 2.0))
shiftScale.SetScale(255.0 / self.WindowLevel[0])
shiftScale.SetOutputScalarTypeToUnsignedChar()
shiftScale.ClampOverflowOn()
shiftScale.Update()
self.Image = shiftScale.GetOutput()
else:
cast = vtk.vtkImageCast()
cast.SetInput(self.Image)
if self.OutputType == "float":
cast.SetOutputScalarTypeToFloat()
elif self.OutputType == "double":
cast.SetOutputScalarTypeToDouble()
elif self.OutputType == "uchar":
cast.SetOutputScalarTypeToUnsignedChar()
elif self.OutputType == "short":
cast.SetOutputScalarTypeToShort()
cast.Update()
self.Image = cast.GetOutput()
示例11: DownsampleImage
def DownsampleImage(self, image, nbits=8):
"""Downsamples an image"""
image.SetReleaseDataFlag(1)
# get the min and max values from the image
(minval, maxval) = image.GetScalarRange()
# create an 8-bit version of this image
_filter = vtk.vtkImageShiftScale()
_filter.SetInput(image.GetRealImage())
_filter.SetShift(-minval)
try:
if nbits == 8:
_filter.SetScale(255.0 / (maxval - minval))
elif nbits == 16:
_filter.SetScale(65535.0 / (maxval - minval))
except ZeroDivisionError:
logging.exception("DownsampleImage")
_filter.SetScale(1.0)
if nbits == 8:
_filter.SetOutputScalarTypeToUnsignedChar()
elif nbits == 16:
_filter.SetOutputScalarTypeToShort()
elif nbits == 32:
_filter.SetOutputScalarTypeToFloat()
elif nbits == 64:
_filter.SetOutputScalarTypeToDouble()
_filter.AddObserver('ProgressEvent', self.HandleVTKProgressEvent)
_filter.SetProgressText("Downsampling to %d-bit..." % nbits)
logging.info("Image downsampled to {0}-bit".format(nbits))
_filter.Update()
return MVImage.MVImage(_filter.GetOutputPort(), input=image)
示例12: WriteTIFFImageFile
def WriteTIFFImageFile(self):
if (self.OutputFileName == ''):
self.PrintError('Error: no OutputFileName.')
self.PrintLog('Writing TIFF image file.')
outputImage = self.Image
if self.Image.GetScalarTypeAsString() != 'unsigned char':
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInputData(self.Image)
if self.WindowLevel[0] == 0.0:
scalarRange = self.Image.GetScalarRange()
shiftScale.SetShift(-scalarRange[0])
shiftScale.SetScale(255.0/(scalarRange[1]-scalarRange[0]))
else:
shiftScale.SetShift(-(self.WindowLevel[1]-self.WindowLevel[0]/2.0))
shiftScale.SetScale(255.0/self.WindowLevel[0])
shiftScale.SetOutputScalarTypeToUnsignedChar()
shiftScale.ClampOverflowOn()
shiftScale.Update()
outputImage = shiftScale.GetOutput()
writer = vtk.vtkTIFFWriter()
writer.SetInputData(outputImage)
if self.Image.GetDimensions()[2] == 1:
writer.SetFileName(self.OutputFileName)
else:
writer.SetFilePrefix(self.OutputFileName)
writer.SetFilePattern("%s%04d.tif")
writer.Write()
示例13: Rescale
def Rescale(combo, ZeroPoint):
"""Rescale to legal pixel values [-1, 1] --> [0, MaxScaledValue]"""
scaled = vtk.vtkImageShiftScale()
scaled.SetInputConnection(combo.GetOutputPort())
scaled.SetShift(1.)
scaled.SetScale(ZeroPoint + 1)
scaled.SetOutputScalarTypeToUnsignedShort()
return scaled
示例14: __init__
def __init__(self,renWin):
self.renWin = renWin
self.zBuffFilter = vtk.vtkWindowToImageFilter()
self.zBuffFilter.SetInput(self.renWin)
self.zBuffFilter.SetInputBufferTypeToZBuffer()
self.scaledZBuff = vtk.vtkImageShiftScale()
self.scaledZBuff.SetOutputScalarTypeToUnsignedChar()
self.scaledZBuff.SetInputConnection(self.zBuffFilter.GetOutputPort())
self.scaledZBuff.SetShift(0)
self.scaledZBuff.SetScale(255)
示例15: __init__
def __init__(self):
"""
Initialization
"""
lib.ProcessingFilter.ProcessingFilter.__init__(self, (1, 1))
self.vtkfilter = vtk.vtkImageShiftScale()
self.vtkfilter.AddObserver("ProgressEvent", lib.messenger.send)
lib.messenger.connect(self.vtkfilter, 'ProgressEvent', self.updateProgress)
self.eventDesc = "Applying a shift and scale to image intensity"
self.descs = {"Shift": "Shift:", "Scale": "Scale:", "AutoScale": "Scale to max range of data type", "NoOverflow":"Prevent over/underflow", "Scale8bit": "Scale to 8-bit range (0-255)"}
self.filterDesc = "Shifts pixel/voxel intensities and then scales them, corresponding roughly to the adjustment of brightness and contrast, respectively\nInput: Grayscale image\nOutput: Grayscale image"