https://github.com/girder/large_image https://digitalslidearchive.github.io/HistomicsTK/installation.html
https://github.com/DigitalSlideArchive/HistomicsTK
761 mkdir machine-learning
  762  cd machine-learning/
  763  ls
  764  mkdir HistomicsTK
  765  ls
  766  cd HistomicsTK/
  767  ls
  768  git clone https://github.com/DigitalSlideArchive/HistomicsTK.git
  769  ls
  770  cd HistomicsTK/
  771  ls
  772  pip install git+https://github.com/cdeepakroy/ctk-cli
  773  ls
  774  vim requirements_dev.txt
  777  pip install --no-cache-dir -r requirements_dev.txt
  778  ls
  779  pip install -e .
OSError: libopenslide.so.0: cannot open shared object file: No such file or directory
./OE5g2z8.jpg: Not a TIFF or MDI file, bad magic number 55551 (0xd8ff).
Made a thumbnail of type image/jpeg taking 499854 bytes
Traceback (most recent call last):
  File "average_color.py", line 56, in <module>
    average_color(args.path, args.magnification)
  File "average_color.py", line 42, in average_color
    tile['magnification'], mean[0], mean[1], mean[2]))
TypeError: float argument required, not NoneType
FIx by:  $ sudo apt-get install python-openslide
$ wget https://file-examples.com/wp-content/uploads/2017/10/file_example_TIFF_5MB.tiff
$ python average_color.py file_example_TIFF_5MB.tiff -m 0.34
# An example to get a tile source, save a thumbnail, and iterate through the
# tiles at a specific magnification, reporting the average color of each tile.
import argparse
import numpy
import large_image
# Explicitly set the caching method before we request any data
#large_image.cache_util.setConfig('cache_backend', 'python')
def average_color(imagePath, magnification=None):   #magnification=None):
    """
    Print the average color for a tiled image file.
    :param imagePath: path of the file to analyze.
    :param magnification: optional magnification to use for the analysis.
    """
    source = large_image.getTileSource(imagePath)
    print("source is {}".format(source))
    # get a thumbnail no larger than 1024x1024 pixels
    thumbnail, mimeType = source.getThumbnail(
        width=1024, height=1024, encoding='JPEG')
    print('Made a thumbnail of type %s taking %d bytes' % (
        mimeType, len(thumbnail)))
    # We could save it, if we want to.
    open('./thumbnail.jpg', 'wb').write(thumbnail)
    tileMeans = []
    tileWeights = []
    # iterate through the tiles at a particular magnification:
    for tile in source.tileIterator(
            format=large_image.tilesource.TILE_FORMAT_NUMPY,
            scale={'magnification': magnification},
            resample=True):
        # The tile image data is in tile['tile'] and is a numpy
        # multi-dimensional array
        print("tile is {}".format(tile))
        mean = numpy.mean(tile['tile'], axis=(0, 1))
        tileMeans.append(mean)
        tileWeights.append(tile['width'] * tile['height'])
        #'''
        #print('x: %d  y: %d  w: %d  h: %d  mag: %g  color: %g %g %g' % (
        print('x: %d  y: %d  w: %d  h: %d  color: %f %f %f' % (
            tile['x'], tile['y'], tile['width'], tile['height'],  mean[0], mean[1], mean[2]))
            #tile['x'], tile['y'], tile['width'], tile['height'], tile['magnification'], mean[0], mean[1], mean[2]))
        print("magnification is {}".format(tile['magnification']))
        #'''
    mean = numpy.average(tileMeans, axis=0, weights=tileWeights)
    print('Average color: %g %g %g' % (mean[0], mean[1], mean[2]))
if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Compute the mean color of a tiled image')
    parser.add_argument('path', metavar='image-path', type=str,
                        help='Path of the tiled image to examine')
    parser.add_argument('-m', '--magnification', dest='magnification',
                        type=float,
                        help='Magnification to use to examine the image')
    args = parser.parse_args()
    average_color(args.path, args.magnification)
                    
                
                
            
        
浙公网安备 33010602011771号