lama/qc/qc_images.py
def make_qc_images(lama_specimen_dir: Path,
                   target: Path,
                   outdir: Path,
                   mask: Path,
                   reverse_reg_propagation: bool = False):
    """
    Generate mid-slice images for quick qc of registration process.

    Parameters
    ----------
    lama_specimen_dir
        The registration outdir. Should contain an 'output' folder
    target
        The target image to display in cyan
    outdir
        Where to put the qc images
    mask
        Used to identify the embryo in the image so we can display useful info
    reverse_reg_propagation
        Whether to overlay on orginal unregistered input (False) or on initial, probably rigid, registered image (True)

    Notes
    -----
    Make qc images from:
        The final registration stage.
            What the volumes look like after registration
        The rigidly-registered images with the inverted labels overlaid
            This is a good indicator of regsitration accuracy

    """
    target = common.LoadImage(target).array
    # Make qc images for all stages of registration including any resolution images
    try:
        paths = LamaSpecimenData(lama_specimen_dir).setup()
    except FileNotFoundError as e:
        logging.exception(f'cannot find specimen directory\n{e}')

    # Order output dirs by qc type
    red_cyan_dir = outdir / 'red_cyan_overlays'
    greyscale_dir = outdir / 'greyscales'
    red_cyan_dir.mkdir(exist_ok=True)
    greyscale_dir.mkdir(exist_ok=True)

    try:
        for i, (stage, img_path) in enumerate(paths.registration_imgs()):
            img = common.LoadImage(img_path).array
            _make_red_cyan_qc_images(target, img, red_cyan_dir, greyscale_dir, img_path.stem, i, stage)

        if paths.inverted_labels_dir:

            # First reg img will the rigid-registered image
            first_reg_dir = paths.reg_dirs[0]

            if reverse_reg_propagation:
                # We have a reverse registration method of label propagation so we overlay the labels that were transformed
                # using the reverse registrtion transform (the final defoemable stage) as the target will have been the
                # Rigid input
                inverted_label_dir = paths.inverted_labels_dir
            else:
                # The labels were propagated using the inverse transfrom method. Therefore we overlay the labels transformed
                # using the tforms up to the inverted affine stage onto the rigid input.
                # (could do inverted rigid labels overalid on orginal input, but on rigid allllows us to compare specimens
                # more easily using this method)
                inverted_label_dir = paths.inverted_labels_dir

            inverted_label_overlays_dir = outdir / 'inverted_label_overlay'
            inverted_label_overlays_dir.mkdir(exist_ok=True)

            _overlay_labels(first_reg_dir,
                            inverted_label_dir,
                            inverted_label_overlays_dir,
                            mask=mask)
    except FileNotFoundError: # 220221 bodge. lama_reg creates a different file structure tha job_runner. Need to harmonise
        logging.error('No QC images made. This maybe because you used lama_reg rather than lama_job_runner')

    Generate mid-slice images for quick qc of registration process.

    Parameters
    ----------
    lama_specimen_dir
        The registration outdir. Should contain an 'output' folder
    target
        The target image to display in cyan
    outdir
        Where to put the qc images
    mask
        Used to identify the embryo in the image so we can display useful info
    reverse_reg_propagation
        Whether to overlay on orginal unregistered input (False) or on initial, probably rigid, registered image (True)

    Notes
    -----
    Make qc images from:
        The final registration stage.
            What the volumes look like after registration
        The rigidly-registered images with the inverted labels overlaid
            This is a good indicator of regsitration accuracy

    
Generate mid-slice images for quick qc of registration process.
Parameters

lama_specimen_dir
The registration outdir. Should contain an 'output' folder
target
The target image to display in cyan
outdir
Where to put the qc images
mask
Used to identify the embryo in the image so we can display useful info
reverse_reg_propagation
Whether to overlay on orginal unregistered input (False) or on initial, probably rigid, registered image (True)

Notes

