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())
 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
Example #3
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])