当前位置: 首页>>代码示例>>Python>>正文


Python ImagePlus.setProperty方法代码示例

本文整理汇总了Python中ij.ImagePlus.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Python ImagePlus.setProperty方法的具体用法?Python ImagePlus.setProperty怎么用?Python ImagePlus.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ij.ImagePlus的用法示例。


在下文中一共展示了ImagePlus.setProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_registered_hyperstack

# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import setProperty [as 别名]
def create_registered_hyperstack(imp, channel, target_folder, virtual):
  """ Takes the imp, determines the x,y,z drift for each pair of time points, using the preferred given channel,
  and outputs as a hyperstack."""
  shifts = compute_frame_translations(imp, channel)
  # Make shifts relative to 0,0,0 of the original imp:
  shifts = concatenate_shifts(shifts)
  print "shifts concatenated:"
  for s in shifts:
    print s.x, s.y, s.z
  # Compute bounds of the new volume,
  # which accounts for all translations:
  minx, miny, minz, maxx, maxy, maxz = compute_min_max(shifts)
  # Make shifts relative to new canvas dimensions
  # so that the min values become 0,0,0
  for shift in shifts:
    shift.x -= minx
    shift.y -= miny
    shift.z -= minz
  print "shifts relative to new dimensions:"
  for s in shifts:
    print s.x, s.y, s.z
  # new canvas dimensions:
  width = imp.width + maxx - minx
  height = maxy - miny + imp.height
  slices = maxz - minz + imp.getNSlices()

  print "New dimensions:", width, height, slices
  # Prepare empty slice to pad in Z when necessary
  empty = imp.getProcessor().createProcessor(width, height)

  # if it's RGB, fill the empty slice with blackness
  if isinstance(empty, ColorProcessor):
    empty.setValue(0)
    empty.fill()
  # Write all slices to files:
  stack = imp.getStack()

  if virtual is False:
  	registeredstack = ImageStack(width, height, imp.getProcessor().getColorModel())
  names = []
  for frame in range(1, imp.getNFrames()+1):
    shift = shifts[frame-1]
    fr = "t" + zero_pad(frame, len(str(imp.getNFrames())))
    # Pad with empty slices before reaching the first slice
    for s in range(shift.z):
      ss = "_z" + zero_pad(s + 1, len(str(slices))) # slices start at 1
      for ch in range(1, imp.getNChannels()+1):
        name = fr + ss + "_c" + zero_pad(ch, len(str(imp.getNChannels()))) +".tif"
        names.append(name)

        if virtual is True:
          currentslice = ImagePlus("", empty)
          currentslice.setCalibration(imp.getCalibration().copy())
          currentslice.setProperty("Info", imp.getProperty("Info"))
          FileSaver(currentslice).saveAsTiff(target_folder + "/" + name)
        else:
          empty = imp.getProcessor().createProcessor(width, height)
          registeredstack.addSlice(str(name), empty)
    # Add all proper slices
    stack = imp.getStack()
    for s in range(1, imp.getNSlices()+1):
      ss = "_z" + zero_pad(s + shift.z, len(str(slices)))
      for ch in range(1, imp.getNChannels()+1):
         ip = stack.getProcessor(imp.getStackIndex(ch, s, frame))
         ip2 = ip.createProcessor(width, height) # potentially larger
         ip2.insert(ip, shift.x, shift.y)
         name = fr + ss + "_c" + zero_pad(ch, len(str(imp.getNChannels()))) +".tif"
         names.append(name)

         if virtual is True:
           currentslice = ImagePlus("", ip2)
           currentslice.setCalibration(imp.getCalibration().copy())
           currentslice.setProperty("Info", imp.getProperty("Info"));
           FileSaver(currentslice).saveAsTiff(target_folder + "/" + name)
         else:
           registeredstack.addSlice(str(name), ip2)

    # Pad the end
    for s in range(shift.z + imp.getNSlices(), slices):
      ss = "_z" + zero_pad(s + 1, len(str(slices)))
      for ch in range(1, imp.getNChannels()+1):
        name = fr + ss + "_c" + zero_pad(ch, len(str(imp.getNChannels()))) +".tif"
        names.append(name)

        if virtual is True:
          currentslice = ImagePlus("", empty)
          currentslice.setCalibration(imp.getCalibration().copy())
          currentslice.setProperty("Info", imp.getProperty("Info"))
          FileSaver(currentslice).saveAsTiff(target_folder + "/" + name)
        else:
          registeredstack.addSlice(str(name), empty)

  if virtual is True:
      # Create virtual hyper stack with the result
      registeredstack = VirtualStack(width, height, None, target_folder)
      for name in names:
        registeredstack.addSlice(name)
      registeredstack_imp = ImagePlus("registered time points", registeredstack)
      registeredstack_imp.setDimensions(imp.getNChannels(), len(names) / (imp.getNChannels() * imp.getNFrames()), imp.getNFrames())
      registeredstack_imp.setCalibration(imp.getCalibration().copy())