Make qc images from:
The final registration stage.
What the volumes look like after registration
The rigidly-registered images with the inverted labels overlaid
This is a good indicator of regsitration accuracy
Generate mid - slice images for quick qc of registration process . Parameters lama_specimen_dir The registration outdir . Should contain an ' output ' folder target The target image to display in cyan outdir Where to put the qc images mask Used to identify the embryo in the image so we can display useful info reverse_reg_propagation Whether to overlay on orginal unregistered input ( False ) or on initial probably rigid registered image ( True ) Notes Make qc images from : The final registration stage . What the volumes look like after registration The rigidly - registered images with the inverted labels overlaid This is a good indicator of regsitration accuracy
def make_qc_images(lama_specimen_dir: Path,
                   target: Path,
                   outdir: Path,
                   mask: Path,
                   reverse_reg_propagation: bool = False):
    target = common.LoadImage(target).array
    try:
        paths = LamaSpecimenData(lama_specimen_dir).setup()
    except FileNotFoundError as e:
        logging.exception(f'cannot find specimen directory\n{e}')
    red_cyan_dir = outdir / 'red_cyan_overlays'
    greyscale_dir = outdir / 'greyscales'
    red_cyan_dir.mkdir(exist_ok=True)
    greyscale_dir.mkdir(exist_ok=True)
    try:
        for i, (stage, img_path) in enumerate(paths.registration_imgs()):
            img = common.LoadImage(img_path).array
            _make_red_cyan_qc_images(target, img, red_cyan_dir, greyscale_dir, img_path.stem, i, stage)
        if paths.inverted_labels_dir:
            first_reg_dir = paths.reg_dirs[0]
            if reverse_reg_propagation:
                inverted_label_dir = paths.inverted_labels_dir
            else:
                inverted_label_dir = paths.inverted_labels_dir
            inverted_label_overlays_dir = outdir / 'inverted_label_overlay'
            inverted_label_overlays_dir.mkdir(exist_ok=True)
            _overlay_labels(first_reg_dir,
                            inverted_label_dir,
                            inverted_label_overlays_dir,
                            mask=mask)
    except FileNotFoundError: 
        logging.error('No QC images made. This maybe because you used lama_reg rather than lama_job_runner')
def make_qc_images ( lama_specimen_dir : Path , target : Path , outdir : Path , mask : Path , reverse_reg_propagation : bool = False ) : target = common . LoadImage ( target ) . array try : paths = LamaSpecimenData ( lama_specimen_dir ) . setup ( ) except FileNotFoundError as e : logging . exception ( f'cannot find specimen directory\n{e}' ) red_cyan_dir = outdir / 'red_cyan_overlays' greyscale_dir = outdir / 'greyscales' red_cyan_dir . mkdir ( exist_ok = True ) greyscale_dir . mkdir ( exist_ok = True ) try : for i , ( stage , img_path ) in enumerate ( paths . registration_imgs ( ) ) : img = common . LoadImage ( img_path ) . array _make_red_cyan_qc_images ( target , img , red_cyan_dir , greyscale_dir , img_path . stem , i , stage ) if paths . inverted_labels_dir : first_reg_dir = paths . reg_dirs [ 0 ] if reverse_reg_propagation : inverted_label_dir = paths . inverted_labels_dir else : inverted_label_dir = paths . inverted_labels_dir inverted_label_overlays_dir = outdir / 'inverted_label_overlay' inverted_label_overlays_dir . mkdir ( exist_ok = True ) _overlay_labels ( first_reg_dir , inverted_label_dir , inverted_label_overlays_dir , mask = mask ) except FileNotFoundError : logging . error ( 'No QC images made. This maybe because you used lama_reg rather than lama_job_runner' )
Generate mid-slice images for quick qc of registration process.
Generate mid - slice images for quick qc of registration process .
"""
    Generate mid-slice images for quick qc of registration process.

    Parameters
    ----------
    lama_specimen_dir
        The registration outdir. Should contain an 'output' folder
    target
        The target image to display in cyan
    outdir
        Where to put the qc images
    mask
        Used to identify the embryo in the image so we can display useful info
    reverse_reg_propagation
        Whether to overlay on orginal unregistered input (False) or on initial, probably rigid, registered image (True)

    Notes
    -----
    Make qc images from:
        The final registration stage.
            What the volumes look like after registration
        The rigidly-registered images with the inverted labels overlaid
            This is a good indicator of regsitration accuracy

    """ # Make qc images for all stages of registration including any resolution images # Order output dirs by qc type # First reg img will the rigid-registered image # We have a reverse registration method of label propagation so we overlay the labels that were transformed # using the reverse registrtion transform (the final defoemable stage) as the target will have been the # Rigid input # The labels were propagated using the inverse transfrom method. Therefore we overlay the labels transformed # using the tforms up to the inverted affine stage onto the rigid input. # (could do inverted rigid labels overalid on orginal input, but on rigid allllows us to compare specimens # more easily using this method) # 220221 bodge. lama_reg creates a different file structure tha job_runner. Need to harmonise
lama_specimen_dir
Path
target
Path
outdir
Path
mask
Path
reverse_reg_propagation
bool