coastalimagelib/corefunctions.py
def pixelStack(frames, grid, cameras, disp_flag=0):
    """
    Function that creates pixel instruments for use in bathymetric inversion,
    surface current, run-up calculations, or other quantitative analyses.
    Instruments can be made in both world and a local rotated coordinate
    system. However, for ease and accuracy, if planned to use in bathymetric
    inversion, surface current, or run-up applications, it should occur
    in local coordinates.


    Inputs:
        grid: XYZGrid object of desired real world coordinates
        cameras_images (array): N x M x K x num_frames struct of images,
            one image per camera (K) at the desired timestamp
            for rectification (N x M is image height x image width,
            K is number of cameras, num_frames is number of frames)
        cameras (K length array of CameraData objects): contains
            intrinsic_list (list): 1x11xK internal calibration data
            extrinsic_list (list): 1x6xK external calibration data
            origin: local origin (x,y,z,angle)
            mType (string): format of intrinsic matrix,
                'CIRN' is default, 'DLT' is also supported
        sample_freq (int): desired frequency at which to grab pixels.
            This does not factor in camera metadata. User must know frames
            per second of collection. freq=1 means grab pixels at every frame.
            For example, freq=2 means grab pixels at every other frame.
        disp_flag (bool): flag to display output image products
            coords (string): 'geo' or 'local'; if 'geo',
            extrinsics transformed to local but origin is needed to transform

    Returns:
        pixels (ndarray): pixel intensities at xyz points (georectified image).
            Size depends on type of pixels. Axis 3 has the same length
            as number of frames/ sample rate

    """

    # Loop for Collecting Pixel Instrument Data.
    s = grid.X.shape
    nc = cameras[0].nc
    numcams = len(cameras)
    if disp_flag:
        fig, axs = plt.subplots(1, numcams)

    # Iterate through each camera from to produce single merged frame
    for k, (I, calib) in enumerate(zip(frames, cameras)):
        nc = calib.nc
        # Determine if filepath or image was provided
        if isinstance(I, str):
            # Load image from current camera
            image = imageio.imread(I)
        else:
            image = 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

        if disp_flag:
            # Show pixels on image
            axs[k].xaxis.set_visible(False)
            axs[k].yaxis.set_visible(False)
            axs[k].imshow(
                image.astype(np.uint8),
                cmap="gray",
                vmin=0,
                vmax=255
            )
            mask = ((Ud < image.shape[1])
                    & (Ud > 0)
                    & (Vd < image.shape[0])
                    & (Vd > 0))
            axs[k].scatter(Ud[mask], Vd[mask], s=3, c="r")

    # Merge rectifications of multiple cameras
    pixels = cameraSeamBlend(IrIndv, numcams, nc)
    if disp_flag:
        plt.show()

    # Return pixels
    pixels = pixels.astype(np.uint8)

    return pixels

    Function that creates pixel instruments for use in bathymetric inversion,
    surface current, run-up calculations, or other quantitative analyses.
    Instruments can be made in both world and a local rotated coordinate
    system. However, for ease and accuracy, if planned to use in bathymetric
    inversion, surface current, or run-up applications, it should occur
    in local coordinates.


    Inputs:
        grid: XYZGrid object of desired real world coordinates
        cameras_images (array): N x M x K x num_frames struct of images,
            one image per camera (K) at the desired timestamp
            for rectification (N x M is image height x image width,
            K is number of cameras, num_frames is number of frames)
        cameras (K length array of CameraData objects): contains
            intrinsic_list (list): 1x11xK internal calibration data
            extrinsic_list (list): 1x6xK external calibration data
            origin: local origin (x,y,z,angle)
            mType (string): format of intrinsic matrix,
                'CIRN' is default, 'DLT' is also supported
        sample_freq (int): desired frequency at which to grab pixels.
            This does not factor in camera metadata. User must know frames
            per second of collection. freq=1 means grab pixels at every frame.
            For example, freq=2 means grab pixels at every other frame.
        disp_flag (bool): flag to display output image products
            coords (string): 'geo' or 'local'; if 'geo',
            extrinsics transformed to local but origin is needed to transform

    Returns:
        pixels (ndarray): pixel intensities at xyz points (georectified image).
            Size depends on type of pixels. Axis 3 has the same length
            as number of frames/ sample rate

    
Function that creates pixel instruments for use in bathymetric inversion,
surface current, run-up calculations, or other quantitative analyses.
Instruments can be made in both world and a local rotated coordinate
system. However, for ease and accuracy, if planned to use in bathymetric
inversion, surface current, or run-up applications, it should occur
in local coordinates.