#.........这里部分代码省略.........
开发者ID:Ghostqiu,项目名称:fiji,代码行数:103,代码来源:Correct_3D_drift.py

示例2: register_hyperstack_subpixel

# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import setProperty [as 别名]
def register_hyperstack_subpixel(imp, channel, shifts, target_folder, virtual):
  """ Takes the imp, determines the x,y,z drift for each pair of time points, using the preferred given channel,
  and outputs as a hyperstack.
  The shifted image is computed using TransformJ allowing for sub-pixel shifts using interpolation.
  This is quite a bit slower than just shifting the image by full pixels as done in above function register_hyperstack().
  However it significantly improves the result by removing pixel jitter.
  """
  # Compute bounds of the new volume,
  # which accounts for all translations:
  minx, miny, minz, maxx, maxy, maxz = compute_min_max(shifts)
  # Make shifts relative to new canvas dimensions
  # so that the min values become 0,0,0
  for shift in shifts:
    shift.x -= minx
    shift.y -= miny
    shift.z -= minz
  # new canvas dimensions:
  width = int(imp.width + maxx - minx)
  height = int(maxy - miny + imp.height)
  slices = int(maxz - minz + imp.getNSlices())

  print "New dimensions:", width, height, slices
    
  # prepare stack for final results
  stack = imp.getStack()
  if virtual is True: 
    names = []
  else:
    registeredstack = ImageStack(width, height, imp.getProcessor().getColorModel())
  
  # prepare empty slice for padding
  empty = imp.getProcessor().createProcessor(width, height)

  IJ.showProgress(0)

  # get raw data as stack
  stack = imp.getStack()

  # loop across frames
  for frame in range(1, imp.getNFrames()+1):
      
    IJ.showProgress(frame / float(imp.getNFrames()+1))
    fr = "t" + zero_pad(frame, len(str(imp.getNFrames()))) # for saving files in a virtual stack
    
    # get and report current shift
    shift = shifts[frame-1]
    print "frame",frame,"correcting drift",-shift.x-minx,-shift.y-miny,-shift.z-minz
    IJ.log("    frame "+str(frame)+" correcting drift "+str(round(-shift.x-minx,2))+","+str(round(-shift.y-miny,2))+","+str(round(-shift.z-minz,2)))

    # loop across channels
    for ch in range(1, imp.getNChannels()+1):      
      
      tmpstack = ImageStack(width, height, imp.getProcessor().getColorModel())

      # get all slices of this channel and frame
      for s in range(1, imp.getNSlices()+1):
        ip = stack.getProcessor(imp.getStackIndex(ch, s, frame))
        ip2 = ip.createProcessor(width, height) # potentially larger
        ip2.insert(ip, 0, 0)
        tmpstack.addSlice("", ip2)

      # Pad the end (in z) of this channel and frame
      for s in range(imp.getNSlices(), slices):
        tmpstack.addSlice("", empty)

      # subpixel translation
      imp_tmpstack = ImagePlus("", tmpstack)
      imp_translated = translate_single_stack_using_imglib2(imp_tmpstack, shift.x, shift.y, shift.z)
      
      # add translated stack to final time-series
      translated_stack = imp_translated.getStack()
      for s in range(1, translated_stack.getSize()+1):
        ss = "_z" + zero_pad(s, len(str(slices)))
        ip = translated_stack.getProcessor(s).duplicate() # duplicate is important as otherwise it will only be a reference that can change its content  
        if virtual is True:
          name = fr + ss + "_c" + zero_pad(ch, len(str(imp.getNChannels()))) +".tif"
          names.append(name)
          currentslice = ImagePlus("", ip)
          currentslice.setCalibration(imp.getCalibration().copy())
          currentslice.setProperty("Info", imp.getProperty("Info"));
          FileSaver(currentslice).saveAsTiff(target_folder + "/" + name)
        else:
          registeredstack.addSlice("", ip)    

  IJ.showProgress(1)
    
  if virtual is True:
    # Create virtual hyper stack
    registeredstack = VirtualStack(width, height, None, target_folder)
    for name in names:
      registeredstack.addSlice(name)
  
  registeredstack_imp = ImagePlus("registered time points", registeredstack)
  registeredstack_imp.setCalibration(imp.getCalibration().copy())
  registeredstack_imp.setProperty("Info", imp.getProperty("Info"))
  registeredstack_imp = HyperStackConverter.toHyperStack(registeredstack_imp, imp.getNChannels(), slices, imp.getNFrames(), "xyzct", "Composite");    
  
  return registeredstack_imp
