Пример #1
0
 def __init__(self, locations):
     caffe.set_mode_gpu()
     self.utils = ImageUtils(locations)
     self.subject = None
     self.index = None
     self.WSIZE = None
     self.BMODE = NetTest.BLEND_MEAN
Пример #2
0
def main():
    """
    utils.create_png_images:

    Creates PNGs for all the subjects in the subject list. The NIFTI images from where these PNGs are generated
    must have been downloaded first (step 1).

    Make sure that you set NUM_LABELS, HISTOLOGY_RANGE_MIN and HISTOLOGY_RANGE_MAX in the configuration file before
    creating running this step.

    The HISTOLOGY_RANGE_MIN and HISTOLOGY_RANGE_MAX parameters determine how histology values are mapped to labels.
    These two parameters correspond to cmin, and cmax in scipy.misc.bytescale
    See: https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.misc.bytescale.html

    """

    config = dh_read_config(
        '/home/dcantor/projects/deephisto/code/config_neuronal_density.ini')
    #config = dh_read_config('/home/dcantor/projects/deephisto/code/config_field_fraction.ini')

    subjects = dh_load_subjects(config)
    utils = ImageUtils(config)

    dh_get_histo_range(config)

    # comment this for loop if you only want to run dh_get_histo_range. This will report the domain values (histology)
    for s in subjects:
        print s
        utils.create_png_images(s)
Пример #3
0
def dh_get_histo_range(subjects, locations):
    utils = ImageUtils(locations)
    for s in subjects:
        print
        print s
        print '---------------------------------'
        utils.set_subject(s)
        utils.get_dynrange_histo()
Пример #4
0
 def __init__(self, config):
     self.config = config
     caffe.set_mode_gpu()
     self.utils = ImageUtils(config)
     self.subject = None
     self.index = None
     self.WSIZE = None
     self.BMODE = NetTest.BLEND_MEAN
Пример #5
0
def dh_create_pngs(subjects, locations):
    """
    Creates PNGs for all the subjects in the subject list. The NIFTI images from where these PNGs are generated
    must have been downloaded first, and be accessible to the class ImageLocations
    """
    utils = ImageUtils(locations)
    for s in subjects:
        print s
        utils.set_subject(s)
        utils.create_png_images()
Пример #6
0
def _get_slices(locations):
    slices = {}
    utils = ImageUtils(locations)
    subjects = dh_load_subjects()
    print
    print 'List of subjects [slices] that will be used for patch creation'
    print '--------------------------------------------------------------'
    for s in subjects:
        utils.set_subject(s)
        slices[s] = utils.get_annotation_indices()
        print s, slices[s]

    return slices
Пример #7
0
def dh_unpack_annotations(subjects, locations):
    """
    The Histology PNGs (S_HI_x.png) are uploaded to  PLEXO (http://plexo.link) for every subject
    to manually annotate the cortex.

    These annotations are saved as a ZIP file under the annotations folder for every patient
    (see Locations.ANNOTATIONS_DIR). This method unpack that zip file and places the individual
    annotations in the Locations.MASK_DIR folder.

    This is an important step, so DeepHisto can tell which slices from every patient are actually annotated and
    which ones are not.
    """
    utils = ImageUtils(locations)
    for s in subjects:
        utils.set_subject(s)
        utils.unpack_annotations()
Пример #8
0
def dh_get_histo_range(config):
    """
    The reported histology value range should provide a good estimate for the
    HISTOLOGY_RANGE_MIN and HISTOLOGY_RANGE_MAX that yoou can set under [histology] in the configuration file
    """
    utils = ImageUtils(config)
    subjects = dh_load_subjects(config)
    print 'Number of labels :' + Console.BOLD + '%s' % config.NUM_LABELS + Console.ENDC
    print
    print 'subject\t\thistology domain\t\tlabel range'
    print '-------\t\t----------------\t\t-----------'
    for s in subjects:
        utils.set_subject(s)
        min, max = utils.get_dynrange_histology(annotated_only=False)
        min_l, max_l = utils.range_to_label(min, max)
        print '%s\t\t[%.2f,%.2f]\t\t     [%d,%d]' % (s, min, max, min_l, max_l)
    print
Пример #9
0
def dh_unpack_annotations(config):
    """
    1. The generated Histology PNGs (H_xxx.png) are uploaded to  PLEXO (http://plexo.link) for every subject.
    2. In plexo the cortex is annotated so the patch creator knows where to generate patches from.
    3. The annotations must be saved in the annotations dir (see [png] section in config file).
    4. The zip file must be saved with the patient's id. For instance EPI_P027.zip
    To achieve this the series loaded in plexo must be named EPI_P027 (or the respective patient)

    Unpacking annotations is to extract the annotations contained in the ZIP file into the mask folder (see [png]
    mask_dir)

    Annotations are used for Quality Control (see step_4_visual_inspection)
    and subsequently to extract patches for training/testing the Convolutional Network.

    """
    utils = ImageUtils(config)
    subjects = dh_load_subjects(config)
    for s in subjects:
        utils.set_subject(s)
        utils.unpack_annotations()
Пример #10
0
def dh_create_patches(target_dir, slices, locations):

    msampler = PatchSampler(wsize=28,
                            type=PatchSampler.TYPE_MONTECARLO,
                            params=dict(coverage=0.8))

    bsampler = PatchSampler(wsize=28,
                            type=PatchSampler.TYPE_BACKGROUND,
                            params=dict(overlap_factor=2, xmax=3, ymax=3))

    utils = ImageUtils(locations)

    mcreator = PatchCreator(utils, msampler, target_dir)
    bcreator = PatchCreator(utils, bsampler, target_dir)

    mcreator.clear_dir(True)

    for subject in sorted(slices):
        indices = slices[subject]
        for index in indices:
            mcreator.create_patches(subject, index)
            bcreator.create_patches(subject, index)