-
Notifications
You must be signed in to change notification settings - Fork 1
Support Functions
This module contains functions independent of any overarching class or specific workflow, which serve to assist the user in utilizing the core functions. supportfunctions.py contains supporting functions to format intrinsic files, convert extrinsic coordinates to and from geographical and local coordinate systems, calculate extrinsic values, and other steps necessary to utilize the core functions of the CoastalImageLib library. Additionally, supportfunctions.py contains functions that interface with Argus technology, including functions to create Argus compatible filenames from UTC timestamps, and convert raw Argus files into delivery files collected from the Argus tower Argus or other mini- Argus systems. Converting raw Argus data utilizes functions contained in argusIO.py.
Functions are grouped by usage--transform functions, intrinsic function for loading and formatting, misc. functions--and listed in alphabetical order.
localTransformPoints(origin, x_in, y_in, flag) source
Transforms points either in geographical coordinates to local,
or in local to geographical.
This requires the local origin in geographical coordinates, as well as the
angle between coordinate systems in CIRN angle convention.
See the WAMFlow user manual for more information on CIRN angle convention.
Args:
origin (list or array) (xo, yo, angle): local origin (0,0) in Geographical coordinates.
Typically xo is E and yo is N coordinate.
The angle should be the relative angle
between the new (local) X axis and old (Geo)
X axis, positive counter-clockwise from the old (Geo) X.
flag (bool) = 1 or 0 to indicate transform direction
Geo-->local (1) or
local-->Geo (0)
x_in (array) - Local (X) or Geo (E) coord depending on transform direction
y_in (array) = Local (Y) or Geo (N) coord depending on direction
Returns:
x_out (array) - Local (X) or Geo (E) coord depending on direction
y_out (array) - Local (Y) or Geo (N) coord depending on direction
Example:
#World to local
origin = [0, 0, 120]
Easting = 322825
Northing = 3076150
xLocal, yLocal = localTransformPoints(
origin,
1,
Easting,
Northing
)
initFullFileName(infile, label, type="avi", return_all=False) source
Function for conveniently creating an outfile name consistent with any
naming convention, given an infile name that contains the naming style
Args:
infile (string): name of input file
label (string): label associated naming convention
avi (string): file type
return_all (bool): if true, return outstr, name, and folder.
If false, just return outstr.
Returns: outstr (string): full formatted filepath name (string): filename folder (string): folder file lives in
Example:
infile = 'C:/Documents/examplepath/filename'
outfilepath,outfilename,folder = initFullFileName(infile, 'CIRN', return_all=True)
loadJson(jsonfile) source
Reads a .json file into a python dictionary.
Requires json package.
Args:
jsonfile (string): filepath to json file
Returns:
dictname (dict): Python dictionary created from json file
Example:
jsonfile = 'C:/Documents/example.json'
jsonDict = loadJson(jsonfile)
loadMatCIRN(files, tag="CIRN") source
Requires scipy.io package
This function reads and formats instrinsics from .mat files, in either
CIRN camera calibration format or CIRN intrinsics format
Args:
files: (string) file paths to .mat intrinsics file
tag: (string) 'CIRN' or 'CalTech', indicates format of .mat file
Note: if CIRN, extrinsics are likely included in .mat file
Returns:
m: array of lists, length is number of cameras, each list contains
intrinsics for the corresponding camera
ex: array of lists, length is number of cameras, each list contains
the extrinsics for the corresponding camera
Example:
matFile = 'C:/Documents/intrinsics.mat'
intrinsics,extrinsics = loadMatCIRN(matFile)
loadYamlDLT(file, cams) source
Requires yaml package
This function reads and formats extrinsics and instrinsics in DLT format
from .yaml files containing camera data from one or more pre-calibrated
cameras that are labeled with a camera ID
Args:
file: (string) .yaml file path that contains camera data
cams: (list of strings) camera labels used in .yaml file
Returns:
m: array of lists, length is number of cameras, each list contains
the DLT vector for the corresponding camera
ex: array of lists, length is number of cameras, each list contains
the extrinsics for the corresponding camera
Example:
#Location of our calibration data, stored in a .yaml file inside this repository
calibration_loc = ('ExampleData/cameraData.yml')
#Call a support function to format .yaml files into CIRN convention
m, ex = loadYamlDLT(calibration_loc,cams)
avgColor(img) source
Calculate the average pixel intensity of an image
Input:
img (ndarray) - np.ndarray representing image
img read as skimage.io.imread( 'imagefilename.jpg' )
Returns:
av (ndarray) - av (np.array of average r, g, b values),
avall (float) - average of r,g,b
Example:
avgRGBArr, overallAvg = avgColor(img)
estSharpness(img) source
Estimate image sharpness and contrast
Input:
img (ndarray) - np.ndarray representing image
img read as skimage.io.imread( 'imagefilename.jpg' )
Returns:
s,c (float) - sharpness and contrast estimates
https://stackoverflow.com/questions/6646371/detect-which-image-is-sharper
Example:
sharpness, contract = estSharpness(img)
Note: If utilizing CoastalImageLib, please cite our SoftwareX publication.