Converts images to JFLAP files (.jff) or Verilog. Use JFLAP for equivalence checking between multiple diagrams.
*NOTE: Circle (i.e. state) detction accuracy is not super great. Any help will be appriciated. Algorithm for such described below.
- Install MiniConda3: https://conda.io/miniconda.html
- Install Python Libraries (in Anaconda Prompt):
- conda create --name=regular python=3.5
- conda activate regular
- conda install pip
- python -m pip install --upgrade pip
- conda install scipy scikit-image ipython
- conda install setuptools wheel
- pip install nnabla numpy matplotlib opencv-python tarjan
- conda install -c anaconda pywin32 #(This is for windows only)
- Clone Git Repo: git clone [this repo url]
- Using the programs:
- Make Verilog from image: python Image2V.py [input image file] # this has visual output
- Make JFLAP File (.jff) from image: python Image2JFLAP.py [input image file] # this has no visual output but outputs .jff file to ./Workspace/imgResult.jff
Sample Visual Output (Examples/epsilonEnds1.jpg)
RULES: leftmost node is the start state, accept states are double circles, transitions are 0, 1, or Epsilon
- State circles must be 10 to 40% of the smaller of the two sides of image (if landscape, then it is the height)
- All transitions represent one and only one value out of 0, 1, or epsilon
- For self-loops, the transition label should be written within the loop. For non-self-loops, the transition label should be written close to the destination.
- Transition line should not cross with another transition line
- No labels or letters within states.
- When having 2 lines in parallel, make sure they are not curved and reduce the distance between the two to prevent it from being detected as circle.
- For accept states (double circle), make sure the inner circle is clearly separated with good distance (10-20% of circle radius).
- Diagram should be written neatly and with thick strokes.
- Keep the number of nodes low (2-4) so that these do not form near-closed regions.
- Keep transition labels from touching transition lines.
NOTE: in the below chart, Synthesize Verilog is replaced with Synthesize JFLAP when running the Image2JFLAP program.
- Detect Circles: For each point at equal intervals in X,Y, go in 4 directions until you hit a black point. If these are symmetric and fit profiles of size and skew, then it is a circle.
- Detect Lines: Around each node, For each black point, trace such unit you hit a node. Form traces and transitions from such.
- Text Region Identification: OpenCV Implementation of MSER
- Machine Learning Text Classifcation: Sony NNABLA and Neural Network Console using Convolutional Neural Network (shown in ./MyLibrary/ImageUtils.py and ./MLParam/01E.h5).
- Join Lines: If 2 lines converge, join them.
- Transition and State: For each self loop, find label closed to it. For each remaining label, find transition endpoint closest to it.
- Synthesize Verilog, Epsilon-Reachable State Detection: Tarjan's Algorithm, Transitive closure