本文整理汇总了Python中vtk.vtkBMPReader函数的典型用法代码示例。如果您正苦于以下问题:Python vtkBMPReader函数的具体用法?Python vtkBMPReader怎么用?Python vtkBMPReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkBMPReader函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: BMPReader
def BMPReader(self, currentElement):
reader = vtk.vtkBMPReader()
try:
reader.SetFileName( os.path.join(self.basedir, currentElement.get('SetFileName')) )
except:
self.logger.error(' .. <BMPReader> failed to SetFileName')
return reader
开发者ID:mfassler,项目名称:jaivis,代码行数:7,代码来源:xmlReader.py
示例2: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkBMPReader(), 'Reading vtkBMP.',
(), ('vtkBMP',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkBMPReader.py
示例3: VtkRead
def VtkRead(filepath, t):
if not const.VTK_WARNING:
log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt')
fow = vtk.vtkFileOutputWindow()
fow.SetFileName(log_path.encode(const.FS_ENCODE))
ow = vtk.vtkOutputWindow()
ow.SetInstance(fow)
global no_error
if t == "bmp":
reader = vtk.vtkBMPReader()
elif t == "tiff" or t == "tif":
reader = vtk.vtkTIFFReader()
elif t == "png":
reader = vtk.vtkPNGReader()
elif t == "jpeg" or t == "jpg":
reader = vtk.vtkJPEGReader()
else:
return False
reader.AddObserver("ErrorEvent", VtkErrorToPy)
reader.SetFileName(filepath)
reader.Update()
if no_error:
image = reader.GetOutput()
dim = image.GetDimensions()
if reader.GetNumberOfScalarComponents() > 1:
luminanceFilter = vtk.vtkImageLuminance()
luminanceFilter.SetInputData(image)
luminanceFilter.Update()
image = vtk.vtkImageData()
image.DeepCopy(luminanceFilter.GetOutput())
img_array = numpy_support.vtk_to_numpy(image.GetPointData().GetScalars())
img_array.shape = (dim[1], dim[0])
return img_array
else:
no_error = True
return False
开发者ID:invesalius,项目名称:invesalius3,代码行数:48,代码来源:bitmap_reader.py
示例4: __init__
def __init__(self, module_manager):
ModuleBase.__init__(self, module_manager)
self._reader = vtk.vtkBMPReader()
self._reader.SetFileDimensionality(3)
self._reader.SetAllow8BitBMP(1)
module_utils.setup_vtk_object_progress(self, self._reader,
'Reading BMP images.')
self._config.filePattern = '%03d.bmp'
self._config.firstSlice = 0
self._config.lastSlice = 1
self._config.spacing = (1,1,1)
self._config.fileLowerLeft = False
configList = [
('File pattern:', 'filePattern', 'base:str', 'filebrowser',
'Filenames will be built with this. See module help.',
{'fileMode' : wx.OPEN,
'fileMask' :
'BMP files (*.bmp)|*.bmp|All files (*.*)|*.*'}),
('First slice:', 'firstSlice', 'base:int', 'text',
'%d will iterate starting at this number.'),
('Last slice:', 'lastSlice', 'base:int', 'text',
'%d will iterate and stop at this number.'),
('Spacing:', 'spacing', 'tuple:float,3', 'text',
'The 3-D spacing of the resultant dataset.'),
('Lower left:', 'fileLowerLeft', 'base:bool', 'checkbox',
'Image origin at lower left? (vs. upper left)')]
ScriptedConfigModuleMixin.__init__(
self, configList,
{'Module (self)' : self,
'vtkBMPReader' : self._reader})
self.sync_module_logic_with_config()
开发者ID:fvpolpeta,项目名称:devide,代码行数:38,代码来源:BMPReader.py
示例5: testAllBlendsFloat
def testAllBlendsFloat(self):
# This script blends images that consist of float data
renWin = vtk.vtkRenderWindow()
renWin.SetSize(512, 256)
# Image pipeline
inputImage = vtk.vtkTIFFReader()
inputImage.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif")
# "beach.tif" image contains ORIENTATION tag which is
# ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF
# reader parses this tag and sets the internal TIFF image
# orientation accordingly. To overwrite this orientation with a vtk
# convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke
# SetOrientationType method with parameter value of 4.
inputImage.SetOrientationType(4)
inputImage2 = vtk.vtkBMPReader()
inputImage2.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")
# shrink the images to a reasonable size
shrink1 = vtk.vtkImageShrink3D()
shrink1.SetInputConnection(inputImage.GetOutputPort())
shrink1.SetShrinkFactors(2, 2, 1)
shrink2 = vtk.vtkImageShrink3D()
shrink2.SetInputConnection(inputImage2.GetOutputPort())
shrink2.SetShrinkFactors(2, 2, 1)
color = vtk.vtkImageShiftScale()
color.SetOutputScalarTypeToFloat()
color.SetShift(0)
color.SetScale(1.0 / 255)
color.SetInputConnection(shrink1.GetOutputPort())
backgroundColor = vtk.vtkImageShiftScale()
backgroundColor.SetOutputScalarTypeToFloat()
backgroundColor.SetShift(0)
backgroundColor.SetScale(1.0 / 255)
backgroundColor.SetInputConnection(shrink2.GetOutputPort())
# create a greyscale version
luminance = vtk.vtkImageLuminance()
luminance.SetInputConnection(color.GetOutputPort())
backgroundLuminance = vtk.vtkImageLuminance()
backgroundLuminance.SetInputConnection(backgroundColor.GetOutputPort())
# create an alpha mask
alpha = vtk.vtkImageThreshold()
alpha.SetInputConnection(luminance.GetOutputPort())
alpha.ThresholdByLower(0.9)
alpha.SetInValue(1.0)
alpha.SetOutValue(0.0)
# make luminanceAlpha and colorAlpha versions
luminanceAlpha = vtk.vtkImageAppendComponents()
luminanceAlpha.AddInputConnection(luminance.GetOutputPort())
luminanceAlpha.AddInputConnection(alpha.GetOutputPort())
colorAlpha = vtk.vtkImageAppendComponents()
colorAlpha.AddInputConnection(color.GetOutputPort())
colorAlpha.AddInputConnection(alpha.GetOutputPort())
foregrounds = ["luminance", "luminanceAlpha", "color", "colorAlpha"]
backgrounds = ["backgroundColor", "backgroundLuminance"]
deltaX = 1.0 / 4.0
deltaY = 1.0 / 2.0
blend = dict()
mapper = dict()
actor = dict()
imager = dict()
for row, bg in enumerate(backgrounds):
for column, fg in enumerate(foregrounds):
blend.update({bg:{fg:vtk.vtkImageBlend()}})
blend[bg][fg].AddInputConnection(eval(bg + '.GetOutputPort()'))
if bg == "backgroundColor" or fg == "luminance" or fg == "luminanceAlpha":
blend[bg][fg].AddInputConnection(eval(fg + '.GetOutputPort()'))
blend[bg][fg].SetOpacity(1, 0.8)
mapper.update({bg:{fg:vtk.vtkImageMapper()}})
mapper[bg][fg].SetInputConnection(blend[bg][fg].GetOutputPort())
mapper[bg][fg].SetColorWindow(1.0)
mapper[bg][fg].SetColorLevel(0.5)
actor.update({bg:{fg:vtk.vtkActor2D()}})
actor[bg][fg].SetMapper(mapper[bg][fg])
imager.update({bg:{fg:vtk.vtkRenderer()}})
imager[bg][fg].AddActor2D(actor[bg][fg])
#.........这里部分代码省略.........
开发者ID:151706061,项目名称:VTK,代码行数:101,代码来源:TestAllBlendsFloat.py
示例6: vtkGetDataRoot
#!/usr/bin/env python
# This example shows how to combine data from both the imaging and
# graphics pipelines. The vtkMergeFilter is used to merge the data
# from each together.
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Read in an image and compute a luminance value. The image is
# extracted as a set of polygons (vtkImageDataGeometryFilter). We then
# will warp the plane using the scalar (luminance) values.
reader = vtk.vtkBMPReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")
luminance = vtk.vtkImageLuminance()
luminance.SetInputConnection(reader.GetOutputPort())
geometry = vtk.vtkImageDataGeometryFilter()
geometry.SetInputConnection(luminance.GetOutputPort())
warp = vtk.vtkWarpScalar()
warp.SetInputConnection(geometry.GetOutputPort())
warp.SetScaleFactor(-0.1)
# Use vtkMergeFilter to combine the original image with the warped
# geometry.
merge = vtk.vtkMergeFilter()
merge.SetGeometryConnection(warp.GetOutputPort())
merge.SetScalarsConnection(reader.GetOutputPort())
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(merge.GetOutputPort())
mapper.SetScalarRange(0, 255)
开发者ID:ElsevierSoftwareX,项目名称:SOFTX-D-15-00004,代码行数:31,代码来源:imageWarp.py
示例7: str
imageGrid = vtk.vtkImageGridSource()
imageGrid.SetGridSpacing(16,16,0)
imageGrid.SetGridOrigin(0,0,0)
imageGrid.SetDataExtent(0,255,0,255,0,0)
imageGrid.SetDataScalarTypeToUnsignedChar()
table = vtk.vtkLookupTable()
table.SetTableRange(0,1)
table.SetValueRange(1.0,0.0)
table.SetSaturationRange(0.0,0.0)
table.SetHueRange(0.0,0.0)
table.SetAlphaRange(0.0,1.0)
table.Build()
alpha = vtk.vtkImageMapToColors()
alpha.SetInputConnection(imageGrid.GetOutputPort())
alpha.SetLookupTable(table)
reader1 = vtk.vtkBMPReader()
reader1.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp")
blend = vtk.vtkImageBlend()
blend.AddInputConnection(0,reader1.GetOutputPort())
blend.AddInputConnection(0,alpha.GetOutputPort())
# next, create a ThinPlateSpline transform
p1 = vtk.vtkPoints()
p1.SetNumberOfPoints(8)
p1.SetPoint(0,0,0,0)
p1.SetPoint(1,0,255,0)
p1.SetPoint(2,255,0,0)
p1.SetPoint(3,255,255,0)
p1.SetPoint(4,96,96,0)
p1.SetPoint(5,96,159,0)
p1.SetPoint(6,159,159,0)
p1.SetPoint(7,159,96,0)
开发者ID:0004c,项目名称:VTK,代码行数:31,代码来源:TestThinPlateWarp.py
示例8: str
# This script shows the magnitude of an image in frequency domain.
# Image pipeline
reader = vtk.vtkPNGReader()
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/fullhead15.png")
cast = vtk.vtkImageCast()
cast.SetInputConnection(reader.GetOutputPort())
cast.SetOutputScalarTypeToFloat()
scale2 = vtk.vtkImageShiftScale()
scale2.SetInputConnection(cast.GetOutputPort())
scale2.SetScale(0.05)
gradient = vtk.vtkImageGradient()
gradient.SetInputConnection(scale2.GetOutputPort())
gradient.SetDimensionality(3)
gradient.Update()
pnm = vtk.vtkBMPReader()
pnm.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp")
cast2 = vtk.vtkImageCast()
cast2.SetInputConnection(pnm.GetOutputPort())
cast2.SetOutputScalarTypeToDouble()
cast2.Update()
magnitude = vtk.vtkImageDotProduct()
magnitude.SetInput1Data(cast2.GetOutput())
magnitude.SetInput2Data(gradient.GetOutput())
#vtkImageViewer viewer
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(magnitude.GetOutputPort())
viewer.SetColorWindow(1000)
viewer.SetColorLevel(300)
#viewer DebugOn
viewer.Render()
开发者ID:ElsevierSoftwareX,项目名称:SOFTX-D-15-00004,代码行数:30,代码来源:TestDotProduct.py
示例9: validate
def validate(self, o):
dlg = self['dlgReader']
if o.readerClass!='vtkNiftiImageReader':
if len(o.pattern)==0:
msg = 'You must supply a number pattern for entry %s.\n' % \
self['labelPattern'].get_label() + 'Consider "%d"'
return error_msg(msg, dlg)
if o.pattern[0]!='%':
msg = '%s format string must begin with a %%.\n' % \
self['labelPattern'].get_label() + 'Consider "%d"'
return error_msg(msg, dlg)
if widgets['radiobuttonDimOther'].get_active():
dim1, dim2 = o.dimensions
val = dim1 = str2posint_or_err(dim1, 'Other: dimension 1', dlg)
if val is None: return None
val = dim2 = str2posint_or_err(dim2, 'Other: dimension 2', dlg)
if val is None: return None
o.dimensions = dim1, dim2
val = o.first = str2int_or_err(o.first, widgets['labelFirst'], dlg)
if val is None:
return None
val = o.last = str2posint_or_err(o.last, widgets['labelLast'], dlg)
if val is None: return None
if o.readerClass!='vtkNiftiImageReader':
fnames = self.get_file_names(o)
for fname in fnames:
print "validate(): doing fname ", fname
if not os.path.exists(fname):
return error_msg('Could not find file %s' % fname, dlg)
if o.readerClass=='vtkBMPReader':
reader = vtk.vtkBMPReader()
b = reader.CanReadFile(fname)
if not b:
return error_msg('Could not read file %s with reader %s'
% (fname, o.readerClass), dlg)
else:
if len(o.extension) > 0:
fname=os.path.join(o.dir,o.pattern+"."+o.extension)
if not os.path.exists(fname):
return error_msg('Could not find file %s' % fname, dlg)
else:
fname=o.pattern
files=os.listdir(o.dir)
match=False
for file in files:
file=file.split(".")
if len(file)>1:
if file[0]==fname:
if file[1] in ["nii","img","hdr"]:
match=True
break
if not match:
return error_msg('Could not find file %s with extension nii, img, hdr [.gz]' % fname, dlg)
# Depth Field Of View
val = o.dfov = str2posnum_or_err(o.dfov, widgets['labelDFOV'], dlg)
print "dfov=", val
if val is None: return None
# Spacing between slices
val = o.spacing = str2posnum_or_err(
o.spacing, widgets['labelSpacing'], dlg)
print "spacing=", val
if val is None: return None
# Size of header
if o.header=='': o.header = 0
else:
val = o.header = str2int_or_err(
o.header, widgets['labelHeader'], dlg)
if val is None: return None
print "header=", val
# Data mask
if o.mask is not None:
if o.mask=='': o.mask = None
else:
val = o.mask = str2int_or_err(
o.mask, widgets['labelMask'], dlg)
if val is None: return None
print "mask=", val
return o
开发者ID:alexsavio,项目名称:nidoodles,代码行数:90,代码来源:image_reader.py
示例10: testGlyphs
def testGlyphs(self):
"""Test if texturing of the glyphs works correctly."""
# The Glyph
cs = vtk.vtkCubeSource()
cs.SetXLength(2.0); cs.SetYLength(1.0); cs.SetZLength(0.5)
# Create input point data.
pts = vtk.vtkPoints()
pts.InsertPoint(0, (1,1,1))
pts.InsertPoint(1, (0,0,0))
pts.InsertPoint(2, (-1,-1,-1))
polys = vtk.vtkCellArray()
polys.InsertNextCell(1)
polys.InsertCellPoint(0)
polys.InsertNextCell(1)
polys.InsertCellPoint(1)
polys.InsertNextCell(1)
polys.InsertCellPoint(2)
pd = vtk.vtkPolyData()
pd.SetPoints(pts)
pd.SetPolys(polys)
# Orient the glyphs as per vectors.
vec = vtk.vtkFloatArray()
vec.SetNumberOfComponents(3)
vec.InsertTuple3(0, 1, 0, 0)
vec.InsertTuple3(1, 0, 1, 0)
vec.InsertTuple3(2, 0, 0, 1)
pd.GetPointData().SetVectors(vec)
# The glyph filter.
g = vtk.vtkGlyph3D()
g.SetScaleModeToDataScalingOff()
g.SetVectorModeToUseVector()
g.SetInputData(pd)
g.SetSourceConnection(cs.GetOutputPort())
m = vtk.vtkPolyDataMapper()
m.SetInputConnection(g.GetOutputPort())
a = vtk.vtkActor()
a.SetMapper(m)
# The texture.
img_file = os.path.join(VTK_DATA_ROOT, "Data", "masonry.bmp")
img_r = vtk.vtkBMPReader()
img_r.SetFileName(img_file)
t = vtk.vtkTexture()
t.SetInputConnection(img_r.GetOutputPort())
t.InterpolateOn()
a.SetTexture(t)
# Renderer, RenderWindow etc.
ren = vtk.vtkRenderer()
ren.SetBackground(0.5, 0.5, 0.5)
ren.AddActor(a)
ren.ResetCamera();
cam = ren.GetActiveCamera()
cam.Azimuth(-90)
cam.Zoom(1.4)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
rwi = vtk.vtkRenderWindowInteractor()
rwi.SetRenderWindow(renWin)
rwi.Initialize()
rwi.Render()
开发者ID:ElsevierSoftwareX,项目名称:SOFTX-D-15-00004,代码行数:67,代码来源:TestTextureGlyph.py
示例11: img2dcm
def img2dcm(self, input_img, output, img_type, img_number):
if img_type == "jpg":
print "JPG"
image = vtk.vtkJPEGReader()
image.SetFileName(input_img)
image.Update()
elif img_type == "tif":
print "TIF"
image = vtk.vtkTIFFReader()
image.SetFileName(input_img)
image.Update()
elif img_type == "bmp":
print "BMP"
image = vtk.vtkBMPReader()
image.SetFileName(input_img)
image.Allow8BitBMPOn()
image.Update()
elif img_type == "png":
print "PNG"
image = vtk.vtkPNGReader()
image.SetFileName(input_img)
image.SetDataSpacing(self.spacing)
image.Update()
elif img_type == "vti":
print "VTI"
image = vtk.vtkXMLImageDataReader()
image.SetFileName(input_img)
image.Update()
#if (orientation == 0):
image_pos = img_number * self.spacing[2]
image_localization = image_pos
# print image_pos, img_number, image.GetOutput().GetScalarRange()
img_clone = vtk.vtkImageData()
img_clone.DeepCopy(image.GetOutput())
img_clone.SetSpacing(self.spacing)
img_clone.Update()
# v = vtk.vtkImageViewer()
# v.SetInput(image.GetOutput())
# v.SetColorLevel(500)
# v.SetColorWindow(240)
# v.Render()
# time.sleep(3)
# a = vtk.vtkImageCast()
# a.SetOutputScalarTypeToUnsignedChar()
# a.SetInput(image.GetOutput())
# a.ClampOverflowOn()
# a.Update()
#b = vtk.vtkJPEGWriter()
#b.SetFileName("C:\\teste.jpg")
#b.SetInput(a.GetOutput())
#b.writer()
#spacing = image.GetOutput().GetSpacing()
#elif (orientation == 1):
# image_pos[0] = image_pos[0] + thickness
# image_localization = image_localization + thickness
# img_number = img_number + 1
#elif (orientation == 2):
# image_pos[1] = image_pos[1] + thickness
# image_localization = image_localization + thickness
# img_number = img_number + 1
pos = 0, 0, image_pos
print pos
# transform = vtk.vtkTransform()
# transform.Translate(pos)
# transform_filter = vtk.vtkImageReslice()
# transform_filter.SetInput(image.GetOutput())
# transform_filter.SetResliceTransform(transform)
# transform_filter.Update()
properties = vtk.vtkMedicalImageProperties()
properties.SetModality(self.modality)
properties.SetInstitutionName(self.institution)
properties.SetPatientName(self.patient)
properties.SetSliceThickness(str(self.spacing[2]))
properties.SetSeriesNumber(str(self.serie))
properties.SetImageNumber(str(img_number))
properties.SetPatientID(self.patient_id)
properties.SetStudyID(self.study_id)
properties.AddUserDefinedValue("Image Position (Patient)", "%.5f\\%.5f\\%.5f" %
(pos[0], pos[1], pos[2]))
properties.AddUserDefinedValue("Instance Number", str(img_number))
print str(img_number), properties.GetNumberOfUserDefinedValues()
writer = vtkgdcm.vtkGDCMImageWriter()
#.........这里部分代码省略.........
开发者ID:archeos,项目名称:img2dcm-archeos,代码行数:101,代码来源:img2dcm.py
示例12: __init__
def __init__(self):
vtkImageReaderBase.vtkImageReaderBase.__init__(self)
self.SetImageReader(vtk.vtkBMPReader())
开发者ID:parallaxinnovations,项目名称:vtkMultiIO,代码行数:3,代码来源:vtkMultiImageReader.py
示例13: ORIENTATION_TOPLEFT
renWin.SetSize(512, 256)
# Image pipeline
image1 = vtk.vtkTIFFReader()
image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif")
# "beach.tif" image contains ORIENTATION tag which is
# ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF
# reader parses this tag and sets the internal TIFF image
# orientation accordingly. To overwrite this orientation with a vtk
# convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke
# SetOrientationType method with parameter value of 4.
image1.SetOrientationType(4)
image2 = vtk.vtkBMPReader()
image2.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")
# shrink the images to a reasonable size
color = vtk.vtkImageShrink3D()
color.SetInputConnection(image1.GetOutputPort())
color.SetShrinkFactors(2, 2, 1)
backgroundColor = vtk.vtkImageShrink3D()
backgroundColor.SetInputConnection(image2.GetOutputPort())
backgroundColor.SetShrinkFactors(2, 2, 1)
# create a greyscale version
luminance = vtk.vtkImageLuminance()
开发者ID:Kitware,项目名称:VTK,代码行数:31,代码来源:TestBlendCompound.py
注:本文中的vtk.vtkBMPReader函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论