本文整理汇总了Python中ij.WindowManager.getCurrentImage方法的典型用法代码示例。如果您正苦于以下问题:Python WindowManager.getCurrentImage方法的具体用法?Python WindowManager.getCurrentImage怎么用?Python WindowManager.getCurrentImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.WindowManager
的用法示例。
在下文中一共展示了WindowManager.getCurrentImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_images
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def get_images(minimum=0, maximum=None, exact=None):
''' Returns a list of ImagePlus objects or None if it failed.
Passing None as parameter will trigger a dialog to show up to enter the exact number of images.
:param minimum: The minimum number of images to select (default: 0).
:param maximum: The maximum number of images to select (default: None).
:param exact: Set this to get an exact number of images (default: None).
'''
if not (minimum or maximum or exact):
exact = int(IJ.getNumber("How many images do you want to process?", 3))
def check_count(count):
'''Returns True if the count of images is as required.'''
# print count, exact, minimum, maximum
if exact:
if not count == exact:
return False
else:
if minimum:
if count < minimum:
return False
if maximum:
if count > maximum:
return False
return True
# Option 1: The selected image is a stack and has the demanded size.
if check_count(WindowManager.getCurrentImage().getStackSize()):
return stack_to_list_of_imp(WindowManager.getCurrentImage())
# Option 2: The count of open images matches the demanded number.
image_ids = WindowManager.getIDList()
if exact:
if len(image_ids) < exact:
return None
if len(image_ids) == exact:
return [WindowManager.getImage(img_id) for img_id in image_ids]
# Option 3: The user can select the images from a list.
image_titles = [WindowManager.getImage(id).getTitle() for id in image_ids]
img_count = len(image_ids)
if exact:
img_count = exact
elif maximum:
img_count = maximum
image_titles.append('None')
images_selected = dialogs.create_selection_dialog(image_titles,
range(img_count),
'Select images for drift correction'
)
# dialogs.create_selection_dialog() returns None if canceled
if not images_selected:
return None
# This is only true if 'None has been appended to image_titles and the user selected it.
if len(image_ids) in images_selected:
images_selected.remove(len(image_ids))
if not check_count(len(images_selected)):
return None
image_list = [WindowManager.getImage(image_ids[selection]) for selection in images_selected]
return image_list
示例2: getImage
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def getImage():
"""Get first open image or open Bio-Formats importer if no image is
available."""
imp = WindowManager.getCurrentImage()
if not imp:
# Show bio formats open dialog
IJ.run("Bio-Formats")
imp = WindowManager.getCurrentImage()
print("Start")
if not imp:
IJ.noImage()
raise ValueError("Need image")
return imp
示例3: select_images
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def select_images():
"""
Returns two ImagePlus objects that can be used by the drift correction.
If more than two images are available a dialog is used for selection.
"""
if WindowManager.getImageCount() > 0:
imp = WindowManager.getCurrentImage()
if imp.getImageStackSize() == 2:
dup = Duplicator()
img1 = dup.run(imp, 1, 1)
img1.setTitle("Slice1")
img2 = dup.run(imp, 2, 2)
img2.setTitle("Slice2")
elif WindowManager.getImageCount() == 2:
img1, img2 = [WindowManager.getImage(id) for id in WindowManager.getIDList()]
elif WindowManager.getImageCount() > 2:
image_ids = WindowManager.getIDList()
image_titles = [WindowManager.getImage(id).getTitle() for id in image_ids]
try:
sel1, sel2 = dialogs.create_selection_dialog(image_titles, range(2))
except TypeError:
return(None, None)
img1 = WindowManager.getImage(image_ids[sel1])
img2 = WindowManager.getImage(image_ids[sel2])
else:
IJ.error("You need two images to run the script.")
return(None, None)
else:
IJ.error("You need two images to run the script.")
return(None, None)
return (img1, img2)
示例4: main
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def main():
"""Get options and create new image."""
options = get_options()
if options is not None:
bwidth, bheight = options
img_cur = WindowManager.getCurrentImage()
img_new = boxed_intensities(img_cur, bwidth, bheight)
img_new.show()
示例5: straighten
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def straighten(stackName):
'''
IJ.run("Set Measurements...", "area mean min center redirect=None decimal=3")
IJ.open(stackName)
imp = IJ.getImage()
stack = imp.getImageStack()
for i in xrange(1, imp.getNSlices()+1):
image = ImagePlus(str(i), stack.getProcessor(i))
xvals = []
yvals = []
maxvals = []
j = 0
for k in xrange(0, 512, 2):
IJ.makeRectangle(k, 0, 4, 512)
IJ.run("Measure")
table = RT.getResultsTable()
x = table.getValue("XM", 0)
y = table.getValue("YM", 0)
#maxi = IJ.getResult("Max")
table = []
xvals.append(k)
yvals.append(y)
#maxvals.append(maxi)
#if maxvals[j] == 0 and j > 0:
#yvals[j] = yvals[j-1]
j += 1
print "xvals:", xvals
print "yvals:", yvals
mr = MR()
IJ.run("Make Selection...", "freeline, "+str(xvals)+" ,"+ str(yvals))
#IJ.runMacro("makeSelection...", "freeline, "+str(xvals)+" ,"+ str(yvals));
#IJ.run("makeSelection(\"freeline\", xvals, yvals);")
#IJ.run("Straighten...", "line = 80")
'''
IJ.open(stackName)
imp = IJ.getImage()
stack = imp.getImageStack()
print imp.getNSlices()
for i in range(1, imp.getNSlices()+1):
image = ImagePlus(str(i), stack.getProcessor(i))
IJ.runMacroFile("/Users/juliansegert/repos/Bio119_root_tracking/straightenOneImage.ijm")
newImp = WM.getCurrentImage()
fs = FileSaver(newImp)
fs.saveAsTiff("/Users/juliansegert/Documents/Roots/Four_root_image_stacks/Pos01/"+str(i)+".tif")
newImp.close()
示例6: main
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def main():
print "Starting script"
imp = WindowManager.getCurrentImage()
if not imp:
imp = MakeStack()
IJ.run(imp,"Properties...","")
scaled_imp = Resize(imp)
scaled_imp.show()
# WaitForUserDialog("Select an ROI if you want to restrict automatic contrast adjustment").show()
# imp.close()
AdjustContrast(scaled_imp)
ConvertTo8bit(scaled_imp)
示例7: run
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def run(imp, preprocessor_path, postprocessor_path, threshold_method, user_comment):
output_parameters = {"image title" : "",
"preprocessor path" : float,
"post processor path" : float,
"thresholding op" : float,
"use ridge detection" : bool,
"high contrast" : int,
"low contrast" : int,
"line width" : int,
"minimum line length" : int,
"mitochondrial footprint" : float,
"branch length mean" : float,
"branch length median" : float,
"branch length stdevp" : float,
"summed branch lengths mean" : float,
"summed branch lengths median" : float,
"summed branch lengths stdevp" : float,
"network branches mean" : float,
"network branches median" : float,
"network branches stdevp" : float}
output_order = ["image title",
"preprocessor path",
"post processor path",
"thresholding op",
"use ridge detection",
"high contrast",
"low contrast",
"line width",
"minimum line length",
"mitochondrial footprint",
"branch length mean",
"branch length median",
"branch length stdevp",
"summed branch lengths mean",
"summed branch lengths median",
"summed branch lengths stdevp",
"network branches mean",
"network branches median",
"network branches stdevp"]
# Perform any preprocessing steps...
status.showStatus("Preprocessing image...")
if preprocessor_path != None:
if preprocessor_path.exists():
preprocessor_thread = scripts.run(preprocessor_path, True)
preprocessor_thread.get()
imp = WindowManager.getCurrentImage()
else:
pass
# Store all of the analysis parameters in the table
if preprocessor_path == None:
preprocessor_str = ""
else:
preprocessor_str = preprocessor_path.getCanonicalPath()
if postprocessor_path == None:
postprocessor_str = ""
else:
postprocessor_str = preprocessor_path.getCanonicalPath()
output_parameters["preprocessor path"] = preprocessor_str
output_parameters["post processor path"] = postprocessor_str
output_parameters["thresholding op"] = threshold_method
output_parameters["use ridge detection"] = str(use_ridge_detection)
output_parameters["high contrast"] = rd_max
output_parameters["low contrast"] = rd_min
output_parameters["line width"] = rd_width
output_parameters["minimum line length"] = rd_length
# Create and ImgPlus copy of the ImagePlus for thresholding with ops...
status.showStatus("Determining threshold level...")
imp_title = imp.getTitle()
slices = imp.getNSlices()
frames = imp.getNFrames()
output_parameters["image title"] = imp_title
imp_calibration = imp.getCalibration()
imp_channel = Duplicator().run(imp, imp.getChannel(), imp.getChannel(), 1, slices, 1, frames)
img = ImageJFunctions.wrap(imp_channel)
# Determine the threshold value if not manual...
binary_img = ops.run("threshold.%s"%threshold_method, img)
binary = ImageJFunctions.wrap(binary_img, 'binary')
binary.setCalibration(imp_calibration)
binary.setDimensions(1, slices, 1)
# Get the total_area
if binary.getNSlices() == 1:
area = binary.getStatistics(Measurements.AREA).area
area_fraction = binary.getStatistics(Measurements.AREA_FRACTION).areaFraction
output_parameters["mitochondrial footprint"] = area * area_fraction / 100.0
else:
mito_footprint = 0.0
for slice in range(binary.getNSlices()):
binary.setSliceWithoutUpdate(slice)
area = binary.getStatistics(Measurements.AREA).area
area_fraction = binary.getStatistics(Measurements.AREA_FRACTION).areaFraction
mito_footprint += area * area_fraction / 100.0
output_parameters["mitochondrial footprint"] = mito_footprint * imp_calibration.pixelDepth
#.........这里部分代码省略.........
示例8: processSlice
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
n_slices = imp.getStackSize()
if 1 == n_slices:
ip = imp.getProcessor().crop()
processSlice(ip, type)
# show result in a new image
ImagePlus("Noisy_" + imp.title, ip).show()
else:
stack1 = imp.getStack()
roi = imp.getRoi()
if None == roi:
width = imp.width
height = imp.height
else:
rect = roi.getBounds()
width = rect.width
height = rect.height
stack2 = ImageStack(width, height)
for i in range(1, n_slices+1):
ip = stack1.getProcessor(i)
# stack processors need the roi to be explicitly set
if roi: ip.setRoi(rect)
ip = ip.crop()
processSlice(ip, type)
stack2.addSlice(stack1.getSliceLabel(i), ip)
# show result in a new image
ImagePlus("Noisy_" + imp.title, stack2).show()
# START PROGRAM:
run(WindowManager.getCurrentImage())
示例9: draw
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
color = "white"
draw(i, j, array, color)
def draw_field(field, selectedX, selectedY):
for j in range(0, 8):
for i in range(0, 8):
draw_one(i, j, field, selectedX, selectedY)
IJ.setTool(Toolbar.HAND)
field = initial_field()
currentX = -1
currentY = -1
draw_field(field, currentX, currentY)
canvas = WindowManager.getCurrentImage().getCanvas()
clicked = 0
while True:
p = canvas.getCursorLoc()
x = int(p.x / w)
y = int(p.y / h)
newClicked = canvas.getModifiers() & 16
if clicked and not newClicked:
if currentX >= 0:
if x != currentX or y != currentY:
oldOffset = currentX + 8 * currentY
field[x + 8 * y] = field[oldOffset]
field[oldOffset] = ""
draw_one(currentX, currentY, field, -1, -1)
draw_one(x, y, field, -1, -1)
示例10: BasicDialog
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
- 2 slices
'''
# should first par be width?
w = imp.getWidth()
h = imp.getHeight()
imagesize = jarray.array([w, h], 'i')
color = imp.getType() == ImagePlus.COLOR_RGB
dl = BasicDialog(imagesize, color, False)
# "quality='1' topology='0' show-view='on' show-topology='off'"
delta = 0
quality = 1
topology = 0
showview = True
showtopology= False
dl.parameters.setQualitySettings(quality)
dl.parameters.setTopologySettings(topology)
dl.parameters.show3dView = showview
dl.parameters.showTopology = showtopology
dl.process()
while (WindowManager.getWindow("Output") is None ):
time.sleep(1)
impEDF = WindowManager.getCurrentImage()
impEDF.show()
imp.close()
imp.flush()
strImg = imgDir + relImg + "/out/bez-50X-1-ij-edf.tif"
print(strImg)
IJ.saveAs("Tiff", strImg)
示例11: str
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
ratio_rec_str = "%.3f" % ratio_rec
gd.addMessage(str(i+1)+"-channel: " + str(mem_recs[i]) + "MB; Ratio: " + ratio_rec_str)
gd.showDialog()
ratioRaw = gd.getNextNumber()
ratio = math.sqrt(ratioRaw)
if (gd.wasOKed()):
filecollection = glob.glob(os.path.join(sourceDir, '*.ome.tif'))
numFiles = len(filecollection)
count = 1
for f in filecollection:
bname1 = os.path.basename(f)
bname2 = os.path.splitext(bname1)[0]
bname3 = os.path.splitext(bname2)[0]
print bname3
params = "open=[" + f + "] color_mode=Default view=Hyperstack stack_order=XYCZT"
IJ.run("Bio-Formats Importer",params)
theImage = WindowManager.getCurrentImage()
params2 = "x=" + str(ratio) + " y=" + str(ratio) + " z=1.0 interpolation=Bilinear average process create title=doggie"
IJ.run(theImage,"Scale...",params2)
theImage.close()
saveImage = WindowManager.getImage("doggie")
savePath = sourceDir+"resized/"+bname3+".tif"
IJ.saveAsTiff(saveImage,sourceDir+"resized/"+bname3+".tif")
saveImage.close()
IJ.showStatus("Tile: " + str(count) + "/" + str(numFiles))
count = count + 1
示例12: print
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
iUnits = "px/micron"
strFile=strPath+strName+strExt
strRpt=strPath+strName+".csv"
strMath="image1=" + strName + " operation=Correlate image2=" + strName + " result=Result do"
# print(strFile)
imp = IJ.openImage(strFile)
imp.setTitle(strName)
imp.show()
IJ.run("32-bit");
IJ.run("FD Math...", strMath)
IJ.selectWindow(strName)
IJ.run("Close")
IJ.selectWindow("Result")
imp=WM.getCurrentImage()
ip = imp.getProcessor()
options = IM.MEAN | IM.MEDIAN | IM.MIN_MAX | IM.STD_DEV
stats = IS.getStatistics(ip, options, imp.getCalibration())
if bVerbose:
print " Min:", IJ.d2s(stats.min,2)
print " Man:", IJ.d2s(stats.max,2)
print " Mean:", IJ.d2s(stats.mean,2)
print "Std Dev:" , IJ.d2s(stats.stdDev,2)
delta = stats.max - stats.min
pixels = ip.getPixels()
newPixels = map(lambda x: (x - stats.min)/delta, pixels)
ipSub = FloatProcessor(ip.width, ip.height, newPixels, None)
impSub = ImagePlus("Sub", ipSub)
impSub.show()
示例13:
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
import os
from ij import IJ
from ij import WindowManager
bCleanup = True
gitDir = os.environ['GIT_HOME']
relImg = "/OSImageAnalysis/images"
strImg = gitDir + relImg + "/George.tif"
strTxt = gitDir + relImg + "/George.txt"
# 1. Open an image
impRaw = IJ.openImage(strImg)
impRaw.show()
IJ.run("Find Edges")
IJ.run("Skeletonize (2D/3D)")
IJ.run("Find Connected Regions", "allow_diagonal display_one_image display_results regions_for_values_over=100 minimum_number_of_points=1 stop_after=-1")
strSaveCoord = "background=0 save=%s" % strTxt
IJ.run("Save XY Coordinates...", strSaveCoord)
# Get the final map
impCon = WindowManager.getCurrentImage()
impRaw.changes=False
impRaw.close()
resWin = WindowManager.getWindow("Results")
resWin.dispose()
logWin = WindowManager.getWindow("Log")
logWin.dispose()
if bCleanup:
impCon.changes=False
impCon.close()
示例14: MakeStack
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def MakeStack():
IJ.run("Bio-Formats","group_files use_virtual_stack")
imp = WindowManager.getCurrentImage()
return imp
示例15: analyze
# 需要导入模块: from ij import WindowManager [as 别名]
# 或者: from ij.WindowManager import getCurrentImage [as 别名]
def analyze(tempFile):
# Get currently selected image
#imp = WindowManager.getCurrentImage()
imp = IJ.openImage(tempFile)
imp.show()
dims = imp.getDimensions();
imp.setDimensions(dims[2], dims[4], dims[3]);
#----------------------------
# Create the model object now
#----------------------------
# Some of the parameters we configure below need to have
# a reference to the model at creation. So we create an
# empty model now.
model = Model()
# Send all messages to ImageJ log window.
model.setLogger(Logger.IJ_LOGGER)
#------------------------
# Prepare settings object
#------------------------
settings = Settings()
settings.setFrom(imp)
print(settings.imageFileName)
# Configure detector - We use the Strings for the keys
settings.detectorFactory = LogDetectorFactory()
settings.detectorSettings = {
'DO_SUBPIXEL_LOCALIZATION' : False,
'RADIUS' : 20.,
'TARGET_CHANNEL' : 1,
'THRESHOLD' : 0.95,
'DO_MEDIAN_FILTERING' : True,
}
# Configure spot filters - Classical filter on quality
#filter1 = FeatureFilter('QUALITY', 0.5, True)
#settings.addSpotFilter(filter1)
# Configure tracker - We want to allow merges and fusions
settings.trackerFactory = SimpleSparseLAPTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap() #probably good enough
#settings.trackerSettings['ALLOW_TRACK_SPLITTING'] = False
#settings.trackerSettings['ALLOW_TRACK_MERGING'] = False
settings.trackerSettings['LINKING_MAX_DISTANCE'] = 35.0
settings.trackerSettings['GAP_CLOSING_MAX_DISTANCE']= 60.0
settings.trackerSettings['MAX_FRAME_GAP']= 2
# Configure track analyzers - Later on we want to filter out tracks
# based on their displacement, so we need to state that we want
# track displacement to be calculated. By default, out of the GUI,
# not features are calculated.
# The displacement feature is provided by the TrackDurationAnalyzer.
settings.addTrackAnalyzer(TrackDurationAnalyzer())
#-------------------
# Instantiate plugin
#-------------------
trackmate = TrackMate(model, settings)
ok = trackmate.process()
if not ok:
sys.exit(str(trackmate.getErrorMessage()))
#----------------
# Display results
#----------------
selectionModel = SelectionModel(model)
displayer = HyperStackDisplayer(model, selectionModel, imp)
displayer.render()
displayer.refresh()
# Echo results with the logger we set at start:
model.getLogger().log(str(model))
print(str(settings))
filename = os.path.splitext(settings.imageFileName)
pathname = settings.imageFolder + "" + filename[0] + "tracks.xml"
guicontroller = TrackMateGUIController(trackmate)
newFile = File(pathname)
ExportTracksToXML(guicontroller).export(model, settings, newFile)
actionObject = CaptureOverlayAction()
actionObject.execute(trackmate)
imp = WindowManager.getCurrentImage()
fileSaver = FileSaver(imp)
fileSaver.saveAsTiffStack(settings.imageFolder + "" + filename[0] + "overlay.tif")
WindowManager.closeAllWindows()
guicontroller.quit()
selectionModel.clearSelection();
model.clearTracks(1)