Function that creates pixel instruments for use in bathymetric inversion surface current run - up calculations or other quantitative analyses . Instruments can be made in both world and a local rotated coordinate system . However for ease and accuracy if planned to use in bathymetric inversion surface current or run - up applications it should occur in local coordinates .
def pixelStack(frames, grid, cameras, disp_flag=0):
    s = grid.X.shape
    nc = cameras[0].nc
    numcams = len(cameras)
    if disp_flag:
        fig, axs = plt.subplots(1, numcams)
    for k, (I, calib) in enumerate(zip(frames, cameras)):
        nc = calib.nc
        if isinstance(I, str):
            image = imageio.imread(I)
        else:
            image = 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
        if disp_flag:
            axs[k].xaxis.set_visible(False)
            axs[k].yaxis.set_visible(False)
            axs[k].imshow(
                image.astype(np.uint8),
                cmap="gray",
                vmin=0,
                vmax=255
            )
            mask = ((Ud < image.shape[1])
                    & (Ud > 0)
                    & (Vd < image.shape[0])
                    & (Vd > 0))
            axs[k].scatter(Ud[mask], Vd[mask], s=3, c="r")
    pixels = cameraSeamBlend(IrIndv, numcams, nc)
    if disp_flag:
        plt.show()
    pixels = pixels.astype(np.uint8)
    return pixels
def pixelStack ( frames , grid , cameras , disp_flag = 0 ) : s = grid . X . shape nc = cameras [ 0 ] . nc numcams = len ( cameras ) if disp_flag : fig , axs = plt . subplots ( 1 , numcams ) for k , ( I , calib ) in enumerate ( zip ( frames , cameras ) ) : nc = calib . nc if isinstance ( I , str ) : image = imageio . imread ( I ) else : image = 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 if disp_flag : axs [ k ] . xaxis . set_visible ( False ) axs [ k ] . yaxis . set_visible ( False ) axs [ k ] . imshow ( image . astype ( np . uint8 ) , cmap = "gray" , vmin = 0 , vmax = 255 ) mask = ( ( Ud < image . shape [ 1 ] ) & ( Ud > 0 ) & ( Vd < image . shape [ 0 ] ) & ( Vd > 0 ) ) axs [ k ] . scatter ( Ud [ mask ] , Vd [ mask ] , s = 3 , c = "r" ) pixels = cameraSeamBlend ( IrIndv , numcams , nc ) if disp_flag : plt . show ( ) pixels = pixels . astype ( np . uint8 ) return pixels
Function that creates pixel instruments for use in bathymetric inversion,
surface current, run-up calculations, or other quantitative analyses.
Function that creates pixel instruments for use in bathymetric inversion surface current run - up calculations or other quantitative analyses .
"""
    Function that creates pixel instruments for use in bathymetric inversion,
    surface current, run-up calculations, or other quantitative analyses.
    Instruments can be made in both world and a local rotated coordinate
    system. However, for ease and accuracy, if planned to use in bathymetric
    inversion, surface current, or run-up applications, it should occur
    in local coordinates.


    Inputs:
        grid: XYZGrid object of desired real world coordinates
        cameras_images (array): N x M x K x num_frames struct of images,
            one image per camera (K) at the desired timestamp
            for rectification (N x M is image height x image width,
            K is number of cameras, num_frames is number of frames)
        cameras (K length array of CameraData objects): contains
            intrinsic_list (list): 1x11xK internal calibration data
            extrinsic_list (list): 1x6xK external calibration data
            origin: local origin (x,y,z,angle)
            mType (string): format of intrinsic matrix,
                'CIRN' is default, 'DLT' is also supported
        sample_freq (int): desired frequency at which to grab pixels.
            This does not factor in camera metadata. User must know frames
            per second of collection. freq=1 means grab pixels at every frame.
            For example, freq=2 means grab pixels at every other frame.
        disp_flag (bool): flag to display output image products
            coords (string): 'geo' or 'local'; if 'geo',
            extrinsics transformed to local but origin is needed to transform

    Returns:
        pixels (ndarray): pixel intensities at xyz points (georectified image).
            Size depends on type of pixels. Axis 3 has the same length
            as number of frames/ sample rate

    """ # Loop for Collecting Pixel Instrument Data. # Iterate through each camera from to produce single merged frame # Determine if filepath or image was provided # 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 # Show pixels on image # Merge rectifications of multiple cameras # Return pixels
pixels (ndarray): pixel intensities at xyz points (georectified image).
Size depends on type of pixels. Axis 3 has the same length
as number of frames/ sample rate
pixels ( ndarray ) : pixel intensities at xyz points ( georectified image ) . Size depends on type of pixels . Axis 3 has the same length as number of frames / sample rate
frames
grid
cameras
disp_flag