labelmeEdits.py - byuawsfhtl/RLL_computer_vision GitHub Wiki

Overview

This provides a collection of functions for editing labelme json files (which in turn changes the labels). This was primarily created to have a model output predictions to labelme, run post processing (with some human intervention) and use this data to further train the model. This also allows automation of actions within labelme.

Most functions return a dictionary. This is (commonly) a json object for the entire file. This can then be dumped to a file (with saveFile).

Model to LabelMe (supercomputer)

This script is an example of the process. The only change from normal segmentation is instead of cropping an image, the left/right/top/bottom values are used to create a polygon and this is saved in the LabelMe json format.

General functions

loadFile(fileName:str, workingDir:str) -> dict:

Move into the directory and return the json for the provided file.

example: loadFile('record_image_vol_88_num_5.json', r'V:\FHSS-JoePriceResearch\papers\current\colorado_land_patents\data\tract books\row from full training')


loadFile(fileName:str) -> dict:

Don't move into the directory, but the same as above.


saveFile(fileName:str, data):

Dumps the data (json parsable) into fileName.

example: saveFile(jsonName, orderFile(loadFile(jsonName)))


Functions that create shapes

addShapes(jsonName:str, workingDir:str = r'V:\FHSS-JoePriceResearch\papers\current\colorado_land_patents\data\tract books\row from full training'):

Interpolates between shapes; if a user annotated every other, this fills in the missing shapes.

example: addShapes('record_image_vol_88_num_5.json', r'V:\FHSS-JoePriceResearch\papers\current\colorado_land_patents\data\tract books\row from full training')


Functions that analyze shapes

checkShapes(workingDir:str = r'V:\FHSS-JoePriceResearch\papers\current\colorado_land_patents\data\tract books\row from full training'):

Moves thru the folder and outputs image names with bad polygons. A polygon is bad if there are not exactly 4 points.

example: checkShapes(r'V:\FHSS-JoePriceResearch\papers\current\colorado_land_patents\data\tract books\row from full training')


Functions that edit shapes

rectToPoly(j:dict) -> dict:

Changes rectangles (model output) to polygons (easier to adjust for training).

example: rectToPoly(loadFile('record_image_vol_88_num_5.json'))


orderFile(j:dict) -> dict:

Sorts the shapes from top to bottom, left page then right page.

example: orderFile(loadFile('record_image_vol_88_num_5.json'))


smooth(j:dict, smoothFactor:float = 1.00) -> dict:

Moves the right/left sides for each box towards to average for that page. Assumes sorted polygons. Ensures leftmost and rightmost lines are sort of lined up.

example: smooth(loadFile('record_image_vol_88_num_5.json'), 0.75)