def testStyleClamp(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath, style=json.dumps({ 'min': 100, 'max': 200, 'clamp': True })) image, _ = source.getRegion(output={ 'maxWidth': 256, 'maxHeight': 256 }, format=constants.TILE_FORMAT_NUMPY) sourceB = large_image_source_tiff.open(imagePath, style=json.dumps({ 'min': 100, 'max': 200, 'clamp': False })) imageB, _ = sourceB.getRegion(output={ 'maxWidth': 256, 'maxHeight': 256 }, format=constants.TILE_FORMAT_NUMPY) assert numpy.all(image[:, :, 3] == 255) assert numpy.any(imageB[:, :, 3] != 255) assert image[0][0][3] == 255 assert imageB[0][0][3] == 0
def testRegionTiledOutputLetterbox(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) params = {'output': {'maxWidth': 500, 'maxHeight': 500}, 'fill': 'pink', 'encoding': 'TILED'} image, mimeType = source.getRegion(**params) result = large_image_source_tiff.open(str(image)) assert result.sizeX == 500 assert result.sizeY == 500 os.unlink(image)
def testRegionTiledOutputIsTiled(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) # TIFF isn't tiled and has only one layer params = {'output': {'maxWidth': 500, 'maxHeight': 500}, 'encoding': 'TIFF'} image, mimeType = source.getRegion(**params) info = tifftools.read_tiff(io.BytesIO(image)) assert len(info['ifds']) == 1 assert tifftools.Tag.StripOffsets.value in info['ifds'][0]['tags'] assert tifftools.Tag.TileOffsets.value not in info['ifds'][0]['tags'] # TILED is tiled and has multiple layers params = {'output': {'maxWidth': 500, 'maxHeight': 500}, 'encoding': 'TILED'} image, mimeType = source.getRegion(**params) info = tifftools.read_tiff(image) assert len(info['ifds']) == 2 assert tifftools.Tag.StripOffsets.value not in info['ifds'][0]['tags'] assert tifftools.Tag.TileOffsets.value in info['ifds'][0]['tags'] os.unlink(image) # Bigger outputs should have more layers params = {'output': {'maxWidth': 3000, 'maxHeight': 3000}, 'encoding': 'TILED'} image, mimeType = source.getRegion(**params) info = tifftools.read_tiff(image) assert len(info['ifds']) == 5 assert tifftools.Tag.StripOffsets.value not in info['ifds'][0]['tags'] assert tifftools.Tag.TileOffsets.value in info['ifds'][0]['tags'] os.unlink(image)
def testRegionBadParameters(badParams, errMessage): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) with pytest.raises(Exception): params = {'output': {'maxWidth': 400}} nestedUpdate(params, badParams) source.getRegion(**params)
def testOrientations(): testDir = os.path.dirname(os.path.realpath(__file__)) testResults = { 0: {'shape': (100, 66, 1), 'pixels': (0, 0, 0, 255, 0, 255, 0, 255)}, 1: {'shape': (100, 66, 1), 'pixels': (0, 0, 0, 255, 0, 255, 0, 255)}, 2: {'shape': (100, 66, 1), 'pixels': (0, 0, 133, 0, 0, 255, 255, 0)}, 3: {'shape': (100, 66, 1), 'pixels': (255, 0, 143, 0, 255, 0, 0, 0)}, 4: {'shape': (100, 66, 1), 'pixels': (0, 255, 0, 255, 255, 0, 0, 0)}, 5: {'shape': (66, 100, 1), 'pixels': (0, 0, 0, 255, 0, 255, 0, 255)}, 6: {'shape': (66, 100, 1), 'pixels': (0, 255, 0, 255, 141, 0, 0, 0)}, 7: {'shape': (66, 100, 1), 'pixels': (255, 0, 255, 0, 143, 0, 0, 0)}, 8: {'shape': (66, 100, 1), 'pixels': (0, 0, 255, 0, 0, 255, 255, 0)}, } for orient in range(9): imagePath = os.path.join(testDir, 'test_files', 'test_orient%d.tif' % orient) source = large_image_source_tiff.open(imagePath) image, _ = source.getRegion( output={'maxWidth': 100, 'maxHeight': 100}, format=constants.TILE_FORMAT_NUMPY) assert image.shape == testResults[orient]['shape'] assert ( image[11][11][0], image[11][-11][0], image[image.shape[0] // 2][11][0], image[image.shape[0] // 2][-11][0], image[11][image.shape[1] // 2][0], image[-11][image.shape[1] // 2][0], image[-11][11][0], image[-11][-11][0] ) == testResults[orient]['pixels']
def testConvertJp2kCompression(tmpdir): imagePath = datastore.fetch('sample_Easy1.png') outputPath = os.path.join(tmpdir, 'out.tiff') large_image_converter.convert(imagePath, outputPath, compression='jp2k') info = tifftools.read_tiff(outputPath) assert (info['ifds'][0]['tags'][tifftools.Tag.Compression.value]['data'][0] == tifftools.constants.Compression.JP2000.value) source = large_image_source_tiff.open(outputPath) image, _ = source.getRegion(output={ 'maxWidth': 200, 'maxHeight': 200 }, format=constants.TILE_FORMAT_NUMPY) assert (image[12][167] == [215, 135, 172]).all() outputPath2 = os.path.join(tmpdir, 'out2.tiff') large_image_converter.convert(imagePath, outputPath2, compression='jp2k', psnr=50) assert os.path.getsize(outputPath2) < os.path.getsize(outputPath) outputPath3 = os.path.join(tmpdir, 'out3.tiff') large_image_converter.convert(imagePath, outputPath3, compression='jp2k', cr=100) assert os.path.getsize(outputPath3) < os.path.getsize(outputPath) assert os.path.getsize(outputPath3) != os.path.getsize(outputPath2)
def testSingleTileIteratorResample(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) tile = source.getSingleTile() assert tile['mm_x'] == 0.00025 assert tile['width'] == 256 tile = source.getSingleTile(tile_size={ 'width': 255, 'height': 255 }, scale={'mm_x': 0.5e-3}) assert tile['mm_x'] == 0.0005 assert tile['width'] == 255 tile = source.getSingleTile(tile_size={ 'width': 255, 'height': 255 }, scale={'mm_x': 0.6e-3}, resample=False) assert tile['mm_x'] == 0.0005 assert tile['width'] == 255 assert tile['magnification'] == 20.0 assert 'tile_mm_x' not in tile assert 'tile_magnification' not in tile tile = source.getSingleTile(tile_size={ 'width': 255, 'height': 255 }, scale={'mm_x': 0.6e-3}, resample=True) assert tile['mm_x'] == pytest.approx(0.0006, 1e-3) assert tile['magnification'] == pytest.approx(16.667, 1e-3) assert tile['width'] == 255 assert tile['tile_mm_x'] == 0.0005 assert tile['tile_magnification'] == 20.0
def testHistogram(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) hist = source.histogram(bins=8, output={'maxWidth': 1024}, resample=False) assert len(hist['histogram']) == 3 assert hist['histogram'][0]['range'] == (0, 256) assert list(hist['histogram'][0]['hist']) == [ 182, 276, 639, 1426, 2123, 2580, 145758, 547432 ] assert list(hist['histogram'][0]['bin_edges']) == [ 0, 32, 64, 96, 128, 160, 192, 224, 256 ] assert hist['histogram'][0]['samples'] == 700416 hist = source.histogram(bins=256, output={'maxWidth': 1024}, resample=False, density=True) assert len(hist['histogram']) == 3 assert hist['histogram'][0]['range'] == (0, 256) assert len(list(hist['histogram'][0]['hist'])) == 256 assert hist['histogram'][0]['hist'][128] == pytest.approx(5.43e-5, 0.01) assert hist['histogram'][0]['samples'] == 700416 hist = source.histogram(bins=256, output={'maxWidth': 2048}, density=True, resample=False) assert hist['histogram'][0]['samples'] == 2801664 assert hist['histogram'][0]['hist'][128] == pytest.approx(6.39e-5, 0.01)
def testConvertFromLargeImage(tmpdir): imagePath = datastore.fetch('sample_image.jp2') outputPath = os.path.join(tmpdir, 'out.tiff') large_image_converter.convert(imagePath, outputPath) source = large_image_source_tiff.open(outputPath) metadata = source.getMetadata() assert metadata['levels'] == 6
def testPixel(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) # Test bad parameters badParams = [ ({ 'left': 'invalid' }, 'TypeError'), ({ 'top': 'invalid' }, 'TypeError'), ({ 'units': 'invalid' }, 'Invalid units'), ] for entry in badParams: with pytest.raises(Exception): source.getPixel(region=entry[0]) # Test a good query pixel = source.getPixel(region={'left': 48000, 'top': 3000}) assert pixel == {'r': 237, 'g': 248, 'b': 242} # If it is outside of the image, we get an empty result pixel = source.getPixel(region={'left': 148000, 'top': 3000}) assert pixel == {}
def testTileIterator(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) # Ask for JPEGS tileCount = 0 for tile in source.tileIterator(scale={'magnification': 2.5}, format=constants.TILE_FORMAT_IMAGE, encoding='JPEG'): tileCount += 1 assert tile['tile'][:len(utilities.JPEGHeader)] == utilities.JPEGHeader assert tileCount == 45 # Ask for PNGs tileCount = 0 for tile in source.tileIterator(scale={'magnification': 2.5}, format=constants.TILE_FORMAT_IMAGE, encoding='PNG'): tileCount += 1 assert tile['tile'][:len(utilities.PNGHeader)] == utilities.PNGHeader assert tileCount == 45 # Ask for TIFFS tileCount = 0 for tile in source.tileIterator(scale={'magnification': 2.5}, format=constants.TILE_FORMAT_IMAGE, encoding='TIFF'): tileCount += 1 assert tile['tile'][:len(utilities.TIFFHeader)] == utilities.TIFFHeader assert tileCount == 45
def testTileIteratorSingleTile(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) # Test getting a single tile sourceRegion = { 'width': 0.7, 'height': 0.6, 'left': 0.15, 'top': 0.2, 'units': 'fraction' } tileCount = 0 for tile in source.tileIterator(region=sourceRegion, scale={'magnification': 5}, tile_position=25): tileCount += 1 assert tile['tile_position']['position'] == 25 assert tile['tile_position']['level_x'] == 8 assert tile['tile_position']['level_y'] == 2 assert tile['tile_position']['region_x'] == 4 assert tile['tile_position']['region_y'] == 1 assert tile['iterator_range']['level_x_min'] == 4 assert tile['iterator_range']['level_y_min'] == 1 assert tile['iterator_range']['level_x_max'] == 25 assert tile['iterator_range']['level_y_max'] == 5 assert tile['iterator_range']['region_x_max'] == 21 assert tile['iterator_range']['region_y_max'] == 4 assert tile['iterator_range']['position'] == 84 assert tileCount == 1 tiles = list( source.tileIterator(region=sourceRegion, scale={'magnification': 5}, tile_position={'position': 25})) assert len(tiles) == 1 assert tiles[0]['tile_position']['position'] == 25 tiles = list( source.tileIterator(region=sourceRegion, scale={'magnification': 5}, tile_position={ 'level_x': 8, 'level_y': 2 })) assert len(tiles) == 1 assert tiles[0]['tile_position']['position'] == 25 tiles = list( source.tileIterator(region=sourceRegion, scale={'magnification': 5}, tile_position={ 'region_x': 4, 'region_y': 1 })) assert len(tiles) == 1 assert tiles[0]['tile_position']['position'] == 25 tiles = list( source.tileIterator(region=sourceRegion, scale={'magnification': 5}, tile_position={'position': 90})) assert len(tiles) == 0
def testStyleDtypeAxis(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open( imagePath, style=json.dumps({'dtype': 'uint16', 'axis': 1})) image, _ = source.getRegion( output={'maxWidth': 456, 'maxHeight': 96}, format=constants.TILE_FORMAT_NUMPY) assert image.shape[2] == 1 assert image[0][0][0] == 65021
def testConvertFromTestSourceFrames(tmpdir): outputPath = os.path.join(tmpdir, 'out.tiff') large_image_converter.convert('large_image://test?maxLevel=3&frames=4', outputPath) source = large_image_source_tiff.open(outputPath) metadata = source.getMetadata() assert metadata['levels'] == 4 assert len(metadata['frames']) == 4 info = tifftools.read_tiff(outputPath) assert len(info['ifds']) == 4
def testStyleNoData(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open( imagePath, style=json.dumps({'nodata': None})) image, _ = source.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) nodata = 86 imageB = image # Pillow 9.0.0 changed how they decode JPEGs, so find a nodata value that # will cause a difference while numpy.all(imageB == image): nodata += 1 sourceB = large_image_source_tiff.open( imagePath, style=json.dumps({'nodata': nodata})) imageB, _ = sourceB.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) assert numpy.all(image[:, :, 3] == 255) assert numpy.any(imageB[:, :, 3] != 255)
def testConvertFromMultiframeImageOnlyOneFrame(tmpdir): imagePath = datastore.fetch('sample.ome.tif') outputPath = os.path.join(tmpdir, 'out.tiff') large_image_converter.convert(imagePath, outputPath, onlyFrame=2) source = large_image_source_tiff.open(outputPath) metadata = source.getMetadata() assert metadata['levels'] == 5 info = tifftools.read_tiff(outputPath) assert len(info['ifds']) == 5
def testConvertFromMultiframeImageNoSubIFDS(tmpdir): imagePath = datastore.fetch('sample.ome.tif') outputPath = os.path.join(tmpdir, 'out.tiff') large_image_converter.convert(imagePath, outputPath, subifds=False) source = large_image_source_tiff.open(outputPath) metadata = source.getMetadata() assert metadata['levels'] == 5 assert len(metadata['frames']) == 3 info = tifftools.read_tiff(outputPath) assert len(info['ifds']) == 15
def testStyleMinMaxThreshold(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open( imagePath, style=json.dumps({'min': 'min', 'max': 'max'})) image, _ = source.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) sourceB = large_image_source_tiff.open( imagePath, style=json.dumps({'min': 'min:0.02', 'max': 'max:0.02'})) imageB, _ = sourceB.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) assert numpy.any(image != imageB) assert image[0][0][0] == 252 assert imageB[0][0][0] == 254 sourceC = large_image_source_tiff.open( imagePath, style=json.dumps({'min': 'full', 'max': 'full'})) imageC, _ = sourceC.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) assert numpy.any(image != imageC) assert imageC[0][0][0] == 253
def testStyleSwapChannels(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) image, _ = source.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) # swap the green and blue channels sourceB = large_image_source_tiff.open(imagePath, style={'bands': [ {'band': 'red', 'palette': ['#000', '#f00']}, {'band': 'green', 'palette': ['#000', '#00f']}, {'band': 'blue', 'palette': ['#000', '#0f0']}, ]}) imageB, _ = sourceB.getRegion( output={'maxWidth': 256, 'maxHeight': 256}, format=constants.TILE_FORMAT_NUMPY) imageB = imageB[:, :, :3] assert numpy.any(image != imageB) assert numpy.all(image[:, :, 0] == imageB[:, :, 0]) assert numpy.any(image[:, :, 1] != imageB[:, :, 1]) assert numpy.all(image[:, :, 1] == imageB[:, :, 2]) assert numpy.all(image[:, :, 2] == imageB[:, :, 1])
def testTilesFromSCN(): imagePath = datastore.fetch('sample_leica.scn') source = large_image_source_tiff.open(imagePath) tileMetadata = source.getMetadata() assert tileMetadata['tileWidth'] == 512 assert tileMetadata['tileHeight'] == 512 assert tileMetadata['sizeX'] == 4737 assert tileMetadata['sizeY'] == 6338 assert tileMetadata['levels'] == 5 assert tileMetadata['magnification'] == 20 utilities.checkTilesZXY(source, tileMetadata)
def testStyleNoData(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath, style=json.dumps({'nodata': None})) image, _ = source.getRegion(output={ 'maxWidth': 256, 'maxHeight': 256 }, format=constants.TILE_FORMAT_NUMPY) sourceB = large_image_source_tiff.open(imagePath, style=json.dumps({'nodata': 101})) imageB, _ = sourceB.getRegion(output={ 'maxWidth': 256, 'maxHeight': 256 }, format=constants.TILE_FORMAT_NUMPY) assert numpy.all(image[:, :, 3] == 255) assert numpy.any(imageB[:, :, 3] != 255) assert image[12][215][3] == 255 assert imageB[12][215][3] != 255
def testTilesFromPTIFJpeg2K(): imagePath = datastore.fetch('huron.image2_jpeg2k.tif') source = large_image_source_tiff.open(imagePath) tileMetadata = source.getMetadata() assert tileMetadata['tileWidth'] == 256 assert tileMetadata['tileHeight'] == 256 assert tileMetadata['sizeX'] == 9158 assert tileMetadata['sizeY'] == 11273 assert tileMetadata['levels'] == 7 assert tileMetadata['magnification'] == 20 utilities.checkTilesZXY(source, tileMetadata)
def testTilesFromMultipleTiledTIF(): imagePath = datastore.fetch('JK-kidney_H3_4C_1-500sec.tif') source = large_image_source_tiff.open(imagePath) tileMetadata = source.getMetadata() assert tileMetadata['tileWidth'] == 256 assert tileMetadata['tileHeight'] == 256 assert tileMetadata['sizeX'] == 16384 assert tileMetadata['sizeY'] == 14848 assert tileMetadata['levels'] == 7 assert tileMetadata['magnification'] == 40 utilities.checkTilesZXY(source, tileMetadata)
def testTilesFromMissingLayer(): imagePath = datastore.fetch('one_layer_missing_tiles.tiff') source = large_image_source_tiff.open(imagePath) tileMetadata = source.getMetadata() assert tileMetadata['tileWidth'] == 256 assert tileMetadata['tileHeight'] == 256 assert tileMetadata['sizeX'] == 5477 assert tileMetadata['sizeY'] == 4515 assert tileMetadata['levels'] == 6 with pytest.raises(Exception): utilities.checkTilesZXY(source, tileMetadata) utilities.checkTilesZXY(source, tileMetadata, {'sparseFallback': True})
def testTilesAssociatedImages(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) imageList = source.getAssociatedImagesList() assert imageList == ['label', 'macro'] image, mimeType = source.getAssociatedImage('label') assert image[:len(utilities.JPEGHeader)] == utilities.JPEGHeader image, mimeType = source.getAssociatedImage('label', encoding='PNG', width=256, height=256) assert image[:len(utilities.PNGHeader)] == utilities.PNGHeader (width, height) = struct.unpack('!LL', image[16:24]) assert max(width, height) == 256 # Test missing associated image assert source.getAssociatedImage('nosuchimage') is None
def testTilesFromMultiFrameTiffWithSubIFD(): imagePath = datastore.fetch('sample.subifd.ome.tif') source = large_image_source_tiff.open(imagePath, frame=1) tileMetadata = source.getMetadata() assert tileMetadata['tileWidth'] == 256 assert tileMetadata['tileHeight'] == 256 assert tileMetadata['sizeX'] == 2106 assert tileMetadata['sizeY'] == 2016 assert tileMetadata['levels'] == 5 assert len(tileMetadata['frames']) == 3 assert tileMetadata['frames'][1]['Frame'] == 1 utilities.checkTilesZXY(source, tileMetadata) tile = source.getSingleTile() assert list(tile['tile'][0, 0]) == [7710]
def testTilesFromPTIF(): testDir = os.path.dirname(os.path.realpath(__file__)) imagePath = os.path.join(testDir, 'test_files', 'yb10kx5k.png') assert large_image_source_tiff.canRead(imagePath) is False imagePath = datastore.fetch('sample_image.ptif') assert large_image_source_tiff.canRead(imagePath) is True source = large_image_source_tiff.open(imagePath) tileMetadata = source.getMetadata() assert tileMetadata['tileWidth'] == 256 assert tileMetadata['tileHeight'] == 256 assert tileMetadata['sizeX'] == 58368 assert tileMetadata['sizeY'] == 12288 assert tileMetadata['levels'] == 9 tileMetadata['sparse'] = 5 utilities.checkTilesZXY(source, tileMetadata)
def testTileFrames(): imagePath = datastore.fetch('sample.ome.tif') source = large_image_source_tiff.open(imagePath) params = {'encoding': 'PNG', 'output': {'maxWidth': 200, 'maxHeight': 200}} image, mimeType = source.tileFrames(**params) assert image[:len(utilities.PNGHeader)] == utilities.PNGHeader (width, height) = struct.unpack('!LL', image[16:24]) assert width == 400 assert height == 382 params['fill'] = 'corner:black' image, mimeType = source.tileFrames(**params) assert image[:len(utilities.PNGHeader)] == utilities.PNGHeader (width, height) = struct.unpack('!LL', image[16:24]) assert width == 400 assert height == 400 params['framesAcross'] = 3 image, mimeType = source.tileFrames(**params) assert image[:len(utilities.PNGHeader)] == utilities.PNGHeader (width, height) = struct.unpack('!LL', image[16:24]) assert width == 600 assert height == 200 params['frameList'] = [0, 2] image, mimeType = source.tileFrames(**params) assert image[:len(utilities.PNGHeader)] == utilities.PNGHeader (width, height) = struct.unpack('!LL', image[16:24]) assert width == 400 assert height == 200 params['frameList'] = [0] image, mimeType = source.tileFrames(**params) assert image[:len(utilities.PNGHeader)] == utilities.PNGHeader (width, height) = struct.unpack('!LL', image[16:24]) assert width == 200 assert height == 200 params.pop('frameList') params['encoding'] = 'TILED' image, mimeType = source.tileFrames(**params) info = tifftools.read_tiff(image) assert len(info['ifds']) == 3 os.unlink(image)
def testGetSingleTile(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) sourceRegion = { 'width': 0.7, 'height': 0.6, 'left': 0.15, 'top': 0.2, 'units': 'fraction' } sourceScale = {'magnification': 5} targetScale = {'magnification': 2.5} tile = source.getSingleTile(region=sourceRegion, scale=sourceScale, tile_position=25) assert tile['tile_position']['position'] == 25 assert tile['tile_position']['level_x'] == 8 assert tile['tile_position']['level_y'] == 2 assert tile['tile_position']['region_x'] == 4 assert tile['tile_position']['region_y'] == 1 assert tile['iterator_range']['level_x_min'] == 4 assert tile['iterator_range']['level_y_min'] == 1 assert tile['iterator_range']['level_x_max'] == 25 assert tile['iterator_range']['level_y_max'] == 5 assert tile['iterator_range']['region_x_max'] == 21 assert tile['iterator_range']['region_y_max'] == 4 assert tile['iterator_range']['position'] == 84 tile = source.getSingleTileAtAnotherScale(sourceRegion, sourceScale, targetScale, tile_position=25) assert tile['tile_position']['position'] == 25 assert tile['tile_position']['level_x'] == 5 assert tile['tile_position']['level_y'] == 2 assert tile['tile_position']['region_x'] == 3 assert tile['tile_position']['region_y'] == 2 assert tile['iterator_range']['level_x_min'] == 2 assert tile['iterator_range']['level_y_min'] == 0 assert tile['iterator_range']['level_x_max'] == 13 assert tile['iterator_range']['level_y_max'] == 3 assert tile['iterator_range']['region_x_max'] == 11 assert tile['iterator_range']['region_y_max'] == 3 assert tile['iterator_range']['position'] == 33
def testHistogram(): imagePath = datastore.fetch('sample_image.ptif') source = large_image_source_tiff.open(imagePath) hist = source.histogram(bins=8, output={'maxWidth': 1024}, resample=False) assert len(hist['histogram']) == 3 assert hist['histogram'][0]['range'] == (0, 256) assert len(list(hist['histogram'][0]['hist'])) == 8 assert list(hist['histogram'][0]['bin_edges']) == [0, 32, 64, 96, 128, 160, 192, 224, 256] assert hist['histogram'][0]['samples'] == 700416 hist = source.histogram(bins=256, output={'maxWidth': 1024}, resample=False, density=True) assert len(hist['histogram']) == 3 assert hist['histogram'][0]['range'] == (0, 256) assert len(list(hist['histogram'][0]['hist'])) == 256 assert 5e-5 < hist['histogram'][0]['hist'][128] < 7e-5 assert hist['histogram'][0]['samples'] == 700416 hist = source.histogram(bins=256, output={'maxWidth': 2048}, density=True, resample=False) assert hist['histogram'][0]['samples'] == 2801664 assert 6e-5 < hist['histogram'][0]['hist'][128] < 8e-5