本文整理汇总了Python中ij.ImagePlus.crop方法的典型用法代码示例。如果您正苦于以下问题:Python ImagePlus.crop方法的具体用法?Python ImagePlus.crop怎么用?Python ImagePlus.crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.ImagePlus
的用法示例。
在下文中一共展示了ImagePlus.crop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_script
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import crop [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", "")