开发者ID:tischi,项目名称:fiji-correct-3d-drift,代码行数:100,代码来源:Correct_3D_Drift_Plus--ImgLib2.py

示例3: xrange

# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import setProperty [as 别名]
import os
from ij import IJ, ImagePlus


orig = IJ.getImage()
cal = orig.getCalibration()
inf = orig.getProperty("Info")
new = orig.duplicate()
ti = orig.getShortTitle()
IJ.run(new, "32-bit", "")
new.setTitle(ti + "-32")
ip = new.getProcessor()

minV = ip.getMin()
maxV = ip.getMax()
delta = maxV-minV
factor = 1.0/delta

pixels = ip.getPixels()
for i in xrange(len(pixels)):  
  pixels[i] -= minV
  pixels[i] *= factor

new = ImagePlus(ti + "-32", ip)  
new.setDisplayRange(0.0, 1.0)
new.setCalibration(cal)
new.setProperty("Info", inf)

# print(minV, maxV)

new.show()
开发者ID:jrminter,项目名称:OSImageAnalysis,代码行数:33,代码来源:make32bitZeroToOne.py

示例4: register_hyperstack_subpixel

# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import setProperty [as 别名]
def register_hyperstack_subpixel(imp, channel, shifts, target_folder, virtual):
  """ Takes the imp, determines the x,y,z drift for each pair of time points, using the preferred given channel,
  and outputs as a hyperstack.
  The shifted image is computed using TransformJ allowing for sub-pixel shifts using interpolation.
  This is quite a bit slower than just shifting the image by full pixels as done in above function register_hyperstack().
  However it significantly improves the result by removing pixel jitter.
  """
  # Compute bounds of the new volume,
  # which accounts for all translations:
  minx, miny, minz, maxx, maxy, maxz = compute_min_max(shifts)
  # Make shifts relative to new canvas dimensions
  # so that the min values become 0,0,0
  for shift in shifts:
    shift.x -= minx
    shift.y -= miny
    shift.z -= minz
  # new canvas dimensions:
  width = int(imp.width + maxx - minx)
  height = int(maxy - miny + imp.height)
  slices = int(maxz - minz + imp.getNSlices())

  print "New dimensions:", width, height, slices
  
  # prepare stack for final results
  stack = imp.getStack()
  if virtual is True: 
    names = []
  else:
    registeredstack = ImageStack(width, height, imp.getProcessor().getColorModel())
  
  # prepare empty slice for padding
  empty = imp.getProcessor().createProcessor(width, height)

  IJ.showProgress(0)
  
  for frame in range(1, imp.getNFrames()+1):
      
    IJ.showProgress(frame / float(imp.getNFrames()+1))
    fr = "t" + zero_pad(frame, len(str(imp.getNFrames()))) # for saving files in a virtual stack
    
    # init
    shift = shifts[frame-1]
    tmpstack = ImageStack(width, height, imp.getProcessor().getColorModel())

    print "frame",frame,"correcting drift",-shift.x-minx,-shift.y-miny,-shift.z-minz
    IJ.log("    frame "+str(frame)+" correcting drift "+str(round(-shift.x-minx,2))+","+str(round(-shift.y-miny,2))+","+str(round(-shift.z-minz,2)))

    # for doing the same with imglib2 i would have to put the channel loop 
    # to the outside and translate each individual channel as long as i don't figure out 
    # to two wrap a composite imglib2 image into an imp
        
    # Add all slices of this frame
    stack = imp.getStack()
    for s in range(1, imp.getNSlices()+1):
      for ch in range(1, imp.getNChannels()+1):
         ip = stack.getProcessor(imp.getStackIndex(ch, s, frame))
         ip2 = ip.createProcessor(width, height) # potentially larger
         ip2.insert(ip, 0, 0)
         tmpstack.addSlice("", ip2)

    # Pad the end (in z) of this frame
    for s in range(imp.getNSlices(), slices):
      for ch in range(1, imp.getNChannels()+1):
         tmpstack.addSlice("", empty)

    # Set correct dimensions of this frame 
    # ..it is important *not* to set the calibration as translation should be in pixels units
    imp_tmpstack = ImagePlus("registered time points", tmpstack)
    imp_tmpstack.setProperty("Info", imp.getProperty("Info"))
    imp_tmpstack.setDimensions(imp.getNChannels(), slices, 1)
    imp_tmpstack.setOpenAsHyperStack(True)
    
    # subpixel translation
    imp_translated = translate_using_imagescience(imp_tmpstack, shift.x, shift.y, shift.z)
    #imp_translated = translate_using_imglib2(imp_tmpstack, shift.x, shift.y, shift.z)
    
    imp_translated.setProperty("Info", imp.getProperty("Info"))
    imp_translated.setDimensions(imp.getNChannels(), slices, 1)
    imp_translated.setOpenAsHyperStack(True)

    # Add translated frame to final time-series
    stack = imp_translated.getStack()
    for s in range(1, imp_translated.getNSlices()+1):
      ss = "_z" + zero_pad(s, len(str(slices)))
      for ch in range(1, imp_translated.getNChannels()+1):
         ip = stack.getProcessor(imp_translated.getStackIndex(ch, s, 1))
         if virtual is True:
           name = fr + ss + "_c" + zero_pad(ch, len(str(imp.getNChannels()))) +".tif"
           names.append(name)
           currentslice = ImagePlus("", ip)
           currentslice.setCalibration(imp.getCalibration().copy())
           currentslice.setProperty("Info", imp.getProperty("Info"));
           FileSaver(currentslice).saveAsTiff(target_folder + "/" + name)
         else:
           registeredstack.addSlice("", ip)
  
  IJ.showProgress(1)

  if virtual is True:
    # Create virtual hyper stack with the result
