本文整理汇总了Python中vtk.vtkPNGReader函数的典型用法代码示例。如果您正苦于以下问题:Python vtkPNGReader函数的具体用法?Python vtkPNGReader怎么用?Python vtkPNGReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkPNGReader函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: compare_png_images
def compare_png_images(self, image1_filename, image2_filename,
threshold=16, allow_shift=False):
"""Compare two PNG images on disc. No two pixels may differ with more
than the default threshold.
"""
import vtk
r1 = vtk.vtkPNGReader()
r1.SetFileName(image1_filename)
r1.Update()
r2 = vtk.vtkPNGReader()
r2.SetFileName(image2_filename)
r2.Update()
# there's a bug in VTK 5.0.1 where input images of unequal size
# (depending on which input is larger) will cause a segfault
# see http://www.vtk.org/Bug/bug.php?op=show&bugid=3586
# se we check for that situation and bail if it's the case
if r1.GetOutput().GetDimensions() != r2.GetOutput().GetDimensions():
em = 'Input images %s and %s are not of equal size.' % \
(image1_filename, image2_filename)
raise RuntimeError, em
# sometimes PNG files have an ALPHA component we have to chuck away
# do this for both images
ec1 = vtk.vtkImageExtractComponents()
ec1.SetComponents(0,1,2)
ec1.SetInput(r1.GetOutput())
ec2 = vtk.vtkImageExtractComponents()
ec2.SetComponents(0,1,2)
ec2.SetInput(r2.GetOutput())
idiff = vtk.vtkImageDifference()
idiff.SetThreshold(threshold)
if allow_shift:
idiff.AllowShiftOn()
else:
idiff.AllowShiftOff()
idiff.SetImage(ec1.GetOutput())
idiff.SetInputConnection(ec2.GetOutputPort())
idiff.Update()
return idiff.GetThresholdedError()
开发者ID:fvpolpeta,项目名称:devide,代码行数:50,代码来源:__init__.py
示例2: testRenderMesh
def testRenderMesh(self):
# Create a "render mesh" operator
renderMesh = self.operationManager.createOperation(
'smtk.extension.matplotlib.render_mesh.RenderMesh')
if not renderMesh:
raise RuntimeError('Could not find operator \'render mesh\'')
# Set the operator's parameters
print renderMesh.parameters()
renderMesh.parameters().find(
'mesh').setValue(self.meshResource.meshes())
self.outFile = os.path.join(
smtk.testing.TEMP_DIR, str(smtk.common.UUID.random()) + '.png')
renderMesh.parameters().find('filename').setValue(self.outFile)
# Execute the operator
result = renderMesh.operate()
if self.interactive() and self.haveVTK() and self.haveVTKExtension():
import vtk
self.startRenderTest()
reader = vtk.vtkPNGReader()
reader.SetFileName(self.outFile)
reader.Update()
self.addImageToScene(reader)
cam = self.renderer.GetActiveCamera()
self.renderer.ResetCamera()
self.renderWindow.Render()
self.interact()
开发者ID:Kitware,项目名称:SMTK,代码行数:33,代码来源:renderMesh.py
示例3: testImportExport
def testImportExport(self):
"Testing if images can be imported to and from numeric arrays."
imp = vtkImageImportFromArray()
exp = vtkImageExportToArray()
idiff = vtk.vtkImageDifference()
img_dir = Testing.getAbsImagePath("")
for i in glob.glob(os.path.join(img_dir, "*.png")):
# Putting the reader outside the loop causes bad problems.
reader = vtk.vtkPNGReader()
reader.SetFileName(i)
reader.Update()
# convert the image to a Numeric Array and convert it back
# to an image data.
exp.SetInputConnection(reader.GetOutputPort())
imp.SetArray(exp.GetArray())
# ensure there is no difference between orig image and the
# one we converted and un-converted.
idiff.SetInputConnection(imp.GetOutputPort())
idiff.SetImage(reader.GetOutput())
idiff.Update()
err = idiff.GetThresholdedError()
msg = "Test failed on image %s, with threshold "\
"error: %d"%(i, err)
self.assertEqual(err, 0.0, msg)
开发者ID:Armand0s,项目名称:homemade_vtk,代码行数:28,代码来源:TestNumericArrayImageData.py
示例4: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkPNGReader(), 'Reading vtkPNG.',
(), ('vtkPNG',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkPNGReader.py
示例5: do_test
def do_test(self):
vw = vtk.vtkButtonWidget()
vr = vtk.vtkTexturedButtonRepresentation2D()
vr.SetNumberOfStates(1)
r = vtk.vtkPNGReader()
r.SetFileName("Pepper.png")
r.Update()
image = r.GetOutput()
vr.SetButtonTexture(0, image)
vw.SetRepresentation(vr)
w = vcs.vtk_ui.widget.Widget(self.inter, vw)
w.show()
width, height, _ = image.GetDimensions()
bounds = (0, 0 + width, 0, height, 0, 0)
vr.SetPlaceFactor(1)
vr.PlaceWidget(bounds)
w.detach()
assert vr.GetRenderer() is None and vw.GetCurrentRenderer() is None, "Renderer is set after detach"
assert vw.GetInteractor() is None, "Interactor set after detach"
assert w.showing() == False, "Widget is flagged as Enabled"
assert w not in vcs.vtk_ui.manager.get_manager(self.inter).widgets, "Widget still being managed"
assert w.interactor is None, "Widget has a reference to interactor"
self.passed = 0
开发者ID:UV-CDAT,项目名称:uvcdat,代码行数:27,代码来源:test_vtk_ui_widget_detach.py
示例6: setupReader
def setupReader(img):
rd = vtk.vtkPNGReader()
rd.SetFileName(img1)
rd.Update()
imp = vtkImageImportFromArray()
exp = vtkImageExportToArray()
exp.SetInputConnection(rd.GetOutputPort())
imp.SetArray(exp.GetArray())
return imp
开发者ID:doutriaux1,项目名称:VTKLearning,代码行数:9,代码来源:test_img_diff.py
示例7: do_test
def do_test(self):
self.win.SetSize((100, 100))
vw = vtk.vtkButtonWidget()
vr = vtk.vtkTexturedButtonRepresentation2D()
vr.SetNumberOfStates(1)
r = vtk.vtkPNGReader()
r.SetFileName("Pepper.png")
r.Update()
image = r.GetOutput()
vr.SetButtonTexture(0, image)
vw.SetRepresentation(vr)
w = vcs.vtk_ui.widget.Widget(self.inter, vw)
w.show()
def dummy(*args, **kwargs):
pass
w.subscribe("StartInteractionEvent", dummy)
# Make sure event was properly subscribed to
assert "StartInteractionEvent" in w.subscriptions, "Event not in subscriptions"
# Check observers of w for the tag in w.subscriptions
tag = w.subscriptions["StartInteractionEvent"]
c = vw.GetCommand(tag)
assert c is not None, "Listener not attached to widget"
try:
w.subscribe("StartInteractionEvent", dummy)
print "Failed to notice double event subscription on widget"
return
except KeyError:
pass
w.unsubscribe("StartInteractionEvent")
assert "StartInteractionEvent" not in w.subscriptions, "Did not remove event from subscriptions on unsubscribe"
# Test multiple unsubscriptions
w.subscribe("EndInteractionEvent", dummy)
w.subscribe("StartInteractionEvent", dummy)
w.unsubscribe("StartInteractionEvent", "EndInteractionEvent")
assert (
"EndInteractionEvent" not in w.subscriptions and "StartInteractionEvent" not in w.subscriptions
), "Did not remove both events from widget subscriptions"
try:
w.unsubscribe("StartInteractionEvent")
print "Failed to notice double unsubscribe on widget"
return
except KeyError:
pass
self.passed = 0
开发者ID:sankhesh,项目名称:uvcdat,代码行数:56,代码来源:test_vtk_ui_widget_subscribe_unsubscribe.py
示例8: image_from_file
def image_from_file(fname):
try:
rd = vtk.vtkPNGReader()
rd.SetFileName(fname)
rd.Update()
exp = vtkImageExportToArray()
exp.SetInputConnection(rd.GetOutputPort())
areader = exp.GetArray()
except Exception,err:
print "Problem opening file",err
return None
开发者ID:arulalant,项目名称:uvcdat,代码行数:11,代码来源:checkimage.py
示例9: image_from_file
def image_from_file(fname):
try:
rd = vtk.vtkPNGReader()
rd.SetFileName(fname)
removeAlpha = vtk.vtkImageExtractComponents()
removeAlpha.SetComponents(0, 1, 2)
removeAlpha.SetInputConnection(rd.GetOutputPort())
removeAlpha.Update()
return removeAlpha.GetOutput()
except Exception, err:
print "Problem opening file '%s': %s" % (fname, err)
return None
开发者ID:NESII,项目名称:uvcdat,代码行数:12,代码来源:checkimage.py
示例10: getFromCache
def getFromCache(self, datafilename, chName, purpose):
"""
Retrieve a MIP image from cache
"""
key = self.getCacheKey(datafilename, chName, purpose)
directory = scripting.get_preview_dir()
filename = "%s.png" % key
filepath = os.path.join(directory, filename)
if not os.path.exists(filepath):
return None
reader = vtk.vtkPNGReader()
reader.SetFileName(filepath)
reader.Update()
return reader.GetOutput()
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:14,代码来源:DataSource.py
示例11: 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
示例12: do_test
def do_test(self):
self.win.SetSize((100, 100))
vw = vtk.vtkButtonWidget()
vr = vtk.vtkTexturedButtonRepresentation2D()
vr.SetNumberOfStates(1)
r = vtk.vtkPNGReader()
r.SetFileName("Pepper.png")
r.Update()
image = r.GetOutput()
vr.SetButtonTexture(0, image)
vw.SetRepresentation(vr)
w = vcs.vtk_ui.widget.Widget(self.inter, vw)
w.show()
width, height, _ = image.GetDimensions()
bounds = (0, 0 + width, 0, height, 0, 0)
vr.SetPlaceFactor(1)
vr.PlaceWidget(bounds)
self.test_file = "test_vtk_ui_widget_show.png"
if self.args:
self.passed = self.check_image(self.args[0])
if self.passed == 1:
print "Failed to show correctly"
return
else:
generate_png(self.win, self.test_file)
assert w.showing(), "showing() thinks hidden while showing"
w.hide()
assert w.showing() == False, "showing() thinks showing while hidden"
self.test_file = "test_vtk_ui_widget_hide.png"
if len(self.args) > 1:
self.passed = self.check_image(self.args[1])
if self.passed == 1:
print "Failed to hide correctly"
return
else:
generate_png(self.win, self.test_file)
self.test_file = None
self.passed = 0
开发者ID:UV-CDAT,项目名称:uvcdat,代码行数:47,代码来源:test_vtk_ui_widget_show_hide.py
示例13: ReadPNGImageFile
def ReadPNGImageFile(self):
if (self.InputFileName == '') & (self.InputFilePrefix == ''):
self.PrintError('Error: no InputFileName or InputFilePrefix.')
self.PrintLog('Reading PNG image file.')
reader = vtk.vtkPNGReader()
if self.InputFileName != '':
reader.SetFileName(self.InputFileName)
else:
reader.SetFilePrefix(self.InputFilePrefix)
if self.InputFilePattern != '':
reader.SetFilePattern(self.InputFilePattern)
else:
reader.SetFilePattern("%s%04d.png")
reader.SetDataExtent(self.DataExtent)
reader.SetDataSpacing(self.DataSpacing)
reader.SetDataOrigin(self.DataOrigin)
reader.Update()
self.Image = reader.GetOutput()
开发者ID:vmtk,项目名称:vmtk,代码行数:18,代码来源:vmtkimagereader.py
示例14: updateContents
def updateContents(self, inputPorts):
if self.view == None:
self.view = pvsp.CreateRenderView()
renWin = self.view.GetRenderWindow()
self.SetRenderWindow(renWin)
iren = renWin.GetInteractor()
iren.SetNonInteractiveRenderDelay(0)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
# Load the uvcdat logo and use it for overlay
logoPath = system.vistrails_root_directory() + "/gui/uvcdat/resources/images/uvcdat_logo_transparent.png"
reader = vtk.vtkPNGReader()
reader.SetFileName(logoPath)
reader.Update()
imageActor = vtk.vtkImageActor()
imageActor.SetInput(reader.GetOutput())
self.overlayRenderer = vtk.vtkRenderer()
self.overlayRenderer.AddActor(imageActor)
renWin.SetNumberOfLayers(renWin.GetNumberOfLayers() + 1)
self.overlayRenderer.SetLayer(renWin.GetNumberOfLayers() - 1)
renWin.AddRenderer(self.overlayRenderer)
self.overlayRenderer.SetViewport(0.7, 0, 1.0, 0.3)
del self.view.Representations[:]
# Fetch variables from the input port
(location, representations) = inputPorts
for rep in representations:
rep.set_view(self.view)
rep.execute()
# Set view specific properties
self.view.CenterAxesVisibility = 0
self.view.Background = [0.6, 0.6, 0.6]
self.view.ResetCamera()
self.view.StillRender()
QCellWidget.updateContents(self, inputPorts)
开发者ID:painter1,项目名称:vistrails,代码行数:44,代码来源:pvgenericcell.py
示例15: create_textured_plane
def create_textured_plane(**kwargs):
"""
create a plane with correct size and texture it with a map
"""
image_reader = vtk.vtkPNGReader()
image_reader.SetFileName(kwargs['map'])
plane = vtk.vtkPlaneSource()
size = kwargs['size']
z_level = 0.0
plane.SetOrigin(-0.5*size[0], -0.5*size[1], z_level)
plane.SetPoint1(+0.5*size[0], -0.5*size[1], z_level)
plane.SetPoint2(-0.5*size[0], +0.5*size[1], z_level)
texture = vtk.vtkTexture()
texture.SetInputConnection(image_reader.GetOutputPort())
texture_plane = vtk.vtkTextureMapToPlane()
texture_plane.SetInputConnection(plane.GetOutputPort())
return texture_plane, texture
开发者ID:capitalaslash,项目名称:radcal-gui,代码行数:20,代码来源:map.py
示例16: vtkRegressionTestImage
def vtkRegressionTestImage( renWin ):
"""vtkRegressionTestImage(renWin) -- produce regression image for window
This function writes out a regression .png file for a vtkWindow.
Does anyone involved in testing care to elaborate?
"""
imageIndex=-1;
for i in range(0, len(sys.argv)):
if sys.argv[i] == '-V' and i < len(sys.argv)-1:
imageIndex = i+1
if imageIndex != -1:
fname = os.path.join(vtkGetDataRoot(), sys.argv[imageIndex])
rt_w2if = vtk.vtkWindowToImageFilter()
rt_w2if.SetInput(renWin)
if os.path.isfile(fname):
pass
else:
rt_pngw = vtk.vtkPNGWriter()
rt_pngw.SetFileName(fname)
rt_pngw.SetInputConnection(rt_w2if.GetOutputPort())
rt_pngw.Write()
rt_pngw = None
rt_png = vtk.vtkPNGReader()
rt_png.SetFileName(fname)
rt_id = vtk.vtkImageDifference()
rt_id.SetInputConnection(rt_w2if.GetOutputPort())
rt_id.SetImageConnection(rt_png.GetOutputPort())
rt_id.Update()
if rt_id.GetThresholdedError() <= 10:
return 1
else:
sys.stderr.write('Failed image test: %f\n'
% rt_id.GetThresholdedError())
return 0
return 2
开发者ID:151706061,项目名称:VTK,代码行数:41,代码来源:misc.py
示例17: createLogo
def createLogo(self):
if self.canvas.drawLogo is False:
## Ok we do not want a logo here
return
# Pth to logo
logoFile = os.path.join(sys.prefix,"share","vcs","uvcdat.png")
# VTK reader for logo
logoRdr=vtk.vtkPNGReader()
logoRdr.SetFileName(logoFile)
logoRdr.Update()
x0,x1,y0,y1,z0,z1 = logoRdr.GetDataExtent()
ia = vtk.vtkImageActor()
ia.GetMapper().SetInputConnection(logoRdr.GetOutputPort())
ren = self.createRenderer()
self.renWin.AddRenderer(ren)
r,g,b = self.canvas.backgroundcolor
ren.SetBackground(r/255.,g/255.,b/255.)
#ren.SetLayer(self.renWin.GetNumberOfLayers()-1)
ren.AddActor(ia)
self.logo = ren
self.logoExtent = [x1,y1]
开发者ID:lizadams,项目名称:uvcdat,代码行数:21,代码来源:VTKPlots.py
示例18: __init__
def __init__(self, renderer, parent, screenDistance, width, height, isActiveCamera = False):
'''
Initialize the CameraScreen model.
If you are going to stream data to it, set isActiveCamera to true in the constructor parameters and pass jpeg data to the update method.
'''
# Call the parent constructor
super(CameraScreen,self).__init__(renderer, parent)
# Create a plane for the camera
# Ref: http://www.vtk.org/doc/nightly/html/classvtkPlaneSource.html
planeSource = vtk.vtkPlaneSource()
# Defaults work for this, so just push it out a bit
#planeSource.Push(screenDistance)
# Transform scale it to the right size
trans = vtk.vtkTransform()
trans.Scale(width, height, 1)
trans.Translate(0, 0, screenDistance)
trans.RotateY(180) # Effectively flipping the UV (texture) mapping so that the video isn't left/right flipped
transF = vtk.vtkTransformPolyDataFilter()
transF.SetInputConnection(planeSource.GetOutputPort())
transF.SetTransform(trans)
# Create a test picture and assign it to the screen for now...
# Ref: http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Rendering/Python/TPlane.py
if not isActiveCamera:
self.__textReader = vtk.vtkPNGReader()
self.__textReader.SetFileName("../scene/media/semisortedcameralogo.png")
else:
self.__textReader = vtk.vtkJPEGReader()
self.cameraVtkTexture = vtk.vtkTexture()
self.cameraVtkTexture.SetInputConnection(self.__textReader.GetOutputPort())
self.cameraVtkTexture.InterpolateOn()
# Finally assign the mapper and the actor
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInputConnection(transF.GetOutputPort())
self.vtkActor.SetMapper(planeMapper)
self.vtkActor.SetTexture(self.cameraVtkTexture)
开发者ID:GearsAD,项目名称:semisorted_arnerve,代码行数:40,代码来源:CameraScreen.py
示例19: testRasterEPS
def testRasterEPS(self):
"""Test EPS output when Write3DPropsAsRasterImage is on."""
# Get a temporary file name. Set the extension to empty since
# the exporter appends a suitable extension.
tmp_eps = tempfile.mktemp('')
# Write an EPS file.
exp = vtk.vtkGL2PSExporter()
exp.SetRenderWindow(self.renWin)
exp.SetFilePrefix(tmp_eps)
# Turn off compression so PIL can read file.
exp.CompressOff()
exp.SetSortToOff()
exp.DrawBackgroundOn()
exp.Write3DPropsAsRasterImageOn()
exp.Write()
# Now read the EPS file using PIL.
tmp_eps += '.eps'
im = Image.open(tmp_eps)
# Get a temporary name for the PNG file.
tmp_png = tempfile.mktemp('.png')
im.save(tmp_png)
# Now read the saved image and compare it for the test.
png_r = vtk.vtkPNGReader()
png_r.SetFileName(tmp_png)
png_r.Update()
img = png_r.GetOutput()
# Cleanup. Do this first because if the test fails, an
# exception is raised and the temporary files won't be
# removed.
self._cleanup([tmp_eps, tmp_png])
img_file = "TestGL2PSExporter.png"
Testing.compareImageWithSavedImage(img,
Testing.getAbsImagePath(img_file))
# Interact if necessary.
Testing.interact()
开发者ID:gang-liu,项目名称:paraview,代码行数:38,代码来源:TestGL2PSExporter.py
示例20: __init__
def __init__(self, module_manager):
ModuleBase.__init__(self, module_manager)
self._reader = vtk.vtkPNGReader()
self._reader.SetFileDimensionality(3)
module_utils.setup_vtk_object_progress(self, self._reader,
'Reading PNG images.')
self._config.filePattern = '%03d.png'
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' :
'PNG files (*.png)|*.png|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,
'vtkPNGReader' : self._reader})
self.sync_module_logic_with_config()
开发者ID:fvpolpeta,项目名称:devide,代码行数:36,代码来源:pngRDR.py
注:本文中的vtk.vtkPNGReader函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论