lama/qc/qc_images.py
def _make_red_cyan_qc_images(target: np.ndarray,
                             specimen: np.ndarray,
                             out_dir: Path,
                             grey_cale_dir: Path,
                             name: str,
                             img_num: int,
                             stage_id: str) -> List[np.ndarray]:
    """
    Create a cyan red overlay
    Parameters
    ----------
    target
    specimen`
    img_num
        A number to prefix onto the qc image so that when browing a folder the images will be sorteed
    Returns
    -------
    0: axial
    1: coronal
    2: sagittal
    """
    oris = ['axial', 'coronal', 'sagittal']

    def get_ori_dirs(root: Path):
        res = []
        for ori_name in oris:
            dir_ = root / ori_name
            dir_.mkdir(exist_ok=True)
            res.append([dir_, ori_name])
        return res

    if target.shape != specimen.shape:
        raise ValueError('target and specimen must be same shape')

    # specimen = np.clip(specimen, 0, 255)
    specimen = rescale_intensity(specimen, out_range=INTENSITY_RANGE).astype(np.uint8)
    target = rescale_intensity(target, out_range=INTENSITY_RANGE).astype(np.uint8)

    def get_slices(img):
        slices = []
        for ax in [0,1,2]:
            slices.append(np.take(img, img.shape[ax] // 2, axis=ax))
        return slices

    t = get_slices(target)
    s = get_slices(specimen)

    # histogram match the specimen to the target for each orientation slice
    #   This produces bad results sometimes. Move to adaptive histogram equalization

    # Todo: histogram matchng swtitched off as it makes the specimen disapaer. Fix this
    # s = [exposure.equalize_adapthist(x, clip_limit=0.03) for x in s]
    # Try mean normalisation
    # for ti, si in zip(t, s):
    #     med_t = ti[ti > 5].mean()
    #     med_s = si[si > 5].mean()
    #     diff = med_t - med_s
    #     si += int(diff)
    s = [match_histograms(si, ti) for si, ti in zip(s, t)]

    rc_oris = get_ori_dirs(out_dir)
    grey_oris = get_ori_dirs(grey_cale_dir)

    # put slices in folders by orientation
    for i in range(len(oris)):
        grey = s[i]
        rgb = _red_cyan_overlay(s[i], t[i])
        if not oris[i] == 'axial':
            rgb = np.flipud(rgb)
            grey = np.flipud(grey)
        imsave(rc_oris[i][0] / f'{img_num}_{stage_id}_{name}_{rc_oris[i][1]}.png', rgb)
        imsave(grey_oris[i][0]  / f'{img_num}_{stage_id}_{name}_{rc_oris[i][1]}.png', grey)

    Create a cyan red overlay
    Parameters
    ----------
    target
    specimen`
    img_num
        A number to prefix onto the qc image so that when browing a folder the images will be sorteed
    Returns
    -------
    0: axial
    1: coronal
    2: sagittal
    
Create a cyan red overlay
Parameters

target
specimen`
img_num
A number to prefix onto the qc image so that when browing a folder the images will be sorteed
Returns

axial
1: coronal
2: sagittal
Create a cyan red overlay Parameters target specimen ` img_num A number to prefix onto the qc image so that when browing a folder the images will be sorteed Returns axial 1 : coronal 2 : sagittal
def _make_red_cyan_qc_images(target: np.ndarray,
                             specimen: np.ndarray,
                             out_dir: Path,
                             grey_cale_dir: Path,
                             name: str,
                             img_num: int,
                             stage_id: str) -> List[np.ndarray]:
    oris = ['axial', 'coronal', 'sagittal']
    def get_ori_dirs(root: Path):
        res = []
        for ori_name in oris:
            dir_ = root / ori_name
            dir_.mkdir(exist_ok=True)
            res.append([dir_, ori_name])
        return res
    if target.shape != specimen.shape:
        raise ValueError('target and specimen must be same shape')
    specimen = rescale_intensity(specimen, out_range=INTENSITY_RANGE).astype(np.uint8)
    target = rescale_intensity(target, out_range=INTENSITY_RANGE).astype(np.uint8)
    def get_slices(img):
        slices = []
        for ax in [0,1,2]:
            slices.append(np.take(img, img.shape[ax] // 2, axis=ax))
        return slices
    t = get_slices(target)
    s = get_slices(specimen)
    s = [match_histograms(si, ti) for si, ti in zip(s, t)]
    rc_oris = get_ori_dirs(out_dir)
    grey_oris = get_ori_dirs(grey_cale_dir)
    for i in range(len(oris)):
        grey = s[i]
        rgb = _red_cyan_overlay(s[i], t[i])
        if not oris[i] == 'axial':
            rgb = np.flipud(rgb)
            grey = np.flipud(grey)
        imsave(rc_oris[i][0] / f'{img_num}_{stage_id}_{name}_{rc_oris[i][1]}.png', rgb)
        imsave(grey_oris[i][0]  / f'{img_num}_{stage_id}_{name}_{rc_oris[i][1]}.png', grey)
def _make_red_cyan_qc_images ( target : np . ndarray , specimen : np . ndarray , out_dir : Path , grey_cale_dir : Path , name : str , img_num : int , stage_id : str ) -> List [ np . ndarray ] : oris = [ 'axial' , 'coronal' , 'sagittal' ] def get_ori_dirs ( root : Path ) : res = [ ] for ori_name in oris : dir_ = root / ori_name dir_ . mkdir ( exist_ok = True ) res . append ( [ dir_ , ori_name ] ) return res if target . shape != specimen . shape : raise ValueError ( 'target and specimen must be same shape' ) specimen = rescale_intensity ( specimen , out_range = INTENSITY_RANGE ) . astype ( np . uint8 ) target = rescale_intensity ( target , out_range = INTENSITY_RANGE ) . astype ( np . uint8 ) def get_slices ( img ) : slices = [ ] for ax in [ 0 , 1 , 2 ] : slices . append ( np . take ( img , img . shape [ ax ] // 2 , axis = ax ) ) return slices t = get_slices ( target ) s = get_slices ( specimen ) s = [ match_histograms ( si , ti ) for si , ti in zip ( s , t ) ] rc_oris = get_ori_dirs ( out_dir ) grey_oris = get_ori_dirs ( grey_cale_dir ) for i in range ( len ( oris ) ) : grey = s [ i ] rgb = _red_cyan_overlay ( s [ i ] , t [ i ] ) if not oris [ i ] == 'axial' : rgb = np . flipud ( rgb ) grey = np . flipud ( grey ) imsave ( rc_oris [ i ] [ 0 ] / f'{img_num}_{stage_id}_{name}_{rc_oris[i][1]}.png' , rgb ) imsave ( grey_oris [ i ] [ 0 ] / f'{img_num}_{stage_id}_{name}_{rc_oris[i][1]}.png' , grey )
Create a cyan red overlay
Parameters
Create a cyan red overlay Parameters
"""
    Create a cyan red overlay
    Parameters
    ----------
    target
    specimen`
    img_num
        A number to prefix onto the qc image so that when browing a folder the images will be sorteed
    Returns
    -------
    0: axial
    1: coronal
    2: sagittal
    """ # specimen = np.clip(specimen, 0, 255) # histogram match the specimen to the target for each orientation slice #   This produces bad results sometimes. Move to adaptive histogram equalization # Todo: histogram matchng swtitched off as it makes the specimen disapaer. Fix this # s = [exposure.equalize_adapthist(x, clip_limit=0.03) for x in s] # Try mean normalisation # for ti, si in zip(t, s): #     med_t = ti[ti > 5].mean() #     med_s = si[si > 5].mean() #     diff = med_t - med_s #     si += int(diff) # put slices in folders by orientation
target
np.ndarray
specimen
np.ndarray
out_dir
Path
grey_cale_dir
Path
name
str
img_num
int
stage_id
str