#.........这里部分代码省略.........
开发者ID:tischi,项目名称:fiji-correct-3d-drift,代码行数:103,代码来源:2016-01-21--Tischi--Correct_3D_Drift_Plus.py

示例5: PrepareDatabase

# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import setProperty [as 别名]
def PrepareDatabase(minw, maxw, baseDir, aspectRatio, majorWidth, majorHeight):
	outputpath = baseDir + "/" + str(majorWidth) + "_" + str(majorHeight) + "_orig.tif"
	#initialize stacks and labels
	stackScaled = []
	stackOrig = ImageStack(majorWidth, majorHeight)
	imageNames = []
	for i in range(minw, maxw+1):
		stackScaled.append(ImageStack(i, int(round(i/aspectRatio, 0))))
		imageNames.append('')

	counter = 0

	# initialize zip file for originals
	zf = zipfile.ZipFile(baseDir + "/originals.zip", mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=1)
	zf.writestr('from_string.txt', 'hello')
	zf.close()
	zf = zipfile.ZipFile(baseDir + "/originals.zip", mode='a', compression=zipfile.ZIP_DEFLATED, allowZip64=1)

	for root, dirs, files in os.walk(str(baseDir)):
		for f1 in files:
			if f1.endswith(".jpg") or f1.endswith(".jpe") or f1.endswith(".jpeg"):
				id = root + "/" +  f1
				IJ.redirectErrorMessages()
				IJ.redirectErrorMessages(1)
				imp = IJ.openImage(id)
				if imp is None:
					print "Couldn\'t open image from file:", id
					continue
				# skip non RGBimages
				if imp.getProcessor().getNChannels() != 3:
					print "Converting non RGB image:", id
					if imp.getStackSize() > 1:
						StackConverter(imp).convertToRGB()
					else:
						ImageConverter(imp).convertToRGB()
				#skip images with different aspect ratio
				width = imp.getWidth()
				height = imp.getHeight()
				ratio = round(float(width)/float(height), 2) # this makes the ratio filering approximate, minor variations in image dimensions will be ignored
				if ratio != aspectRatio:
					IJ.log("Skipping image of size: " + str(width) + "," + str(height))
					continue
				# now scale the image within a given range
				scale = Scale(imp.getProcessor())
				IJ.log("Scaling image " + str(counter) + " " + str(id))
				for i in range(minw, maxw+1):
					stackScaled[i-minw].addSlice(None, ScaleImageToSize(scale, i, int(round(i/aspectRatio, 0))))
					imageNames[i-minw] += str(id) + ";"
				# save the originals to a temp directory
				scaledOrig = ImagePlus(None, ScaleImageToSize(scale, majorWidth, majorHeight))
				SaveToZip(zf, scaledOrig, baseDir, counter)
				counter += 1
	zf.close()
	# save the stacks
	for i in range(minw, maxw+1):
		impScaled = ImagePlus(str(minw) + "_" + str(int(round(i/aspectRatio, 0))), stackScaled[i-minw])
		impScaled.show()
		#print imageNames
		impScaled.setProperty('Info', imageNames[i-minw][:-1])
		fs = FileSaver(impScaled)
		filepath = baseDir + "/" + str(i) + "_" + str(int(round(i/aspectRatio, 0))) + ".tif"
		IJ.log("Saving output stack" + str(filepath))
		fs.saveAsTiffStack(filepath)
		#IJ.save(impScaled, filepath);
		IJ.log("Done")
