coastalimagelib/corefunctions.py
def mergeRectify(input_frames, cameras, grid):
    """
    This function performs image rectifications at one timestamp given
    the associated extrinsics, intrinsics, and distorted images
    corresponding to each camera contained within the CameraData object.
    The function utilizes matchHist to match images from each camera
    to the same histogram, then calls xyz2DistUV or dlt2UV to find
    corresponding UVd values to the input grid and pulls the rgb pixel
    intensity for each value using getPixels.

    If a multi-camera rectification is desired, images, intrinsic_list,
    and extrinsic_list can be input as cell values for each camera.

    The function calls cameraSeamBlend as a last step to merge the values.

    Inputs:
        input_frames (list OR ndarray): 1xK list of paths to images for
            each camera, OR NxMxK struct of images, one image per camera
            at the desired timestamp for rectification
        cameras (array of CameraData objects): contains:
            intrinsic_list (list): 1x11xK internal calibration data for
                each camera
            extrinsic_list (list): 1x6xK external calibration data for
                each camera
            mType: intrinsic format ('DLT' or 'CIRN')
        xyz (ndarray): XYZ rectification grid

    Returns:
        Ir (ndarray): Image intensities at xyz points (georectified image)

    """
    s = grid.X.shape
    numcams = len(cameras)

    # Iterate through each camera from to produce single merged frame
    for k, (I, calib) in enumerate(zip(input_frames, cameras)):
        nc = calib.nc
        # Determine if the user provided a filepath or image
        if isinstance(I, str):
            # Load image from current camera
            image = imageio.imread(I)
        else:
            image = input_frames[:, :, (k * nc): (k * nc + nc)]

        # Match histograms
        if k == 0:
            ref = image
        else:
            image = matchHist(ref, image)

        # Find distorted UV points at each XY location in grid
        if calib.mType == "CIRN":
            Ud, Vd = xyz2DistUV(grid, calib)
        elif calib.mType == "DLT":
            Ud, Vd = dlt2UV(grid, calib)
        else:
            sys.exit("This intrinsics format is not supported")

        # Grab pixels from image at each position
        ir = getPixels(image, Ud, Vd, s)

        # Initialize array for pixel values
        if k == 0:
            IrIndv = np.tile(np.zeros((s[0], s[1], numcams)), (nc,))

        IrIndv[:, :, (k * nc): (k * nc + nc)] = ir

    # Merge rectifications of multiple cameras
    Ir = cameraSeamBlend(IrIndv, numcams, nc)

    # Return merged frame
    return np.flipud(Ir.astype(np.uint8))

    This function performs image rectifications at one timestamp given
    the associated extrinsics, intrinsics, and distorted images
    corresponding to each camera contained within the CameraData object.
    The function utilizes matchHist to match images from each camera
    to the same histogram, then calls xyz2DistUV or dlt2UV to find
    corresponding UVd values to the input grid and pulls the rgb pixel
    intensity for each value using getPixels.

    If a multi-camera rectification is desired, images, intrinsic_list,
    and extrinsic_list can be input as cell values for each camera.

    The function calls cameraSeamBlend as a last step to merge the values.

    Inputs:
        input_frames (list OR ndarray): 1xK list of paths to images for
            each camera, OR NxMxK struct of images, one image per camera
            at the desired timestamp for rectification
        cameras (array of CameraData objects): contains:
            intrinsic_list (list): 1x11xK internal calibration data for
                each camera
            extrinsic_list (list): 1x6xK external calibration data for
                each camera
            mType: intrinsic format ('DLT' or 'CIRN')
        xyz (ndarray): XYZ rectification grid

    Returns:
        Ir (ndarray): Image intensities at xyz points (georectified image)

    
This function performs image rectifications at one timestamp given
the associated extrinsics, intrinsics, and distorted images
corresponding to each camera contained within the CameraData object.
The function utilizes matchHist to match images from each camera
to the same histogram, then calls xyz2DistUV or dlt2UV to find
corresponding UVd values to the input grid and pulls the rgb pixel
intensity for each value using getPixels.

If a multi-camera rectification is desired, images, intrinsic_list,
and extrinsic_list can be input as cell values for each camera.

The function calls cameraSeamBlend as a last step to merge the values.


