本文整理汇总了Python中jicbioimage.core.image.Image.from_array方法的典型用法代码示例。如果您正苦于以下问题:Python Image.from_array方法的具体用法?Python Image.from_array怎么用?Python Image.from_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jicbioimage.core.image.Image
的用法示例。
在下文中一共展示了Image.from_array方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_array
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_from_array(self):
from jicbioimage.core.image import Image
ar = np.zeros((50,50), dtype=np.uint8)
im = Image.from_array(ar)
self.assertTrue(isinstance(im, Image))
self.assertEqual(len(im.history), 0)
self.assertEqual(im.history.creation, 'Created Image from array')
示例2: to_directory
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def to_directory(self, directory):
if not os.path.isdir(directory):
os.mkdir(directory)
xdim, ydim, zdim = self.shape
num_digits = Image3D._num_digits(zdim-1)
for z in range(zdim):
num = str(z).zfill(num_digits)
fname = "z{}.png".format(num)
fpath = os.path.join(directory, fname)
with open(fpath, "wb") as fh:
im = Image.from_array(unique_color_array(self[:, :, z]))
fh.write(im.png())
示例3: create_mask
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def create_mask(image):
"""Return a mask for the region of interest."""
selem = skimage.morphology.disk(2)
im = equalize_adaptive_clahe(image)
im = threshold_otsu(im)
im = erosion_binary(im, selem)
mask = np.ones(im.shape, dtype=bool)
segmentation = connected_components(im, background=0)
for i in segmentation.identifiers:
region = segmentation.region_by_identifier(i)
if region.area > 5000:
mask[np.where(region.convex_hull)] = False
return Image.from_array(mask)
示例4: test_connected_components_acts_like_a_transform
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_connected_components_acts_like_a_transform(self):
from jicbioimage.segment import connected_components
from jicbioimage.core.image import Image
ar = np.array([[1, 1, 0, 0, 0],
[1, 1, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 2, 2, 2],
[0, 0, 2, 2, 2]], dtype=np.uint8)
im = Image.from_array(ar)
self.assertEqual(len(im.history), 1)
segmentation = connected_components(im)
self.assertEqual(len(segmentation.history), 2)
self.assertEqual(segmentation.history[-1],
"Applied connected_components transform")
示例5: func_as_transformation
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def func_as_transformation(*args, **kwargs):
# Take copies of the args and kwargs for use in the history.
# We will need to remove the image from either the kwargs
# or the args before we use h_args and h_kwargs to create a
# history event.
h_args = list(args[:])
h_kwargs = kwargs.copy()
# Get the input image, so that we can get the history from it.
# Also, strip the image for h_args/h_kwargs.
input_image = kwargs.get("image", None)
if input_image is None:
# The image is the first item of args.
input_image = args[0]
h_args.pop(0)
else:
# The image is in kwargs.
h_kwargs.pop("image")
def array_to_str(value):
if isinstance(value, np.ndarray):
value = repr(value)
return value
h_args = [array_to_str(v) for v in h_args]
for key, value in h_kwargs.items():
h_kwargs[key] = array_to_str(value)
# Get the history from the image.
history = History()
if hasattr(input_image, "history"):
history.extend(input_image.history)
image = func(*args, **kwargs)
if not isinstance(image, _BaseImageWithHistory):
image = Image.from_array(image, log_in_history=False)
# Update the history of the image.
image.history = history
image.history.add_event(func, h_args, h_kwargs)
if AutoWrite.on:
fpath = AutoName.name(func)
image.write(fpath)
return image
示例6: test_can_return_segmented_image
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_can_return_segmented_image(self):
from jicbioimage.core.image import Image
from jicbioimage.segment import SegmentedImage
from jicbioimage.core.transform import transformation
from jicbioimage.core.io import AutoName
AutoName.directory = TMP_DIR
@transformation
def test_segmentation(image):
return image.view(SegmentedImage)
image = Image.from_array(np.zeros((50, 50), dtype=np.uint8))
self.assertTrue(isinstance(image, Image))
segmentation = test_segmentation(image)
self.assertTrue(isinstance(segmentation, SegmentedImage))
self.assertEqual(len(segmentation.history), 2)
self.assertEqual(segmentation.history[-1],
"Applied test_segmentation transform")
示例7: test_from_directory
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_from_directory(self):
from jicbioimage.core.image import Image3D, Image
directory = os.path.join(TMP_DIR)
with open(os.path.join(directory, 'junk.txt'), "w") as fh:
fh.write("junk")
z0 = np.zeros((50,50), dtype=np.uint8)
z1 = np.ones((50, 50), dtype=np.uint8) * 255
for i, z in enumerate([z0, z1]):
im = Image.from_array(z)
fpath = os.path.join(directory, "z{}.png".format(i))
with open(fpath, "wb") as fh:
fh.write(im.png())
im3d = Image3D.from_directory(TMP_DIR)
self.assertTrue(isinstance(im3d, Image3D))
self.assertEqual(im3d.shape, (50, 50, 2))
stack = np.dstack([z0, z1])
self.assertTrue(np.array_equal(im3d, stack))
示例8: test_watershed_with_seeds_acts_like_a_transform
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_watershed_with_seeds_acts_like_a_transform(self):
from jicbioimage.segment import watershed_with_seeds
from jicbioimage.core.image import Image
ar = np.array([[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 9, 0, 0],
[9, 9, 9, 9, 9, 9],
[0, 0, 0, 9, 0, 0],
[0, 0, 0, 9, 0, 0]], dtype=np.uint8)
im = Image.from_array(ar)
self.assertEqual(len(im.history), 1)
sd = np.array([[1, 0, 0, 0, 0, 2],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[3, 0, 0, 0, 0, 4]], dtype=np.uint8)
segmentation = watershed_with_seeds(im, seeds=sd)
self.assertEqual(len(segmentation.history), 2)
self.assertEqual(segmentation.history[-1],
"Applied watershed_with_seeds transform")
示例9: unique_color_image
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def unique_color_image(self):
"""Return segmentation as a unique color image.
:returns: `jicbioimage.core.image.Image`
"""
return Image.from_array(unique_color_array(self))
示例10: pretty_color_image
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def pretty_color_image(self):
"""Return segmentation as a pretty color image.
:returns: `jicbioimage.core.image.Image`
"""
return Image.from_array(pretty_color_array(self))
示例11: average_projection
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def average_projection(stack):
xmax, ymax, zmax = stack.shape
projection = np.sum(stack, axis=2, dtype=np.uint8) // zmax
return Image.from_array(projection)
示例12: test_from_array_no_history
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_from_array_no_history(self):
from jicbioimage.core.image import Image
ar = np.zeros((50,50), dtype=np.uint8)
im = Image.from_array(ar, log_in_history=False)
self.assertEqual(len(im.history), 0)
示例13: test_from_array_with_name
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_array [as 别名]
def test_from_array_with_name(self):
from jicbioimage.core.image import Image
ar = np.zeros((50,50), dtype=np.uint8)
im = Image.from_array(ar, name='Test1')
self.assertEqual(len(im.history), 0)
self.assertEqual(im.history.creation, 'Created Image from array as Test1')