本文整理汇总了Python中pyworkflow.em.convert.ImageHandler类的典型用法代码示例。如果您正苦于以下问题:Python ImageHandler类的具体用法?Python ImageHandler怎么用?Python ImageHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _buildDendrogram
def _buildDendrogram(self, leftIndex, rightIndex, index, writeAverages=False, level=0):
""" This function is recursively called to create the dendogram graph(binary tree)
and also to write the average image files.
Params:
leftIndex, rightIndex: the indinxes within the list where to search.
index: the index of the class average.
writeImages: flag to select when to write averages.
From self:
self.dendroValues: the list with the heights of each node
self.dendroImages: image stack filename to read particles
self.dendroAverages: stack name where to write averages
It will search for the max in values list (between minIndex and maxIndex).
Nodes to the left of the max are left childs and the other right childs.
"""
maxValue = self.dendroValues[leftIndex]
maxIndex = 0
for i, v in enumerate(self.dendroValues[leftIndex+1:rightIndex]):
if v > maxValue:
maxValue = v
maxIndex = i+1
m = maxIndex + leftIndex
node = DendroNode(index, maxValue)
ih = ImageHandler()
particleNumber = self.dendroIndexes[m+1]
node.imageList = [particleNumber]
if writeAverages:
node.image = ih.read((particleNumber, self.dendroImages))
def addChildNode(left, right, index):
if right > left:
child = self._buildDendrogram(left, right, index, writeAverages, level+1)
node.addChild(child)
node.length += child.length
node.imageList += child.imageList
if writeAverages:
node.image += child.image
del child.image # Allow to free child image memory
if rightIndex > leftIndex + 1 and level < self.dendroMaxLevel:
addChildNode(leftIndex, m, 2*index)
addChildNode(m+1, rightIndex, 2*index+1)
node.avgCount = self.dendroAverageCount + 1
self.dendroAverageCount += 1
node.path = '%[email protected]%s' % (node.avgCount, self.dendroAverages)
if writeAverages:
#TODO: node['image'] /= float(node['length'])
#node.image.inplaceDivide(float(node.length)) #FIXME: not working, noisy images
avgImage = node.image / float(node.length)
ih.write(avgImage, (node.avgCount, self.dendroAverages))
fn = self._getTmpPath('doc_class%03d.stk' % index)
doc = SpiderDocFile(fn, 'w+')
for i in node.imageList:
doc.writeValues(i)
doc.close()
return node
开发者ID:josegutab,项目名称:scipion,代码行数:60,代码来源:protocol_classify_base.py
示例2: importVolumesStep
def importVolumesStep(self, pattern, samplingRate):
""" Copy images matching the filename pattern
Register other parameters.
"""
self.info("Using pattern: '%s'" % pattern)
# Create a Volume template object
vol = Volume()
vol.setSamplingRate(self.samplingRate.get())
copyOrLink = self.getCopyOrLink()
imgh = ImageHandler()
volSet = self._createSetOfVolumes()
volSet.setSamplingRate(self.samplingRate.get())
for fileName, fileId in self.iterFiles():
dst = self._getExtraPath(basename(fileName))
copyOrLink(fileName, dst)
x, y, z, n = imgh.getDimensions(dst)
# First case considers when reading mrc without volume flag
# Second one considers single volumes (not in stack)
if (z == 1 and n != 1) or (z !=1 and n == 1):
vol.setObjId(fileId)
vol.setLocation(dst)
volSet.append(vol)
else:
for index in range(1, n+1):
vol.cleanObjId()
vol.setLocation(index, dst)
volSet.append(vol)
if volSet.getSize() > 1:
self._defineOutputs(outputVolumes=volSet)
else:
self._defineOutputs(outputVolume=vol)
开发者ID:josegutab,项目名称:scipion,代码行数:35,代码来源:volumes.py
示例3: ImagePreviewDialog
class ImagePreviewDialog(PreviewDialog):
def _beforePreview(self):
self.dim = 256
self.previewLabel = ''
def _createPreview(self, frame):
""" Should be implemented by subclasses to
create the items preview.
"""
from pyworkflow.gui.matplotlib_image import ImagePreview
self.preview = ImagePreview(frame, self.dim, label=self.previewLabel)
self.preview.grid(row=0, column=0)
def _itemSelected(self, obj):
index = obj.getIndex()
filename = obj.getFileName()
if index:
filename = "%[email protected]%s" % (index, filename)
# self.image = xmipp.Image()
self.image = ImageHandler()._img
try:
self.image.readPreview(filename, self.dim)
if filename.endswith('.psd'):
self.image.convertPSD()
self.Z = self.image.getData()
except Exception, e:
from pyworkflow.gui.matplotlib_image import getPngData
self.Z = getPngData(findResource('no-image.png'))
dialog.showError("Input particles", "Error reading image <%s>" % filename, self)
self.preview.updateData(self.Z)
开发者ID:coocoky,项目名称:scipion,代码行数:34,代码来源:wizard.py
示例4: convertInputStep
def convertInputStep(self, particlesId, volId):
""" Write the input images as a Xmipp metadata file.
particlesId: is only need to detect changes in
input particles and cause restart from here.
"""
inputParticles = self.inputParticles.get()
inputVolume = self.inputVolume.get()
writeSetOfParticles(inputParticles, self._getExpParticlesFn())
img = ImageHandler()
img.convert(inputVolume, self._getInputVolFn())
if self._useSeveralClasses():
# Scale particles
Xdim = inputParticles.getXDim()
Ts = inputParticles.getSamplingRate()
newTs = self.targetResolution.get() * 0.4
newTs = max(Ts, newTs)
newXdim = Xdim * Ts / newTs
self.runJob("xmipp_image_resize",
"-i %s -o %s --save_metadata_stack %s --fourier %d" %
(self._getExpParticlesFn(),
self._getTmpPath('scaled_particles.stk'),
self._getTmpPath('scaled_particles.xmd'),
newXdim))
# Scale volume
Xdim = inputVolume.getXDim()
if Xdim != newXdim:
self.runJob("xmipp_image_resize", "-i %s --dim %d"
% (self._getInputVolFn(), newXdim), numberOfMpi=1)
开发者ID:I2PC,项目名称:scipion,代码行数:31,代码来源:protocol_solid_angles.py
示例5: test_readDM4
def test_readDM4(self):
""" Check we can read dm4 files (using EMAN)
"""
micFn = self.dsFormat.getFile('SuperRef_c3-adp-se-xyz-0228_001.dm4')
ih = ImageHandler()
# Check that we can read the dimensions of the dm4 file:
EXPECTED_SIZE = (7676, 7420, 1, 1)
self.assertEqual(ih.getDimensions(micFn), EXPECTED_SIZE)
# We could even convert to an mrc file:
outSuffix = pwutils.replaceBaseExt(micFn, 'mrc')
outFn = join('/tmp', outSuffix)
print "Converting: \n%s -> %s" % (micFn, outFn)
ih.convert(micFn, outFn)
self.assertTrue(os.path.exists(outFn))
self.assertTrue(pwutils.getFileSize(outFn) > 0)
# Check dimensions are still the same:
self.assertEqual(ih.getDimensions(outFn), EXPECTED_SIZE)
# Clean up tmp files
pwutils.cleanPath(outFn)
开发者ID:I2PC,项目名称:scipion,代码行数:25,代码来源:test_data.py
示例6: _validateImages
def _validateImages(self):
errors = []
ih = ImageHandler()
for imgFn, _ in self.iterFiles():
if isdir(imgFn):
errors.append("Folders can not be selected.")
errors.append(' %s' % imgFn)
else:
# Check if images are correct by reading the header of the
# imported files:
# Exceptions:
# - Compressed movies (bz2 or tbz extensions)
# - Importing in streaming, since files may be incomplete
# - Bad characters in path [':' ,'%', '#']
if (not self.dataStreaming and
not (imgFn.endswith('bz2') or
imgFn.endswith('tbz') or
ih.isImageFile(imgFn))):
if not errors: # if empty add the first line
errors.append("Error reading the following images:")
errors.append(' %s' % imgFn)
errors += ProtImportImages.validatePath(imgFn)
return errors
开发者ID:I2PC,项目名称:scipion,代码行数:26,代码来源:images.py
示例7: createOutputStep
def createOutputStep(self):
particles = self.inputParticles.get()
# Generate the SetOfAlignmet
alignedSet = self._createSetOfParticles()
alignedSet.copyInfo(particles)
inputMd = self._getPath('aligned_particles.xmd')
alignedSet.copyItems(particles,
updateItemCallback=self._updateItem,
itemDataIterator=iterMdRows(inputMd))
# Remove alignment 2D
alignedSet.setAlignment(ALIGN_NONE)
# Define the output average
avgFile = self._getExtraPath("average.xmp")
imgh = ImageHandler()
avgImage = imgh.computeAverage(alignedSet)
avgImage.write(avgFile)
avg = Particle()
avg.setLocation(1, avgFile)
avg.copyInfo(alignedSet)
self._defineOutputs(outputAverage=avg)
self._defineSourceRelation(self.inputParticles, avg)
self._defineOutputs(outputParticles=alignedSet)
self._defineSourceRelation(self.inputParticles, alignedSet)
开发者ID:denisfortun,项目名称:scipion,代码行数:32,代码来源:protocol_apply_alignment.py
示例8: prepareMask
def prepareMask(self,maskObject,fnMask,TsMaskOut,XdimOut):
img=ImageHandler()
img.convert(maskObject, fnMask)
self.runJob('xmipp_image_resize',"-i %s --factor %f"%(fnMask,maskObject.getSamplingRate()/TsMaskOut),numberOfMpi=1)
maskXdim, _, _, _ =img.getDimensions((1,fnMask))
if XdimOut!=maskXdim:
self.runJob('xmipp_transform_window',"-i %s --size %d"%(fnMask,XdimOut),numberOfMpi=1)
self.runJob('xmipp_transform_threshold',"-i %s --select below 0.5 --substitute binarize"%fnMask,numberOfMpi=1)
开发者ID:azazellochg,项目名称:scipion,代码行数:8,代码来源:protocol_split_volume.py
示例9: _runBeforePreWhitening
def _runBeforePreWhitening(self):
prot = self.form.protocol
# Convert input volumes
ih = ImageHandler()
ih.convert(prot.inputVolume.get(), join(self.workingDir, 'volume1.map'))
if prot.useSplitVolume:
ih.convert(prot.splitVolume.get(), join(self.workingDir, 'volume2.map'))
self.results = prot.runResmap(self.workingDir, wizardMode=True)
开发者ID:josegutab,项目名称:scipion,代码行数:9,代码来源:wizard.py
示例10: _particlesToEmx
def _particlesToEmx(emxData, partSet, micSet=None, **kwargs):
""" Write a SetOfMicrograph as expected in EMX format
Params:
micSet: input set of micrographs
filename: the EMX file where to store the micrographs information.
micSet: micrographs set associated with the particles
**kwargs: writeImages: if set to False, only coordinates are exported.
imagesStack: if passed all images will be output into a single
stack file.
imagesPrefix: used when not imagesStack is passed. A different
stack will be created per micrograph.
"""
writeImages = kwargs.get('writeImages', True)
imagesPrefix = kwargs.get('imagesPrefix', None)
micDict = {}
# Use singleMic for count all particles to be written to a single stack
imagesStack = kwargs.get('imagesStack', None)
singleMic = Micrograph()
singleMic.setFileName(imagesStack)
singleMic.counter = pwobj.Integer(0)
def _getMicKey(particle):
coord = particle.getCoordinate()
if coord is None or coord.getMicName() is None:
return '%05d' % particle.getMicId()
else:
return pwutils.removeExt(coord.getMicName())
def _getLocation(particle):
if imagesStack is not None:
mic = singleMic
else:
micKey = _getMicKey(particle)
if micKey not in micDict:
mic = Micrograph()
mic.setFileName(join(imagesPrefix, 'particles_%s.mrc' % micKey))
mic.counter = pwobj.Integer(0)
micDict[micKey] = mic
else:
mic = micDict[micKey]
# Count one more particle assigned to this micrograph
mic.counter.increment()
return (mic.counter.get(), mic.getFileName())
ih = ImageHandler()
partAlign = partSet.getAlignment()
for particle in partSet:
if writeImages:
newLoc = _getLocation(particle)
ih.convert(particle, newLoc)
localFn = basename(newLoc[1])
particle.setLocation(newLoc[0], localFn)
emxObj = _particleToEmx(emxData, particle, micSet, partAlign)
else:
emxObj = _coordinateToEmx(emxData, particle, micSet)
emxData.addObject(emxObj)
开发者ID:azazellochg,项目名称:scipion,代码行数:57,代码来源:convert.py
示例11: projectInitialVolume
def projectInitialVolume(self):
fnOutputInitVolume=self._getTmpPath("initialVolume.vol")
img = ImageHandler()
img.convert(self.initialVolume.get(), fnOutputInitVolume)
self.runJob("xmipp_image_resize","-i %s --dim %d %d"%(fnOutputInitVolume,self.Xdim2,self.Xdim2))
fnGallery=self._getTmpPath('gallery_InitialVolume.stk')
fnOutputReducedClass = self._getExtraPath("reducedClasses.xmd")
self.runJob("xmipp_angular_project_library", "-i %s -o %s --sampling_rate %f --sym %s --method fourier 1 0.25 bspline --compute_neighbors --angular_distance -1 --experimental_images %s"\
%(fnOutputInitVolume,fnGallery,self.angularSampling.get(),self.symmetryGroup.get(),fnOutputReducedClass))
开发者ID:denisfortun,项目名称:scipion,代码行数:9,代码来源:protocol_ransac.py
示例12: importImagesStep
def importImagesStep(self, pattern, voltage, sphericalAberration, amplitudeContrast, magnification):
""" Copy images matching the filename pattern
Register other parameters.
"""
self.info("Using pattern: '%s'" % pattern)
createSetFunc = getattr(self, '_create' + self._outputClassName)
imgSet = createSetFunc()
imgSet.setIsPhaseFlipped(self.haveDataBeenPhaseFlipped.get())
acquisition = imgSet.getAcquisition()
self.fillAcquisition(acquisition)
# Call a function that should be implemented by each subclass
self.setSamplingRate(imgSet)
outFiles = [imgSet.getFileName()]
imgh = ImageHandler()
img = imgSet.ITEM_TYPE()
img.setAcquisition(acquisition)
n = 1
copyOrLink = self.getCopyOrLink()
for i, (fileName, fileId) in enumerate(self.iterFiles()):
dst = self._getExtraPath(basename(fileName))
copyOrLink(fileName, dst)
# Handle special case of Imagic images, copying also .img or .hed
self.handleImgHed(copyOrLink, fileName, dst)
if self._checkStacks:
_, _, _, n = imgh.getDimensions(dst)
if n > 1:
for index in range(1, n+1):
img.cleanObjId()
img.setMicId(fileId)
img.setFileName(dst)
img.setIndex(index)
imgSet.append(img)
else:
img.setObjId(fileId)
img.setFileName(dst)
self._fillMicName(img, fileName) # fill the micName if img is a Micrograph.
imgSet.append(img)
outFiles.append(dst)
sys.stdout.write("\rImported %d/%d" % (i+1, self.numberOfFiles))
sys.stdout.flush()
print "\n"
args = {}
outputSet = self._getOutputName()
args[outputSet] = imgSet
self._defineOutputs(**args)
return outFiles
开发者ID:azazellochg,项目名称:scipion,代码行数:56,代码来源:images.py
示例13: convertInputStep
def convertInputStep(self, volLocation1, volLocation2=None):
""" Convert input volume to .mrc as expected by ResMap.
Params:
volLocation1: a tuple containing index and filename of the input volume.
volLocation2: if not None, a tuple like volLocation1 for the split volume.
"""
ih = ImageHandler()
ih.convert(volLocation1, self._getPath('volume1.map'))
if volLocation2 is not None:
ih.convert(volLocation2, self._getPath('volume2.map'))
开发者ID:coocoky,项目名称:scipion,代码行数:10,代码来源:protocol_resmap.py
示例14: _beforePreWhitening
def _beforePreWhitening(protocol, dir):
from pyworkflow.em.convert import ImageHandler
# Convert input volumes
ih = ImageHandler()
inputVolume = protocol.inputVolume.get()
path = join(dir, 'volume1.map')
print path
ih.convert(inputVolume, path)
if protocol.useSplitVolume:
ih.convert(protocol.splitVolume.get(), join(dir, 'volume2.map'))
return protocol.runResmap(dir, wizardMode=True)
开发者ID:azazellochg,项目名称:scipion,代码行数:12,代码来源:resmap_wizard.py
示例15: createMaskStep
def createMaskStep(self):
""" Create a circular mask in Imagic format. """
inputParticles = self.inputParticles.get()
radius = self.radius.get()
if self.maskType.get() == 0:
if radius < 0: # usually -1
radiusMask = inputParticles.getDim()[0] / 2 # use half of input dim
else:
radiusMask = radius
outMask = self._getTmpPath('mask.img')
ih = ImageHandler()
ih.createCircularMask(radiusMask, inputParticles.getFirstItem(), outMask)
开发者ID:I2PC,项目名称:scipion,代码行数:13,代码来源:protocol_msa.py
示例16: testExistLocation
def testExistLocation(self):
volFn = self.dataset.getFile('volumes/volume_1_iter_002.mrc')
ih = ImageHandler()
# Test the volume filename exists
self.assertTrue(ih.existsLocation(volFn))
# Test missing filename
self.assertFalse(ih.existsLocation(volFn.replace('.mrc', '_fake.mrc')))
# Test the :mrc is append when used as volume
newFn = ih.getVolFileName(volFn)
self.assertEqual(newFn, volFn + ":mrc")
# Test that the new filename still exists even with the :mrc suffix
self.assertTrue(ih.existsLocation(newFn))
开发者ID:I2PC,项目名称:scipion,代码行数:13,代码来源:test_data.py
示例17: convertStep
def convertStep(self, imgsFn):
from convert import writeSetOfClasses2D, writeSetOfParticles
imgSet = self.inputSet.get()
if isinstance(imgSet, SetOfClasses2D):
writeSetOfClasses2D(imgSet, self.imgsFn, writeParticles=True)
else:
writeSetOfParticles(imgSet, self.imgsFn)
from pyworkflow.em.convert import ImageHandler
img = ImageHandler()
fnVol = self._getTmpPath("volume.vol")
img.convert(self.inputVolume.get(), fnVol)
xdim=self.inputVolume.get().getDim()[0]
if xdim!=self._getDimensions():
self.runJob("xmipp_image_resize","-i %s --dim %d"%(fnVol,self._getDimensions()))
开发者ID:I2PC,项目名称:scipion,代码行数:14,代码来源:protocol_compare_reprojections.py
示例18: convertInputStep
def convertInputStep(self, particlesId):
""" Write the input images as a Xmipp metadata file.
particlesId: is only need to detect changes in
input particles and cause restart from here.
"""
writeSetOfParticles(self.inputParticles.get(),
self._getPath('input_particles.xmd'))
if self.doWiener.get():
params = ' -i %s' % self._getPath('input_particles.xmd')
params += ' -o %s' % self._getExtraPath('corrected_ctf_particles.stk')
params += ' --save_metadata_stack %s' % self._getExtraPath('corrected_ctf_particles.xmd')
params += ' --pad %s' % self.padding_factor.get()
params += ' --wc %s' % self.wiener_constant.get()
params += ' --sampling_rate %s' % self.inputParticles.get().getSamplingRate()
if self.inputParticles.get().isPhaseFlipped():
params += ' --phase_flipped '
if self.correctEnvelope:
params += ' --correct_envelope '
nproc = self.numberOfMpi.get()
nT=self.numberOfThreads.get()
self.runJob('xmipp_ctf_correct_wiener2d',
params)
newTs, newXdim = self._getModifiedSizeAndSampling()
if self.doWiener.get():
params = ' -i %s' % self._getExtraPath('corrected_ctf_particles.xmd')
else :
params = ' -i %s' % self._getPath('input_particles.xmd')
params += ' -o %s' % self._getExtraPath('scaled_particles.stk')
params += ' --save_metadata_stack %s' % self._getExtraPath('scaled_particles.xmd')
params += ' --fourier %d' % newXdim
self.runJob('xmipp_image_resize',params)
from pyworkflow.em.convert import ImageHandler
img = ImageHandler()
img.convert(self.inputVolumes.get(), self._getExtraPath("volume.vol"))
Xdim = self.inputVolumes.get().getDim()[0]
if Xdim!=newXdim:
self.runJob("xmipp_image_resize","-i %s --dim %d"%\
(self._getExtraPath("volume.vol"),
newXdim), numberOfMpi=1)
开发者ID:I2PC,项目名称:scipion,代码行数:50,代码来源:protocol_multireference_alignability.py
示例19: _beforePreview
def _beforePreview(self):
ImagePreviewDialog._beforePreview(self)
self.lastObj = None
self.rightPreviewLabel = "PSD"
self.message = "Computing PSD..."
self.previewLabel = "Micrograph"
self.rightImage = ImageHandler()._img
开发者ID:coocoky,项目名称:scipion,代码行数:7,代码来源:wizard.py
示例20: buildDendrogram
def buildDendrogram(self, writeAverages=False):
""" Parse Spider docfile with the information to build the dendogram.
Params:
dendroFile: docfile with a row per image.
Each row contains the image id and the height.
"""
dendroFile = self._getFileName('dendroDoc')
# Dendrofile is a docfile with at least 3 data colums (class, height, id)
doc = SpiderDocFile(dendroFile)
values = []
indexes = []
for c, h, _ in doc.iterValues():
indexes.append(c)
values.append(h)
doc.close()
self.dendroValues = values
self.dendroIndexes = indexes
self.dendroImages = self._getFileName('particles')
self.dendroAverages = self._getFileName('averages')
self.dendroAverageCount = 0 # Write only the number of needed averages
self.dendroMaxLevel = 10 # FIXME: remove hard coding if working the levels
self.ih = ImageHandler()
return self._buildDendrogram(0, len(values)-1, 1, writeAverages)
开发者ID:denisfortun,项目名称:scipion,代码行数:25,代码来源:protocol_classify_base.py
注:本文中的pyworkflow.em.convert.ImageHandler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论