|
IVALab Python Libraries
Collection of code for computer vision and robotics with specific API.
|
Instance of Matrix that can also generate defective puzzles by introducing erroenous puzzle pieces based on the configuration parameters and random sampling. More...


Public Member Functions | |
| def | __init__ (self, theBoard=[], imSource=[], theParams=CfgMatrix) |
| Constructor. More... | |
| def | annotateDetectionsWithCircles (self, theImage, piCoords, blockOutGrid) |
| Uses trial settings to generate robot detection annotation on image. More... | |
| def | annotatePuzzleImage (self, theImage, spCoords, fpCoords) |
| Given bad piece and false positive locations, mark them in image. More... | |
| def | applyCorruptionToPiecesByMatrix (self, pgCoords) |
| Uses trial settings to generate corruption vectors for pieces. More... | |
| def | applyDetectionToPuzzleImage (self, theImage, pgCoords, blockOutGrid) |
| Apply detection process to system, if robot specified to exist. More... | |
| def | buildFrom_ImageAndRegions (theImage, theRegions, theParams=CfgMatrix()) |
| def | corruptPieces (self, pcInds, pcErrs) |
| Corrupt the pieces indicated according to specified defect vector. More... | |
| def | corruptPiecesByCoords (self, pcCoords, pcErrs) |
| Corrupt pieces at specified coordinates according to specified defect vector. More... | |
| def | reset (self) |
| Reset puzzle to the original version. More... | |
| def | samplePieces (self, nSamp, doBlockOut=True, blockOutMat=None) |
| Sample a small set of pieces based on block-out (or not). More... | |
Public Member Functions inherited from Matrix | |
| def | __init__ (self, theBoard=[], theParams=CfgMatrix) |
| Constructor for the puzzle.builder.adjacent class. More... | |
| def | coord2ind (self, theCoords) |
| Uses puzzle shape to convert puzzle piece coordinate to linear index/key. More... | |
| def | explodedPuzzle (self, dx=100, dy=50, bgColor=(0, 0, 0)) |
| Create an exploded version of the puzzle. More... | |
| def | getCoordinates (self) |
| Obtain solution board coordinates for the pieces. More... | |
| def | retile (self, dx=150, dy=150, inOrder=True) |
| Organize puzzle pieces according to gridding. More... | |
| def | shuffle (self, numPieces=None, reorient=False) |
| Randomly shuffle location of puzzle pieces of the puzzle. More... | |
| def | sub2ind (self, theSubs) |
| Uses puzzle shape to convert puzzle piece subscripts to linear index/key. More... | |
| def | swap (self, theswap=None, reorient=False) |
| Randomly shuffle location of puzzle pieces of the puzzle. More... | |
| def | swapByCoords (self, swapCoords) |
| Specify puzzle piece coordinates that should be swapped. More... | |
Public Member Functions inherited from Adjacent | |
| def | processAdjacency (self) |
| Process the solution board and determine what pieces are adjacent or "close enough." It will determine the adjacency matrix. More... | |
Public Member Functions inherited from Arrangement | |
| def | corrections (self, pLoc) |
| Given an array of locations that correspond to the puzzle board (e.g., in the same order as puzzle board list), provide the correction vector that would move them to the calibrated locations. More... | |
| def | distances (self, pLoc) |
| Given an array of locations that correspond to the puzzle board (e.g., in same order as puzzle board list), provide the distances between the locations and the calibrated locations. More... | |
| def | piecesInPlace (self, pLoc, tauDist=None) |
| Return boolean array indicating whether the piece is correctly in place or not. More... | |
| def | scoreBoard (self, theBoard) |
| Given a puzzle board with in ordered correspondence with the calibrated puzzle board, in the same order as puzzle board list), provide a score for the distance between the puzzle piece locations and the calibrated locations. More... | |
| def | scoreByLocation (self, pLoc) |
| Given an array of locations that correspond to the puzzle board (e.g., in same order as puzzle board list), provide a score for the distance between the locations and the calibrated locations. More... | |
Public Member Functions inherited from Board | |
| def | __init__ (self, *argv) |
| Constructor for puzzle board. More... | |
| def | addPiece (self, piece, ORIGINAL_ID=False) |
| Add puzzle piece instance to the board. More... | |
| def | addPieceFromMaskAndImage (self, theImage, theMask, centroidLoc=None, cLoc=None) |
| Given a mask and an image of same base dimensions, use to instantiate a puzzle piece template. More... | |
| def | addPieces (self, pieces) |
| Add puzzle piece to board. More... | |
| def | boundingBox (self) |
| Iterate through pieces to get tight bounding box. More... | |
| def | clear (self) |
| def | display_cv (self, theImage=None, fh=None, ID_DISPLAY=False, CONTOUR_DISPLAY=False, BOUNDING_BOX=False, window_name='Puzzle') |
| Display the puzzle board as an image using matplot library. More... | |
| def | display_mp (self, theImage=None, ax=None, fh=None, ID_DISPLAY=False, CONTOUR_DISPLAY=False, BOUNDING_BOX=True) |
| Display the puzzle board as an image using matplot library. More... | |
| def | display_mp_expanded (self, theImage=None, ax=None, fh=None, ID_DISPLAY=False, CONTOUR_DISPLAY=False, BOUNDING_BOX=False) |
| Display the puzzle board as an image using matplot library. More... | |
| def | extents (self) |
| Iterate through puzzle pieces to get tight bounding box extents of the board. More... | |
| def | fromImageAndLabels (self, theImage, theLabels) |
| Template | getPiece (self, id) |
| Get puzzle piece instance based on id. More... | |
| def | markMissing (self, indSetMeasured) |
| Given set of indices to measured pieces, mark remaining as unmeasured. More... | |
| def | offset (self, dr) |
| Offset the location of the entire puzzle in the board. More... | |
| def | pieceLocations (self, isCenter=False) |
| Returns list/array of puzzle piece locations. More... | |
| def | relabel (self, newLabels, idContinue) |
| Relabel the puzzle piece IDs in the board using new label reassignments and adjust IDs for those without reassignment. More... | |
| def | rmPiece (self, id) |
| def | size (self) |
| Number of pieces on the board. More... | |
| def | testAdjacent (self, id_A, id_B, tauAdj) |
| Check if two puzzle pieces are adjacent or not. More... | |
| def | toImage (self, theImage=None, ID_DISPLAY=False, COLOR=(0, 0, 0), ID_COLOR=(255, 255, 255), CONTOUR_DISPLAY=True, BOUNDING_BOX=True) |
| Uses puzzle piece locations to create an image for visualizing them. More... | |
| def | toImageAndSegmentation (self, theImage=None, ID_DISPLAY=False, COLOR=(0, 0, 0), ID_COLOR=(255, 255, 255), CONTOUR_DISPLAY=False, BOUNDING_BOX=False) |
| Render the board image together with an ID-labelled segmentation image. More... | |
| def | toImageExpanded (self, theImage=None, ID_DISPLAY=False, COLOR=(0, 0, 0), ID_COLOR=(255, 255, 255), CONTOUR_DISPLAY=True, BOUNDING_BOX=False) |
| Uses puzzle piece locations to create an image for visualizing them. More... | |
Static Public Member Functions | |
| def | buildFrom_ImageAndMask (theImage, theMask, theParams=CfgMatrix(), show_grid=False) |
| Given an image and an image mask, parse both to recover the puzzle calibration/solution. More... | |
| def | buildFrom_ImageAndSpecs (theImage, theParams) |
| Given a fully specific Matrix puzzle and an image, instantiate a MatrixDefect puzzle. More... | |
| def | buildFrom_ImageProcessing (theImage, theProcessor=None, theDetector=None, theParams=None) |
| def | buildFrom_Sketch (theImage, theMask, theProcessor=None, theDetector=None, theParams=None) |
| def | buildFromFile_ImageAndMask (fileName, theParams=None) |
| Load a saved arrangement calibration/solution stored as an image and a mask. More... | |
| def | buildFromFile_Puzzle (fileName, theParams=None) |
| Load a saved arrangement calibration/solution puzzle board. More... | |
| def | buildFromFiles_ImageAndMask (imFile, maskFile, theParams=None) |
| Load a saved arrangement calibration/solution stored as separate image and mask files. More... | |
| def | generateStudy (theTrials, theSettings, theImage, filePre) |
| Generate all of the images associated to a study. More... | |
| def | generateTrainingImages (theTrials, theSettings, theImage, filePre) |
| Generate all of the images associated to a study. More... | |
| def | generateTrainingImages_Pilot01 (puzzleImage, theSettings, filePre, randSeed=3454564) |
| Generate trial matrix associated to training trials across all conditions and trial classes. More... | |
| def | generateTrial (trialInfo, trialStgs, theImage, filePrefix) |
Static Public Member Functions inherited from Adjacent | |
| def | buildFrom_ImageAndMask (theImage, theMask, theParams=None) |
| Given an image and an image mask, process both to recover and instantiate a puzzle calibration/solution. More... | |
Public Attributes | |
| conditions | |
| image | |
| original | |
| pieces | |
Public Attributes inherited from Matrix | |
| gc | |
Public Attributes inherited from Adjacent | |
| adjMat | |
Public Attributes inherited from Arrangement | |
| params | |
Public Attributes inherited from Board | |
| id_count | |
| pieces | |
Static Public Attributes | |
| tuple | cent |
| dx = self.xcoords[1]-self.xcoords[0] | |
| dy = self.ycoords[1]-self.ycoords[0] | |
| int | li = li+1 |
| markImage = cv2.circle(markImage, cent, r, (0, 0, 0) , 2) | |
| modPiece = self.pieces[inds] | |
| list | piShift = []; |
| r = self.params.rho * np.linalg.norm(np.array([ self.xcoords[-1], self.ycoords[-1] ])) | |
| tuple | r = (self.params.rhoDetect * rad).astype('int') |
| int | rad = np.linalg.norm(np.array([dx, dy]))/2 |
| selCoord = sc[selInd,:] | |
| int | selInd = random.randint(1,sc.shape[0])-1 |
| list | shiftVec = [] |
| int | theta = 2 * math.pi * random.random() |
| int | ti = ti+1 |
| list | xtake = [selCoord[0]-self.params.blockOut, 1+selCoord[0]+self.params.blockOut] |
| list | ytake = [selCoord[1]-self.params.blockOut, 1+selCoord[1]+self.params.blockOut] |
Static Public Attributes inherited from Matrix | |
| colTarg = int((imcols*theParams.isize[0])/imrows) | |
| dc = int(imsize[1] / theParams.psize[0]) | |
| dr = int(imsize[0] / theParams.psize[1]) | |
| imcols = imsize[0] | |
| imFact = theParams.isize[0] / imcols | |
| imRatio = imcols / imrows | |
| imrows = imsize[1] | |
| imsize = theImage.shape | |
| isize | |
| order | |
| partition_num | |
| rowTarg = int((imrows*theParams.isize[1])/imcols) | |
| shape | |
| theImage = cv2.resize(theImage, None, fx=imFact, fy=imFact) | |
| theMask = np.ones([imrows, imcols]) | |
| thePuzzle = Matrix.buildFrom_ImageAndMask(theImage, theMask, theParams) | |
| ticols = dc * theParams.psize[0] | |
| tirows = dr * theParams.psize[1] | |
| x_labels | |
| x_list | |
| x_parts | |
| xcoords | |
| y_labels | |
| y_list | |
| y_parts | |
| ycoords | |
Instance of Matrix that can also generate defective puzzles by introducing erroenous puzzle pieces based on the configuration parameters and random sampling.
Provides an API to the Matrix puzzle for creating faulty or defective puzzles.
| def __init__ | ( | self, | |
theBoard = [], |
|||
imSource = [], |
|||
theParams = CfgMatrix |
|||
| ) |
Constructor.
| [in] | theBoard | Input board instance that serves as the non-defective board. |
| [in] | imSource | The source image for generating defects with. |
| [in] | theParams | Matrix puzzle configuration instance. |
| def annotateDetectionsWithCircles | ( | self, | |
| theImage, | |||
| piCoords, | |||
| blockOutGrid | |||
| ) |
Uses trial settings to generate robot detection annotation on image.
Applies any annotation configuration specifications.
applyDetectionToPuzzleImage member function does it all.| [in] | theImage | The image to annotate. |
| [in] | pcCoords | The puzzle piece image coordinates to annotate. |
| def annotatePuzzleImage | ( | self, | |
| theImage, | |||
| spCoords, | |||
| fpCoords | |||
| ) |
Given bad piece and false positive locations, mark them in image.
The purpose is to provide a quality control human with the true quality control state of the puzzle board. Presumably for training purposes; to learn how to differentiate pieces.
| def applyCorruptionToPiecesByMatrix | ( | self, | |
| pgCoords | |||
| ) |
Uses trial settings to generate corruption vectors for pieces.
Applies the corruption.
| [in] | pgCoords | Puzzle pieces to corrupt in (x,y) matrix grid coordinates. |
| def applyDetectionToPuzzleImage | ( | self, | |
| theImage, | |||
| pgCoords, | |||
| blockOutGrid | |||
| ) |
Apply detection process to system, if robot specified to exist.
| [in] | theImage | Image to annotate with detections (if at all). |
| [in] | pgCoords | Puzzle grid coordinates (ground truth). |
| [in] | blockOutGrid | False positive block-out grid. |
| [out] | theImage | Annotated image. |
| [out] | fpc | False positive (matrix) coordinate. |
| [ou] | wasDetected Boolean array indicating if defect was detected or not. |
|
static |
Given an image and an image mask, parse both to recover the puzzle calibration/solution.
Instantiates a puzzle parser that gets applied to the submitted data to create a puzzle board instance. That instance is the calibration/solution.
| [in] | theImage | Puzzle image data. |
| [in] | theMask | Puzzle mask data. |
| [in] | theParams | Matrix configuration instance. |
Reimplemented from Matrix.
| def buildFrom_ImageAndRegions | ( | theImage, | |
| theRegions, | |||
theParams = CfgMatrix() |
|||
| ) |
Reimplemented from Matrix.
|
static |
Given a fully specific Matrix puzzle and an image, instantiate a MatrixDefect puzzle.
The image and the puzzle specification need not agree. The image will be reshaped to the nearest possible size compatible with the Matrix specifications. It may be that the puzzle sizing has to change to match that aspect ratio of the original image, or the image has to be cropped. This routine tries to minimize how much the specifications are adjusted to make a puzzle from the source image.
What is important about the puzzle specification is that the number of columns and rows (width and height) of the puzzle matrix should be given. The target image size should be given too. If not, then the source image will be used for the initial target image size, which may be adjusted or cropped for compatiblity with the puzzle sizing.
| [in] | theImage | The source image. |
| [in] | theParams | The Matrix puzzle configuration (should be complete). |
Reimplemented from Matrix.
|
static |
@todo NOT UPDATED!!!!
@brief Given an image with regions clearly separated by some color or threshold,
parse it to recover the puzzle calibration/solution. Can source alternative
detector.
Instantiates a puzzle parser that gets applied to the submitted data to create a
puzzle board instance. That instance is the calibration/solution.
@param[in] theImage: The puzzle image data.
@param[in] theProcessor: The processing scheme.
@param[in] theDetector: The detector scheme.
@param[in] theParams Matrix configuration instance.
@return thePuzzle Matrix puzzle board instance.
Reimplemented from Matrix.
|
static |
@todo NOT UPDATED!!!!
@brief Given an image with regions clearly separated by some color or threshold,
parse it to recover the puzzle calibration/solution. Can source alternative
detector.
Instantiates a puzzle parser that gets applied to the submitted data to create a
puzzle board instance. That instance is the calibration/solution.
@param[in] theImage: Puzzle image data.
@param[in] theMask: Puzzle mask data.
@param[in] theProcessor Processing scheme.
@param[in] theDetector Detector scheme.
@param[in] theParams Matrix configuration instance.
@return thePuzzle Matrix puzzle board instance.
Reimplemented from Matrix.
|
static |
Load a saved arrangement calibration/solution stored as an image and a mask.
The python file contains the puzzle board mask and image source data. It gets processed into an arrangement instance. If a threshold variable tauDist is found, then it is applied to the arrangement instance.
| [in] | fileName | Python file to load. |
| [in] | theParams | Matrix configuration instance. |
Reimplemented from Matrix.
|
static |
|
static |
Load a saved arrangement calibration/solution stored as separate image and mask files.
The source file contain the puzzle board image and mask data. It gets processed into an arrangement instance. If a threshold variable tauDist is found, then it is applied to the arrangement instance.
| [in] | imFile | Image file to load. |
| [in] | maskFile | Mask file to load. |
| [in] | theParams | Matrix configuration instance. |
Reimplemented from Matrix.
| def corruptPieces | ( | self, | |
| pcInds, | |||
| pcErrs | |||
| ) |
Corrupt the pieces indicated according to specified defect vector.
| [in] | pcInd | Index to puzzle piece(s) to corrupt. |
| [in] | pcErrs | Vectors Parameter specifications for corruption process. |
| def corruptPiecesByCoords | ( | self, | |
| pcCoords, | |||
| pcErrs | |||
| ) |
Corrupt pieces at specified coordinates according to specified defect vector.
Autocorrects vector at boundaries.
| [in] | pcCoords | Coordinates to puzzle pieces to corrupt. (x,y) coords. |
| [in] | pcErrs | Vector shifts to apply for new puzzle patch images. (x,y) coords. |
|
static |
Generate all of the images associated to a study.
| [in] | theTrials | List of trial conditions. |
| [in] | theSettings | Study settings. |
| [in] | reps | No. of replicates (whole number) |
| [in] | filePre | Prefix of saved files. |
|
static |
Generate all of the images associated to a study.
| [in] | theTrials | List of trial conditions. |
| [in] | theSettings | Study settings. |
| [in] | reps | No. of replicates (whole number) |
| [in] | filePre | Prefix of saved files. |
|
static |
Generate trial matrix associated to training trials across all conditions and trial classes.
This particular pilot isolates certain conditions to a subject. Those are puzzle size and robot assistance, which are held constant for a subject. Meanwhile number of errors and magnitude of error vary.
|
static |
| def reset | ( | self | ) |
Reset puzzle to the original version.
| def samplePieces | ( | self, | |
| nSamp, | |||
doBlockOut = True, |
|||
blockOutMat = None |
|||
| ) |
Sample a small set of pieces based on block-out (or not).
Randomly pick a small set of puzzle pieces from all possible puzzle pieces. Selection is without replacement and incorporate a block-out radius from the configuration parameters unless it is specified to be ignored.
| [in] | nSamp | Number of puzzle piece samples to return. |
| [in] | blockOut | Optional binary flag to disable blockOut [def: True] |
|
static |
| conditions |
|
static |
|
static |
| image |
|
static |
|
static |
| original |
| pieces |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |