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


Python ImagesLoader.meanByRegions方法代码示例

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


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

示例1: test_meanWithSingleRegionIndices3D

# 需要导入模块: from thunder.rdds.fileio.imagesloader import ImagesLoader [as 别名]
# 或者: from thunder.rdds.fileio.imagesloader.ImagesLoader import meanByRegions [as 别名]
 def test_meanWithSingleRegionIndices3D(self):
     ary1 = array([[[3, 5, 3], [6, 8, 6]], [[3, 5, 3], [6, 8, 6]]], dtype="int32")
     ary2 = array([[[13, 15, 13], [16, 18, 16]], [[13, 15, 13], [16, 18, 16]]], dtype="int32")
     images = ImagesLoader(self.sc).fromArrays([ary1, ary2])
     indices = [[(1, 1, 1), (0, 0, 0)]]  # one region with two indices
     regionMeanImages = images.meanByRegions(indices)
     self.__checkAttrPropagation(regionMeanImages, (1, 1))
     collected = regionMeanImages.collect()
     # check values
     assert_equals(5, collected[0][1][0])
     assert_equals(15, collected[1][1][0])
开发者ID:nerduno,项目名称:thunder,代码行数:13,代码来源:test_images.py

示例2: TestImagesMeanByRegions

# 需要导入模块: from thunder.rdds.fileio.imagesloader import ImagesLoader [as 别名]
# 或者: from thunder.rdds.fileio.imagesloader.ImagesLoader import meanByRegions [as 别名]
class TestImagesMeanByRegions(PySparkTestCase):
    def setUp(self):
        super(TestImagesMeanByRegions, self).setUp()
        self.ary1 = array([[3, 5], [6, 8]], dtype="int32")
        self.ary2 = array([[13, 15], [16, 18]], dtype="int32")
        self.images = ImagesLoader(self.sc).fromArrays([self.ary1, self.ary2])

    def __checkAttrPropagation(self, newImages, newDims):
        assert_equals(newDims, newImages._dims.count)
        assert_equals(self.images._nrecords, newImages._nrecords)
        assert_equals(self.images._dtype, newImages._dtype)

    def test_badMaskShapeThrowsValueError(self):
        mask = array([[1]], dtype="int16")
        assert_raises(ValueError, self.images.meanByRegions, mask)

    def test_meanWithFloatMask(self):
        mask = array([[1.0, 0.0], [0.0, 1.0]], dtype="float32")
        regionMeanImages = self.images.meanByRegions(mask)
        self.__checkAttrPropagation(regionMeanImages, (1, 1))
        collected = regionMeanImages.collect()
        assert_equals(2, len(collected))
        assert_equals((1, 1), collected[0][1].shape)
        # check keys
        assert_equals(0, collected[0][0])
        assert_equals(1, collected[1][0])
        # check values
        assert_equals(5, collected[0][1][0])
        assert_equals(15, collected[1][1][0])

    def test_meanWithIntMask(self):
        mask = array([[1, 0], [2, 1]], dtype="uint8")
        regionMeanImages = self.images.meanByRegions(mask)
        self.__checkAttrPropagation(regionMeanImages, (1, 2))
        collected = regionMeanImages.collect()
        assert_equals(2, len(collected))
        assert_equals((1, 2), collected[0][1].shape)
        # check keys
        assert_equals(0, collected[0][0])
        assert_equals(1, collected[1][0])
        # check values
        assert_equals(5, collected[0][1].flat[0])
        assert_equals(6, collected[0][1].flat[1])
        assert_equals(15, collected[1][1].flat[0])
        assert_equals(16, collected[1][1].flat[1])

    def test_meanWithSingleRegionIndices(self):
        indices = [[(1, 1), (0, 0)]]  # one region with two indices
        regionMeanImages = self.images.meanByRegions(indices)
        self.__checkAttrPropagation(regionMeanImages, (1, 1))
        collected = regionMeanImages.collect()
        assert_equals(2, len(collected))
        assert_equals((1, 1), collected[0][1].shape)
        # check keys
        assert_equals(0, collected[0][0])
        assert_equals(1, collected[1][0])
        # check values
        assert_equals(5, collected[0][1][0])
        assert_equals(15, collected[1][1][0])

    def test_meanWithMultipleRegionIndices(self):
        indices = [[(0, 0), (0, 1)], [(0, 1), (1, 0)]]  # two regions with two indices each
        regionMeanImages = self.images.meanByRegions(indices)
        self.__checkAttrPropagation(regionMeanImages, (1, 2))
        collected = regionMeanImages.collect()
        assert_equals(2, len(collected))
        assert_equals((1, 2), collected[0][1].shape)
        # check keys
        assert_equals(0, collected[0][0])
        assert_equals(1, collected[1][0])
        # check values
        assert_equals(4, collected[0][1].flat[0])
        assert_equals(5, collected[0][1].flat[1])
        assert_equals(14, collected[1][1].flat[0])
        assert_equals(15, collected[1][1].flat[1])

    def test_badIndexesThrowErrors(self):
        indices = [[(0, 0), (-1, 0)]]  # index too small (-1)
        assert_raises(ValueError, self.images.meanByRegions, indices)

        indices = [[(0, 0), (2, 0)]]  # index too large (2)
        assert_raises(ValueError, self.images.meanByRegions, indices)

        indices = [[(0, 0), (0,)]]  # too few indices
        assert_raises(ValueError, self.images.meanByRegions, indices)

        indices = [[(0, 0), (0, 1, 0)]]  # too many indices
        assert_raises(ValueError, self.images.meanByRegions, indices)

    def test_meanWithSingleRegionIndices3D(self):
        ary1 = array([[[3, 5, 3], [6, 8, 6]], [[3, 5, 3], [6, 8, 6]]], dtype="int32")
        ary2 = array([[[13, 15, 13], [16, 18, 16]], [[13, 15, 13], [16, 18, 16]]], dtype="int32")
        images = ImagesLoader(self.sc).fromArrays([ary1, ary2])
        indices = [[(1, 1, 1), (0, 0, 0)]]  # one region with two indices
        regionMeanImages = images.meanByRegions(indices)
        self.__checkAttrPropagation(regionMeanImages, (1, 1))
        collected = regionMeanImages.collect()
        # check values
        assert_equals(5, collected[0][1][0])
        assert_equals(15, collected[1][1][0])
开发者ID:nerduno,项目名称:thunder,代码行数:102,代码来源:test_images.py


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