本文整理汇总了Python中ij.ImagePlus.show方法的典型用法代码示例。如果您正苦于以下问题:Python ImagePlus.show方法的具体用法?Python ImagePlus.show怎么用?Python ImagePlus.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.ImagePlus
的用法示例。
在下文中一共展示了ImagePlus.show方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SaveCoverFromFs
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def SaveCoverFromFs(tiles, newwidth, newheight, cols, rows):
tilewidth = int(newwidth/cols)
tileheight = int(newheight/rows)
newwidth = int(newwidth/tilewidth) * tilewidth
newheight = int(newheight/tileheight) * tileheight
hiresoutip = ColorProcessor(newwidth, newheight)
hiresout = ImagePlus("hi res output", hiresoutip)
hiresout.show()
x = 0
y = -1
plane = []
# scale the images
for i in sorted(tiles.iterkeys()):
if y < rows-1:
y += 1
else:
y = 0
x += 1
imp = IJ.openImage(str(tiles[i]))
scale = Scale(imp.getProcessor())
ipscaled = ScaleImageToSize(scale, tilewidth, tileheight)
hiresoutip.copyBits(ipscaled, x*tilewidth, y*tileheight, 0)
hiresout.draw()
示例2: extract_stack_under_arealist
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def extract_stack_under_arealist():
# Check that a Display is open
display = Display.getFront()
if display is None:
IJ.log("Open a TrakEM2 Display first!")
return
# Check that an AreaList is selected and active:
ali = display.getActive()
if ali is None or not isinstance(ali, AreaList):
IJ.log("Please select an AreaList first!")
return
# Get the range of layers to which ali paints:
ls = display.getLayerSet()
ifirst = ls.indexOf(ali.getFirstLayer())
ilast = ls.indexOf(ali.getLastLayer())
layers = display.getLayerSet().getLayers().subList(ifirst, ilast +1)
# Create a stack with the dimensions of ali
bounds = ali.getBoundingBox()
stack = ImageStack(bounds.width, bounds.height)
# Using 16-bit. To change to 8-bit, use GRAY8 and ByteProcessor in the two lines below:
type = ImagePlus.GRAY16
ref_ip = ShortProcessor(bounds.width, bounds.height)
for layer in layers:
area = ali.getArea(layer)
z = layer.getZ()
ip = ref_ip.createProcessor(bounds.width, bounds.height)
if area is None:
stack.addSlice(str(z), bp)
continue
# Create a ROI from the area of ali at layer:
aff = ali.getAffineTransformCopy()
aff.translate(-bounds.x, -bounds.y)
roi = ShapeRoi(area.createTransformedArea(aff))
# Create a cropped snapshot of the images at layer under ali:
flat = Patch.makeFlatImage(type, layer, bounds, 1.0, layer.getDisplayables(Patch), Color.black)
b = roi.getBounds()
flat.setRoi(roi)
ip.insert(flat.crop(), b.x, b.y)
# Clear the outside of ROI (ShapeRoi is a non-rectangular ROI type)
bimp = ImagePlus("", ip)
bimp.setRoi(roi)
ip.setValue(0)
ip.setBackgroundValue(0)
IJ.run(bimp, "Clear Outside", "")
# Accumulate slices
stack.addSlice(str(z), ip)
imp = ImagePlus("AreaList stack", stack)
imp.setCalibration(ls.getCalibrationCopy())
imp.show()
示例3: draw_bounding_boxes
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def draw_bounding_boxes(objects,title,templateImage):
drawnIp = ByteProcessor(templateImage.getWidth(),templateImage.getHeight())
drawnImage = ImagePlus(title,drawnIp)
drawnImage.show()
IJ.selectWindow(title)
for j in range(len(objects)):
IJ.makeRectangle(objects[j][42],objects[j][43],objects[j][45]-objects[j][42],objects[j][46]-objects[j][43])
IJ.run("Draw","stack")
drawnImage.hide()
return(drawnImage)
示例4: run_script
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def run_script():
# We can use import inside of code blocks to limit the scope.
import math
from ij import IJ, ImagePlus
from ij.process import FloatProcessor
blank = IJ.createImage("Blank", "32-bit black", img_size, img_size, 1)
# This create a list of lists. Each inner list represents a line.
# pixel_matrix[0] is the first line where y=0.
pixel_matrix = split_list(blank.getProcessor().getPixels(), wanted_parts=img_size)
# This swaps x and y coordinates.
# http://stackoverflow.com/questions/8421337/rotating-a-two-dimensional-array-in-python
# As zip() creates tuples, we have to convert each one by using list().
pixel_matrix = [list(x) for x in zip(*pixel_matrix)]
for y in range(img_size):
for x in range(img_size):
# This function oszillates between 0 and 1.
# The distance of 2 maxima in a row/column is given by spacing.
val = (0.5 * (math.cos(2*math.pi/spacing*x) + math.sin(2*math.pi/spacing*y)))**2
# When assigning, we multiply the value by the amplitude.
pixel_matrix[x][y] = amplitude * val
# The constructor of FloatProcessor works fine with a 2D Python list.
crystal = ImagePlus("Crystal", FloatProcessor(pixel_matrix))
# Crop without selection is used to duplicate an image.
crystal_with_noise = crystal.crop()
crystal_with_noise.setTitle("Crystal with noise")
IJ.run(crystal_with_noise, "Add Specified Noise...", "standard=%d" % int(amplitude/math.sqrt(2)))
# As this is a demo, we don't want to be ask to save an image on closing it.
# In Python True and False start with capital letters.
crystal_with_noise.changes = False
crystal.show()
crystal_with_noise.show()
filtered = fft_filter(crystal_with_noise)
# We create a lambda function to be used as a parameter of img_calc().
subtract = lambda values: values[0] - values[1]
""" This is a short form for:
def subtract(values):
return values[0] - values[1]
"""
# The first time we call img_calc with 2 images.
difference = img_calc(subtract, crystal, filtered, title="Difference of 2")
difference.show()
# The first time we call img_calc with 3 images.
minimum = img_calc(min, crystal, filtered, crystal_with_noise, title="Minimum of 3")
minimum.show()
for imp in (crystal, crystal_with_noise, filtered, difference, minimum):
IJ.run(imp, "Measure", "")
示例5: SaveCoverFromZip
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def SaveCoverFromZip(tileIndex, newwidth, newheight, cols, rows, originalspath):
baseDir = re.sub(r'\/originals.zip', "", originalspath)
#print baseDir
zf = zipfile.ZipFile(originalspath, mode='r')
tilewidth = int(newwidth/cols)
tileheight = int(newheight/rows)
newwidth = int(newwidth/tilewidth) * tilewidth
newheight = int(newheight/tileheight) * tileheight
hiresoutip = ColorProcessor(newwidth, newheight)
hiresout = ImagePlus("hi res output", hiresoutip)
hiresout.show()
x = 0
y = -1
plane = []
# scale the images
for i in sorted(tileIndex.iterkeys()):
if y < rows-1:
y += 1
else:
y = 0
x += 1
#bi = bir.openImage(tileIndex[i]);
#ip = ColorProcessor(bi)
image = zf.read(str(tileIndex[i]) + ".jpeg")
#IJ.log("Placing image :" + str(tileIndex[i]) + ".jpeg")
my_file = open(baseDir + 'temporary.jpeg','w')
my_file.write(image)
my_file.close()
imp = IJ.openImage(baseDir + "/temporary.jpeg")
ip = imp.getProcessor()
scale = Scale(ip)
ipscaled = ScaleImageToSize(scale, tilewidth, tileheight)
hiresoutip.copyBits(ipscaled, x*tilewidth, y*tileheight, 0)
hiresout.draw()
示例6: run
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def run():
d = str(input_dir)
files = get_swc_files(d, filenameFilter);
if not files or len(files) == 0:
uiservice.showDialog("No files matched the specified criteria", "Error")
IT = ImportTracings()
IT.applyScalingFactor(scale_factor, scale_factor, scale_factor)
# IT.applyCalibration(1, 1, 1, "um")
proj_rendering = "Projected" in display_choice
for (counter, f) in enumerate(files):
basename = os.path.basename(f)
status.showStatus('Loading file %s: %s...' % (counter + 1, basename))
try:
IT.autoLoadSWC(f, proj_rendering)
if proj_rendering:
imp = ImagePlus("file: " + basename, IT.getSkeletonizedProjection())
imp.show()
except Exception, msg: # Jython 3: except Exception as msg:
log.error("An error occurred when loading %s. Details:\n%s" % (f, msg))
break
示例7: Extract_Red_Channel
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def Extract_Red_Channel(color):
imp = IJ.getImage()
stack = imp.getImageStack()
print "number of slices:", imp.getNSlices()
# A list of red slices
reds = []
# Iterate each slice in the stack
for i in xrange(1, imp.getNSlices()+1):
# Get the ColorProcessor slice at index i
cp = stack.getProcessor(i)
# Get its green channel as a FloatProcessor
fp = cp.toFloat(0, None)
# ... and store it in a list
reds.append(fp)
# Create a new stack with only the green channel
stack2 = ImageStack(imp.width, imp.height)
for fp in reds:
stack2.addSlice(None, fp)
# Create a new image with the stack of green channel slices
imp2 = ImagePlus("Red channel", stack2)
# Set a green look-up table:
IJ.run(imp2, "Red", "")
imp2.show()
示例8: range
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
lRound = rt.getColumn(rt.getColumnIndex("Round"))
lSolid = rt.getColumn(rt.getColumnIndex("Solidity"))
for j in range(len(lArea)):
imgOut.append(iNum)
parOut.append(j+1)
ecd = 2.0*sqrt(lArea[j]/3.1415926)
ecdOut.append(ecd)
con = 1.0-(lMode[j]/iZero)
conOut.append(con)
cirOut.append(lCirc[j])
arOut.append(lAspRat[j])
rndOut.append(lRound[j])
solOut.append(lSolid[j])
orig.show()
outPth = sRptImgPath + strName + ".png"
# burn a scale bar and save the image
IJ.run(orig, "RGB Color", "")
IJ.run(orig, "Add Scale Bar", strBar)
IJ.saveAs(orig, "PNG", outPth)
orig.changes = False
orig.close()
print("%d particles detected in image %s" % (nMeas, strNum))
# prepare the output file
f=open(sRptCsvPath, 'w')
strLine = 'img, part, ecd.nm, contrast, circ, a.r, round, solidity\n'
f.write(strLine)
for k in range(len(ecdOut)):
示例9: range
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
in_f = 0
avt = 1
for jj in range(imp.height):
for ii in range(imp.width):
if pix_new_green[k] != 0:
in_f = 1
if in_f == 1 :
avt = 1
if in_f == 0 & avt == 1:
print jj
avt = 0
in_f = 0
cp = slice.duplicate()
cp.setPixels(0, new_red) # at channel 0, the red
new_stack.addSlice(stack.getSliceLabel(i), cp)
cp.setPixels(1, new_green) # at channel 0, the red
new_stack.addSlice(stack.getSliceLabel(i), cp)
cp.setPixels(2, new_blue) # at channel 0, the red
new_stack.addSlice(stack.getSliceLabel(i), cp)
new_imp = ImagePlus("g-r subtracted", new_stack)
new_imp.show()
示例10: Straightener
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
# Straighten: like the command in Edit > Selection menu,
# this snippet creates a new image by taking some pixels along a
# line ROI. It is typically used to make a straight image from
# a bent selection.
from ij import IJ, ImagePlus
width = 20 # how many pixels should we fetch from around the ROI?
# Get current ImagePlus
image = IJ.getImage()
if image is not None:
roi = image.getRoi()
if roi is not None and roi.isLine(): # we can only do it for line ROIs
# Instantiate plugin
straightener = Straightener()
# Are we dealing with a stack?
stack_size = image.getStackSize()
if stack_size > 1:
new_stack = straightener.straightenStack(image, roi, width)
new_image = ImagePlus( image.getTitle()+"-straightened", new_stack)
else:
new_ip = straightener.straighten(image, roi, width)
new_image = ImagePlus( image.getTitle()+"-straightened", new_ip)
# Display result
new_image.show()
示例11: xrange
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
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()
示例12: processOneImage
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def processOneImage(inputDir):
tmp = glob.glob(os.path.join(inputDir, "fibrone*"))
fibronectin = tmp[0]
tmp = glob.glob(os.path.join(inputDir, "nucleus*"))
nucleus = tmp[0]
tmp = glob.glob(os.path.join(inputDir, "actin*"))
actin = tmp[0]
# read sample name
head,tail = os.path.split(inputDir)
sample = tail.replace(".tif_Files","")
# original images
imp_fn_orig = IJ.openImage(fibronectin)
imp_nuc_orig = IJ.openImage(nucleus)
# work copies
imp_fn = imp_fn_orig.duplicate()
imp_nuc = imp_nuc_orig.duplicate()
IJ.run(imp_fn,"Set Scale...", "distance=1 known=1 pixel=1 unit=pixels")
IJ.run(imp_fn,"Gaussian Blur...","sigma=5")
IJ.run(imp_fn,"Make Binary","")
IJ.run(imp_nuc,"Set Scale...", "distance=1 known=1 pixel=1 unit=pixels")
IJ.run(imp_nuc,"Gaussian Blur...","sigma=5")
IJ.run(imp_nuc,"Make Binary","")
# get moments of the fibronectin image
moments_file = os.path.join(OUTPUT, sample + " moments.txt")
printMoments(fibronectin, moments_file)
moments = readMoments(moments_file)
print moments.m00
sys.exit()
# centroid of fibronectin anchor
centers = getParticleCenters(imp_fn)
cxfn = int(round(centers[0][0]))
cyfn = int(round(centers[1][0]))
fn_centroid_roi = PointRoi(cxfn,cyfn)
fn_centroid_roi.setDefaultMarkerSize("Large")
fn_centroid_roi.setStrokeColor(Color.CYAN)
# center of mass of nucleus
centers = getParticleCenters(imp_nuc)
cxnuc = int(round(centers[2][0]))
cynuc = int(round(centers[3][0]))
nuc_com_roi = PointRoi(cxnuc,cynuc)
nuc_com_roi.setDefaultMarkerSize("Large")
# skeletonize fibronectin anchor to find its orientation
IJ.run(imp_fn,"Skeletonize","")
skel = AnalyzeSkeleton_()
skel.setup("",imp_fn)
skelResult = skel.run(skel.NONE, False, True, None, True, True)
graph = skelResult.getGraph()
print len(graph)
print skelResult.getNumOfTrees()
# find the longest graph
graph = sorted(graph, key=lambda g: getGraphLength(g), reverse=True)
graph = graph[0]
edges = graph.getEdges()
# find longest edge, the main axis of the anchor
edges = sorted(edges, key=lambda edge: edge.getLength(), reverse=True)
#for e in edges:
# print e.getLength()
v1long = edges[0].getV1()
v2long = edges[0].getV2()
x1 = v1long.getPoints()[0].x
y1 = v1long.getPoints()[0].y
x2 = v2long.getPoints()[0].x
y2 = v2long.getPoints()[0].y
anchor_roi = PointRoi(x1,y1)
anchor_roi = anchor_roi.addPoint(x2,y2)
# find top and bottom vertices of the graph
vertices = graph.getVertices()
vertices = sorted(vertices, key=lambda vertex: vertex.getPoints()[0].y)
v1short = vertices[len(vertices)-1]
v2short = vertices[0]
x3 = v1short.getPoints()[0].x
y3 = v1short.getPoints()[0].y
x4 = v2short.getPoints()[0].x
y4 = v2short.getPoints()[0].y
anchor_roi = anchor_roi.addPoint(x3,y3)
anchor_roi = anchor_roi.addPoint(x4,y4)
# calculate angles
a1 = math.atan(abs(float(y2-y1)/float(x2-x1))) / math.pi * 360
a2 = math.atan(abs(float(x4-x3)/float(y4-y3))) / math.pi * 360
amean = float((a1+a2)/2)
dx = cxfn-cxnuc
print sample,cxfn,cyfn,cxnuc,cynuc,dx,math.cos(amean)*dx,x1,y1,x2,y2,x3,y3,x4,y4,a1,a2
# create composite
comp = ImagePlus("composite",imp_nuc_orig.getProcessor().convertToColorProcessor())
comp.getProcessor().setChannel(2,imp_fn_orig.getProcessor())
comp.getProcessor().setChannel(3,imp_fn.getProcessor())
comp.show()
comp.getProcessor().drawRoi(fn_centroid_roi)
comp.getProcessor().drawRoi(nuc_com_roi)
comp.getProcessor().drawRoi(anchor_roi)
comp.repaintWindow()
#.........这里部分代码省略.........
示例13: print
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
impG = WindowManager.getImage(imgNamG)
impG.show()
# create a gray image fo redirect...
impGbare = impG.duplicate()
impGbare.setTitle("green_channel")
impGbare.show()
impG.setRoi(OvalRoi(22,12,334,337))
impG.show()
w = impG.getWidth()
h = impG.getHeight()
print(w, h)
sp = ByteProcessor(w,h)
blank = ImagePlus("blank", sp)
pix = blank.getProcessor().getPixels()
for i in range(len(pix)):
pix[i] = -1
blank.show()
IJ.selectWindow("original (green)");
IJ.run("Copy")
IJ.selectWindow("blank")
IJ.run("Paste")
blank.show()
示例14: makeMask
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def makeMask(self):
"""
This function makes the mask. The steps are (1) Minimum Filter - makes a darker boundary around beads (2) Autothresholding using the Huang algorithm - has some fuzzy logic and seems to work (3) Analyze particles with a size between 500-50000 and
circularity between 0.4 to 1.0; The mask generated is sometimes black on beads and white around. Then I need to invert the LUTs
"""
ipOriginal = self.stack.getProcessor(self.DIC_index)
ip = ipOriginal.duplicate()
imgUpdate = ImagePlus("New",ip)
imgUpdate.setProcessor("Mask",ip)
img0 = ImagePlus("Before",ipOriginal)
img0.show()
# Minimum filter
RankFilters().rank(ip,2,RankFilters.MIN)
img1 = ImagePlus("Filter",ip)
# Autothreshold - Huang algorithm
hist = ip.getHistogram()
lowTH = Auto_Threshold.Huang(hist)
ip.setThreshold(0,lowTH, ImageProcessor.BLACK_AND_WHITE_LUT)
img3 = ImagePlus("Thresholded",ip)
img3.show()
# Making a binary mask
IJ.run(img3,"Convert to Mask","")
if self._dialog("Invert Mask ??") is True: IJ.run("Invert LUT")
img3.updateAndDraw()
# The true mask after Particle Analysis; Creates a mask image around the particles
IJ.run(img3,"Analyze Particles...", "size=500-50000 circularity=0.40-1.00 show=Masks")
img1.close()
#img3.close()
# Editing the masks (filling holes and dilating it twice)
imgActive = IJ.getImage()
IJ.run(imgActive,"Convert to Mask","")
IJ.run(imgActive,"Fill Holes","")
for i in range(8): IJ.run(imgActive,"Dilate","")
ipActive = imgActive.getProcessor().convertToFloat()
# Saving the mask
maskFname = self.sourceDir + "\\" + self.title + '_mask'
IJ.saveAs(imgActive, "PNG", maskFname)
# Confirming that the image is masked and the histogram is correct
#IJ.run(imgActive, "Histogram", "")
#stats = ipActive.getStatistics()
pixels = ipActive.getPixels()
self.maskPixels = [pix/255 for pix in pixels]
self.areaMask = self.maskPixels.count(1)
# Checking if the image is fine. If not, returns option to skip
ImageCalculator().calculate("zero create", img0, imgActive)
skip = False
if self._dialog("Skip Image ??") is True: skip = True
IJ.run("Close All")
return self.maskPixels, skip
示例15: openImp
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import show [as 别名]
def openImp(self, path):
imp = ImagePlus(path) # open associated tif file
imp.show()
imp.getWindow().setLocationAndSize(280, 120, imp.getWidth()*4, imp.getHeight()*4) # int x, int y, int width, int height
return imp