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


Python ThunderContext.loadImagesFromArray方法代码示例

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


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

示例1: TestContextLoading

# 需要导入模块: from thunder import ThunderContext [as 别名]
# 或者: from thunder.ThunderContext import loadImagesFromArray [as 别名]

#.........这里部分代码省略.........
        del pilImg, tmpAry

        rangeSeries = self.tsc.loadImagesAsSeries(self.outputdir, inputFormat="tif-stack")
        assert_equals('float16', rangeSeries._dtype)
        rangeSeriesAry = rangeSeries.pack()
        rangeSeriesAry_xpose = rangeSeries.pack(transpose=True)

        assert_equals((60, 120), rangeSeries.dims.count)  # 2d tif now loaded as 2d image; was 3d with singleton z dim
        assert_equals((2, 60, 120), rangeSeriesAry.shape)
        assert_equals((2, 120, 60), rangeSeriesAry_xpose.shape)
        assert_equals('float16', str(rangeSeriesAry.dtype))
        assert_true(array_equal(rangeAry, rangeSeriesAry[0]))
        assert_true(array_equal(rangeAry2, rangeSeriesAry[1]))
        assert_true(array_equal(rangeAry.T, rangeSeriesAry_xpose[0]))
        assert_true(array_equal(rangeAry2.T, rangeSeriesAry_xpose[1]))

    @unittest.skipIf(not _have_image, "PIL/pillow not installed or not functional")
    def test_loadMultipleMultipointTifsAsSeries(self):
        testResourcesDir = TestContextLoading._findTestResourcesDir()
        imagesPath = os.path.join(testResourcesDir, "multilayer_tif", "dotdotdot_lzw*.tif")

        # load only one file, second is a copy of this one
        testimg_pil = Image.open(os.path.join(testResourcesDir, "multilayer_tif", "dotdotdot_lzw.tif"))
        testimg_arys = [array(testimg_pil)]
        for idx in xrange(1, 3):
            testimg_pil.seek(idx)
            testimg_arys.append(array(testimg_pil))

        rangeSeries = self.tsc.loadImagesAsSeries(imagesPath, inputFormat="tif-stack", nplanes=1)
        assert_equals((70, 75), rangeSeries.dims.count)

        rangeSeriesAry = rangeSeries.pack()
        assert_equals((6, 70, 75), rangeSeriesAry.shape)
        for idx in xrange(6):
            assert_true(array_equal(testimg_arys[idx % 3], rangeSeriesAry[idx]))

    @staticmethod
    def _tempFileWithPaths(f, blob):
        f.write(blob)
        f.flush()
        return f.name

    def test_loadParams(self):

        params = json.dumps({"name": "test1", "value": [1, 2, 3]})

        f = tempfile.NamedTemporaryFile()
        path = TestContextLoading._tempFileWithPaths(f, params)

        d = self.tsc.loadParams(path)

        assert(d.names() == ["test1"])
        assert(array_equal(d.values(), [1, 2, 3]))

        params = json.dumps([{"name": "test0", "value": [1, 2, 3]},
                             {"name": "test1", "value": [4, 5, 6]}])

        f = tempfile.NamedTemporaryFile()
        path = TestContextLoading._tempFileWithPaths(f, params)
        d = self.tsc.loadParams(path)

        assert(d.names() == ["test0", "test1"])
        assert(array_equal(d.values(), [[1, 2, 3], [4, 5, 6]]))
        assert(array_equal(d.values("test0"), [1, 2, 3]))

    def test_loadSeriesFromArray(self):

        target = array([[0, 1], [0, 2]])
        d1 = self.tsc.loadSeriesFromArray([[0, 1], [0, 2]])
        d2 = self.tsc.loadSeriesFromArray(array([[0, 1], [0, 2]]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect(), [(0,), (1,)])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect(), [(0,), (1,)])

        target = array([[0, 1]])
        d1 = self.tsc.loadSeriesFromArray([0, 1])
        d2 = self.tsc.loadSeriesFromArray(array([0, 1]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect(), [(0,)])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect(), [(0,)])

    def test_loadImagesFromArray(self):

        target = array([[[0, 1], [0, 2]]])
        d1 = self.tsc.loadImagesFromArray([[0, 1], [0, 2]])
        d2 = self.tsc.loadImagesFromArray(array([[0, 1], [0, 2]]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect() == [0])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect() == [0])

        target = array([[[0, 1], [0, 2]], [[0, 1], [0, 2]]])
        d1 = self.tsc.loadImagesFromArray([[[0, 1], [0, 2]], [[0, 1], [0, 2]]])
        d2 = self.tsc.loadImagesFromArray(array([[[0, 1], [0, 2]], [[0, 1], [0, 2]]]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect() == [0, 1])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect() == [0, 1])
开发者ID:Peichao,项目名称:thunder,代码行数:104,代码来源:test_context.py


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