Пример #1
0
 def test_fromTif(self):
     imagepath = os.path.join(self.testresourcesdir, "singlelayer_tif", "dot1_lzw.tif")
     tifimage = ImagesLoader(self.sc).fromTif(imagepath, self.sc)
     firsttifimage = tifimage.first()
     assert_equals(0, firsttifimage[0], "Key error; expected first image key to be 0, was "+str(firsttifimage[0]))
     expectedshape = (70, 75, 4)  # 4 channel tif; RGBalpha
     assert_true(isinstance(firsttifimage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firsttifimage[1])))
     assert_equals(expectedshape, firsttifimage[1].shape)
     assert_equals(248, firsttifimage[1][:, :, 0].flatten().max())
     assert_equals(8, firsttifimage[1][:, :, 0].flatten().min())
Пример #2
0
 def test_fromPng(self):
     imagepath = os.path.join(self.testresourcesdir, "singlelayer_png", "dot1.png")
     pngimage = ImagesLoader(self.sc).fromPng(imagepath, self.sc)
     firstpngimage = pngimage.first()
     assert_equals(0, firstpngimage[0], "Key error; expected first image key to be 0, was "+str(firstpngimage[0]))
     expectedshape = (70, 75, 4)  # 4 channel png; RGBalpha
     assert_true(isinstance(firstpngimage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firstpngimage[1])))
     assert_equals(expectedshape, firstpngimage[1].shape)
     assert_almost_equal(0.97, firstpngimage[1][:, :, 0].flatten().max(), places=2)
     assert_almost_equal(0.03, firstpngimage[1][:, :, 0].flatten().min(), places=2)
Пример #3
0
 def test_fromTif(self):
     imagePath = os.path.join(self.testResourcesDir, "singlelayer_tif", "dot1_grey_lzw.tif")
     tiffImage = ImagesLoader(self.sc).fromTif(imagePath)
     firstTiffImage = tiffImage.first()
     assert_equals(0, firstTiffImage[0], "Key error; expected first image key to be 0, was "+str(firstTiffImage[0]))
     expectedShape = (70, 75)
     assert_true(isinstance(firstTiffImage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firstTiffImage[1])))
     assert_equals(expectedShape, firstTiffImage[1].shape)
     assert_equals(expectedShape, tiffImage.dims.count)
     assert_equals(239, firstTiffImage[1].ravel().max())
     assert_equals(1, firstTiffImage[1].ravel().min())
Пример #4
0
 def test_fromPng(self):
     imagePath = os.path.join(self.testResourcesDir, "singlelayer_png", "dot1_grey.png")
     pngImage = ImagesLoader(self.sc).fromPng(imagePath)
     firstPngImage = pngImage.first()
     assert_equals(0, firstPngImage[0], "Key error; expected first image key to be 0, was "+str(firstPngImage[0]))
     expectedShape = (70, 75)
     assert_true(isinstance(firstPngImage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firstPngImage[1])))
     assert_equals(expectedShape, firstPngImage[1].shape)
     assert_equals(expectedShape, pngImage.dims.count)
     assert_almost_equal(0.937, firstPngImage[1].ravel().max(), places=2)  # integer val 239
     assert_almost_equal(0.00392, firstPngImage[1].ravel().min(), places=2)  # integer val 1
Пример #5
0
 def test_fromTif(self):
     imagePath = os.path.join(self.testResourcesDir, "singlelayer_tif", "dot1_grey_lzw.tif")
     tiffImage = ImagesLoader(self.sc).fromTif(imagePath)
     firstTiffImage = tiffImage.first()
     assert_equals(0, firstTiffImage[0], "Key error; expected first image key to be 0, was "+str(firstTiffImage[0]))
     expectedShape = (70, 75)
     assert_true(isinstance(firstTiffImage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firstTiffImage[1])))
     assert_equals(expectedShape, firstTiffImage[1].shape)
     assert_equals(expectedShape, tiffImage.dims.count)
     assert_equals(239, firstTiffImage[1].ravel().max())
     assert_equals(1, firstTiffImage[1].ravel().min())
Пример #6
0
 def test_fromPng(self):
     imagePath = os.path.join(self.testResourcesDir, "singlelayer_png", "dot1_grey.png")
     pngImage = ImagesLoader(self.sc).fromPng(imagePath)
     firstPngImage = pngImage.first()
     assert_equals(0, firstPngImage[0], "Key error; expected first image key to be 0, was "+str(firstPngImage[0]))
     expectedShape = (70, 75)
     assert_true(isinstance(firstPngImage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firstPngImage[1])))
     assert_equals(expectedShape, firstPngImage[1].shape)
     assert_equals(expectedShape, pngImage.dims.count)
     assert_almost_equal(0.937, firstPngImage[1].ravel().max(), places=2)  # integer val 239
     assert_almost_equal(0.00392, firstPngImage[1].ravel().min(), places=2)  # integer val 1
Пример #7
0
 def test_fromTif(self):
     imagepath = os.path.join(self.testresourcesdir, "singlelayer_tif", "dot1_lzw.tif")
     tifimage = ImagesLoader(self.sc).fromTif(imagepath, self.sc)
     firsttifimage = tifimage.first()
     assert_equals(0, firsttifimage[0], "Key error; expected first image key to be 0, was "+str(firsttifimage[0]))
     expectedshape = (70, 75, 4)  # 4 channel tif; RGBalpha
     assert_true(isinstance(firsttifimage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firsttifimage[1])))
     assert_equals(expectedshape, firsttifimage[1].shape)
     assert_equals(expectedshape, tifimage.dims.count)
     assert_equals(248, firsttifimage[1][:, :, 0].flatten().max())
     assert_equals(8, firsttifimage[1][:, :, 0].flatten().min())
Пример #8
0
 def test_fromPng(self):
     imagepath = os.path.join(self.testresourcesdir, "singlelayer_png", "dot1.png")
     pngimage = ImagesLoader(self.sc).fromPng(imagepath, self.sc)
     firstpngimage = pngimage.first()
     assert_equals(0, firstpngimage[0], "Key error; expected first image key to be 0, was "+str(firstpngimage[0]))
     expectedshape = (70, 75, 4)  # 4 channel png; RGBalpha
     assert_true(isinstance(firstpngimage[1], ndarray),
                 "Value type error; expected first image value to be numpy ndarray, was " +
                 str(type(firstpngimage[1])))
     assert_equals(expectedshape, firstpngimage[1].shape)
     assert_equals(expectedshape, pngimage.dims.count)
     assert_almost_equal(0.97, firstpngimage[1][:, :, 0].flatten().max(), places=2)
     assert_almost_equal(0.03, firstpngimage[1][:, :, 0].flatten().min(), places=2)
Пример #9
0
 def roundTrip(images, dtype):
     outdir = os.path.join(self.outputdir, "binary-images-" + dtype)
     images.astype(dtype).saveAsBinaryImages(outdir)
     newimages = ImagesLoader(self.sc).fromStack(outdir, ext="bin")
     array_equal(images.first()[1], newimages.first()[1])
Пример #10
0
 def roundTrip(images, dtype):
     outdir = os.path.join(self.outputdir, "binary-images-" + dtype)
     images.astype(dtype).saveAsBinaryImages(outdir)
     newimages = ImagesLoader(self.sc).fromStack(outdir, ext='bin')
     array_equal(images.first()[1], newimages.first()[1])