This function performs image rectifications at one timestamp given the associated extrinsics intrinsics and distorted images corresponding to each camera contained within the CameraData object . The function utilizes matchHist to match images from each camera to the same histogram then calls xyz2DistUV or dlt2UV to find corresponding UVd values to the input grid and pulls the rgb pixel intensity for each value using getPixels . If a multi - camera rectification is desired images intrinsic_list and extrinsic_list can be input as cell values for each camera . The function calls cameraSeamBlend as a last step to merge the values .
def mergeRectify(input_frames, cameras, grid):
    s = grid.X.shape
    numcams = len(cameras)
    for k, (I, calib) in enumerate(zip(input_frames, cameras)):
        nc = calib.nc
        if isinstance(I, str):
            image = imageio.imread(I)
        else:
            image = input_frames[:, :, (k * nc): (k * nc + nc)]
        if k == 0:
            ref = image
        else:
            image = matchHist(ref, image)
        if calib.mType == "CIRN":
            Ud, Vd = xyz2DistUV(grid, calib)
        elif calib.mType == "DLT":
            Ud, Vd = dlt2UV(grid, calib)
        else:
            sys.exit("This intrinsics format is not supported")
        ir = getPixels(image, Ud, Vd, s)
        if k == 0:
            IrIndv = np.tile(np.zeros((s[0], s[1], numcams)), (nc,))
        IrIndv[:, :, (k * nc): (k * nc + nc)] = ir
    Ir = cameraSeamBlend(IrIndv, numcams, nc)
    return np.flipud(Ir.astype(np.uint8))
def mergeRectify ( input_frames , cameras , grid ) : s = grid . X . shape numcams = len ( cameras ) for k , ( I , calib ) in enumerate ( zip ( input_frames , cameras ) ) : nc = calib . nc if isinstance ( I , str ) : image = imageio . imread ( I ) else : image = input_frames [ : , : , ( k * nc ) : ( k * nc + nc ) ] if k == 0 : ref = image else : image = matchHist ( ref , image ) if calib . mType == "CIRN" : Ud , Vd = xyz2DistUV ( grid , calib ) elif calib . mType == "DLT" : Ud , Vd = dlt2UV ( grid , calib ) else : sys . exit ( "This intrinsics format is not supported" ) ir = getPixels ( image , Ud , Vd , s ) if k == 0 : IrIndv = np . tile ( np . zeros ( ( s [ 0 ] , s [ 1 ] , numcams ) ) , ( nc , ) ) IrIndv [ : , : , ( k * nc ) : ( k * nc + nc ) ] = ir Ir = cameraSeamBlend ( IrIndv , numcams , nc ) return np . flipud ( Ir . astype ( np . uint8 ) )
This function performs image rectifications at one timestamp given
the associated extrinsics, intrinsics, and distorted images
corresponding to each camera contained within the CameraData object.
This function performs image rectifications at one timestamp given the associated extrinsics intrinsics and distorted images corresponding to each camera contained within the CameraData object .
"""
    This function performs image rectifications at one timestamp given
    the associated extrinsics, intrinsics, and distorted images
    corresponding to each camera contained within the CameraData object.
    The function utilizes matchHist to match images from each camera
    to the same histogram, then calls xyz2DistUV or dlt2UV to find
    corresponding UVd values to the input grid and pulls the rgb pixel
    intensity for each value using getPixels.

    If a multi-camera rectification is desired, images, intrinsic_list,
    and extrinsic_list can be input as cell values for each camera.

    The function calls cameraSeamBlend as a last step to merge the values.

    Inputs:
        input_frames (list OR ndarray): 1xK list of paths to images for
            each camera, OR NxMxK struct of images, one image per camera
            at the desired timestamp for rectification
        cameras (array of CameraData objects): contains:
            intrinsic_list (list): 1x11xK internal calibration data for
                each camera
            extrinsic_list (list): 1x6xK external calibration data for
                each camera
            mType: intrinsic format ('DLT' or 'CIRN')
        xyz (ndarray): XYZ rectification grid

    Returns:
        Ir (ndarray): Image intensities at xyz points (georectified image)

    """ # Iterate through each camera from to produce single merged frame # Determine if the user provided a filepath or image # Load image from current camera # Match histograms # Find distorted UV points at each XY location in grid # Grab pixels from image at each position # Initialize array for pixel values # Merge rectifications of multiple cameras # Return merged frame
Ir (ndarray): Image intensities at xyz points (georectified image)
Ir ( ndarray ) : Image intensities at xyz points ( georectified image )
input_frames
cameras
grid