开发者ID:151706061,项目名称:fiji,代码行数:67,代码来源:Prepare_Cover_Maker_Database.py

示例6: regBf

# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import setProperty [as 别名]

#.........这里部分代码省略.........
    refImp = ImagePlus("ref", stack.getProcessor(imp.getStackIndex(refC, refZ, refT)))
    refWin.setImage(refImp)

    tr = TurboReg_()

    for t in xrange(1, nFrames+1):
        IJ.showProgress(t-1, nFrames)

        # print "t ", t
        # do TurboReg on reference channel
        toRegId = imp.getStackIndex(refC, refZ, t)
        toRegImp = ImagePlus("toReg", stack.getProcessor(toRegId))
        toRegWin.setImage(toRegImp)

        regArg =  "-align " +\
                  "-window " + toRegImp.getTitle() + " " +\
                  "0 0 " + str(width - 1) + " " + str(height - 1) + " " +\
                  "-window " + refImp.getTitle() + " " +\
                  "0 0 " + str(width - 1) + " " + str(height - 1) + " " +\
                  "-rigidBody " +\
                  str(width / 2) + " " + str(height / 2) + " " +\
                  str(width / 2) + " " + str(height / 2) + " " +\
                  "0 " + str(height / 2) + " " +\
                  "0 " + str(height / 2) + " " +\
                  str(width - 1) + " " + str(height / 2) + " " +\
                  str(width - 1) + " " + str(height / 2) + " " +\
                  "-hideOutput"
                
        tr = TurboReg_()
        tr.run(regArg)
        registeredImp = tr.getTransformedImage()
        sourcePoints = tr.getSourcePoints()
        targetPoints = tr.getTargetPoints()

        registeredStack.setProcessor(registeredImp.getProcessor(), toRegId)

        # toRegImp.flush()

        # apply transformation on other channels
        for c in xrange(1, nChannels+1):
            # print "c ", c
            if c == refC:
                continue

            toTransformId = imp.getStackIndex(c, 1, t)
            toTransformImp = ImagePlus("toTransform", stack.getProcessor(toTransformId))
            toTransformWin.setImage(toTransformImp)

            transformArg = "-transform " +\
                           "-window " + toTransformImp.getTitle() + " " +\
                           str(width) + " " + str(height) + " " +\
                           "-rigidBody " +\
                           str(sourcePoints[0][0]) + " " +\
                           str(sourcePoints[0][1]) + " " +\
                           str(targetPoints[0][0]) + " " +\
                           str(targetPoints[0][1]) + " " +\
                           str(sourcePoints[1][0]) + " " +\
                           str(sourcePoints[1][1]) + " " +\
                           str(targetPoints[1][0]) + " " +\
                           str(targetPoints[1][1]) + " " +\
                           str(sourcePoints[2][0]) + " " +\
                           str(sourcePoints[2][1]) + " " +\
                           str(targetPoints[2][0]) + " " +\
                           str(targetPoints[2][1]) + " " +\
                           "-hideOutput"

            tr = TurboReg_()
            tr.run(transformArg)
            registeredStack.setProcessor(tr.getTransformedImage().getProcessor(), toTransformId)

            # toTransformImp.flush()
            sourcePoints = None
            targetPoints = None

        IJ.showProgress(t, nFrames)
        IJ.showStatus("Frames registered: " + str(t) + "/" + str(nFrames))

    refWin.close()
    toRegWin.close()
    toTransformWin.close()

    imp2 = ImagePlus("reg_"+imp.getTitle(), registeredStack)
    imp2.setCalibration(imp.getCalibration().copy())
    imp2.setDimensions(nChannels, nSlices, nFrames)
    # print "type ", imp.getType()
    # print "type ", imp2.getType()
    # print nChannels, " ", nSlices, " ", nFrames
    # print registeredStack.getSize()

    for key in imp.getProperties().stringPropertyNames():
        imp2.setProperty(key, imp.getProperty(key))
    # comp = CompositeImage(imp2, CompositeImage.COLOR)  
    # comp.show()
    # imp2 = imp.clone()
    # imp2.setStack(registeredStack)
    # imp2.setTitle("reg"+imp.getTitle())
    # imp2.show()
    # imp.show()

    return imp2
开发者ID:singingstars,项目名称:lab-program,代码行数:104,代码来源:split.reg.nd2_.py


注:本文中的ij.ImagePlus.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。