An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

Related tags

Image Processingvizh
Overview

vizh

An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

Overview

Here is an implementation of memcpy:

Implementation of memcpy in vizh

Yes, you literally pass an image file to the compiler.

The "parser" is based on computer vision and the backend produces C code.

Here's how the parser understands the program (produced if you pass --debug-parser when compiling):

Image decorated with the instructions that are recognised

Here's a C program which calls into the function:

#include <stdio.h>
// Supplied by linking with the vizh object file
void memcopy(uint8_t*,uint8_t*,uint8_t*);

int main() {
    uint8_t str[] = "Hello!";
    uint8_t size = sizeof(str);
    uint8_t to[sizeof(str)];

    memcopy(&size, str, to);
    puts(to);
}

We can compile this into an executable in a single command:

$ vizh memcopy.png main_memcopy.c -o memcopy

Then run it:

$ ./memcopy
Hello!

Errors

But what if you make an error, like this?

Version of the memcopy program with some instructions changed

Well you get the best compiler errors you'll ever see:

The errors highlighted and explained

Implementation

The provided implementation is called vizh and compiles to C and can link executables.

Installation

You can install vizh directly from PyPi:

$ pip install vizh

Dependencies

vizh depends on OpenCV, cffi, and Tesseract OCR.

You can install OpenCV and cffi with pip:

$ pip install opencv-python cffi

You'll have to install Tesseract OCR separately. See their documentation for instructions.

Usage

Usage: vizh [OPTIONS] [INPUTS]...

Options:
  --version               Show the version and exit.
  -c, --compile-only      Only compile, don't link.
  -o, --output-file PATH  Output file for executables or vizh object files.
  -q, --quiet             Suppress output.
  --debug-parser          Display how the parser understands your source file.
  --help                  Show this message and exit.

The compiler can take any combination of image files, C sources files, and object files.

You may need to set the TESSDATA_PREFIX environment variable to the folder containing Tesseract data. If you're on Linux this is likely /usr/share/tesseract-ocr//tessdata.

Language

Abstract Machine

The vizh abstract machine consists of:

  • Some number of tapes which are contiguous groups of 8-bit unsigned integers
  • A read/write head with storage for a single 8-bit unsigned integer

The initial state of the abstract machine is:

  • A single tape of size 4096 is allocated with all cells initialised to 0
  • The read/write head is initialised to the left-most cell of this tape

See instructions for the valid operations on the abstract machine.

Program

A vizh program consists of a number of functions, each in its own image file. (What image types are allowed? Ideally at least png and jpg)

The entry point to a vizh program is a function called main. (Note that the main function gets mangled as vizh_main. For all other functions the symbol name is the same as the vizh name).

Functions

A vizh function is an image file containing:

  • The name of the function at the top left of the image
  • The number of arguments (tapes) it takes at the top right of the image
  • A sequnce of instructions in a horizontal lines

Function names are alphanumeric: [a-zA-Z][a-zA-Z0-9]*.

The tapes available to a vizh function consist of its tape arguments. On entry to the function the r/w head is initialised to the start of the first tape argument, if any.

A function returns when control flow reaches the end of its instructions.

Any tapes allocated by a function are automatically deallocated when the function exits.

Function Calls

When you call a function subsequent pointer arguments are taken from the currently active tape onwards.

For example, given the following state of the abstract machine where ^ is the last position of the r/w head on that tape and $ is the active tape:

 t1 01234
     ^
$t2 99999
    ^
 t3 00000
    ^

Then a call to a function that takes two tapes would supply the arguments t2, t3.

Instructions

The valid instructions in vizh and their encodings are:

  • Left arrow: move the r/w head left
  • Right arrow: move the r/w head right
  • Up arrow: move the r/w head to the tape above the current one
  • Down arrow: move the r/w head to the tape below the current one
  • Function name in a circle: call the given function not yet implemented
  • +: increment the value pointed to by the r/w head by 1
  • -: decrement the value pointed to by the r/w head by 1
  • Equilateral triangle with the point at the top: read the cell pointed to by the r/w head into the r/w head storage
  • Equilateral triangle with the point at the bottom: write the value stored in r/w head storage into the cell pointed to by the r/w head
  • []: loop over the instructions between the brackets until the value pointed to by the r/w head at the start of the loop is 0

When you move the r/w head up or down, the position it was last at for the previous tape is saved. E.g. given this state of the abstract where ^ is the last position of the r/w head on that tape and $ is the active tape:

$t0 01234
    ^  
 t1 01234
    ^

The sequence of instructions "right right right down" would result in this state:

 t0 01234
       ^  
$t1 01234
    ^

Comments

Comments in vizh are anything enclosed in a rectangle. Stick what you want in there.

Standard Library

The vizh standard library is called libv. Much of it is implemented in vizh itself and it is built when you install vizh. It provides the following functions:

I/O

  • readin: read an ASCII character from stdin and write its integral representation into the cell pointed to by the r/w head
  • print: print the value of the cell pointed to by the r/w head to stout, interpreted as an ASCII character
  • putstr: write the null-terminated ASCII string starting at the position pointed to by the r/w head to stdout.

Strings

  • geta: puts the character a at the current position of the r/w head.
  • getA: puts the character A at the current position of the r/w head.

Arithmetic

  • add given tape cells a,b from the r/w head, results in a+b,0.
  • mul given tape cells a,b,c from the r/w head, results in a*b,0,0.
  • zero given tape cell a from the r/w head, results in 0

Memory

  • newtape: allocate a new secondary tape underneath the last one currently allocated for this function (or the primary tape if there are no secondary tapes)
  • freetape: deallocate the bottom-most secondary tape for this function (no-op if there are not any)
Owner
Sy Brand
@TartanLlama
Sy Brand
Docbarcodes extracts 1D and 2D barcodes from scanned PDF documents or images. It can be used to automate extraction and processing of all kind of documents.

Intro Barcodes are being used in many documents or forms to enable machine reading capabilities and reduce manual processing effort. Simple 1D barcode

Arlind Nocaj 3 Jun 18, 2022
Javascript image annotation tool based on image segmentation.

JS Segment Annotator Javascript image annotation tool based on image segmentation. Label image regions with mouse. Written in vanilla Javascript, with

Kota Yamaguchi 513 Nov 15, 2022
Scramb.py is a region based JPEG Image Scrambler and Descrambler written in Python

Scramb.py Scramb.py is a region based JPEG Image Scrambler and Descrambler written in Python. Main features Scramb.py can scramble images regions. So

47 Dec 25, 2022
An API which would colorize a black and white image

Image Colorization API Machine Learning Model used- https://github.com/richzhang/colorization/tree/caffe Paper - https://arxiv.org/abs/1603.08511 Step

Neelesh Ranjan Jha 4 Nov 23, 2021
LSB Image Steganography Using Python

Steganography is the science that involves communicating secret data in an appropriate multimedia carrier, e.g., image, audio, and video files

Mahmut Can Gönül 2 Nov 04, 2021
An python script to convert images to upscaled versions made out of one-colour emojis.

ABOUT This is an python script to convert png, jpg and gif(output isnt animated :( ) images to scaled versions made out of one-colour emojis. Please n

0 Oct 19, 2022
Collection of SVG diagrams about how UTF-8 works

Diagrams Repository of diagrams made for articles on my blog. All diagrams are created using diagrams.net. UTF-8 Licenses Copyright 2022 Seth Michael

Seth Michael Larson 24 Aug 13, 2022
Django helper application to easily and non-destructively crop arbitrarily large images in admin and frontend.

django-image-cropping django-image-cropping is an app for cropping uploaded images via Django's admin backend using Jcrop. Screenshot: django-image-cr

Jonas und der Wolf GmbH 546 Jan 03, 2023
Fast Image Retrieval is an open source image retrieval framework

Fast Image Retrieval is an open source image retrieval framework release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This framework implements most of the major binar

CISiP Lab 39 Nov 25, 2022
Short piece of code to create a rainbow gif of gradual contours from two shapefiles

rainbow-elevation-gif Short piece of code to create a rainbow gif of gradual con

Jess Roberts 6 Jan 17, 2022
Converting Images Into Minecraft Houses

Converting Images Into Minecraft Houses In this particular project, we turned a 2D Image into Minecraft pixel art and then scaled it in 3D such that i

Mathias Oliver Valdbjørn Jørgensen 1 Feb 02, 2022
Deep Illuminator is a data augmentation tool designed for image relighting.

Deep Illuminator Deep Illuminator is a data augmentation tool designed for image relighting. It can be used to easily and efficiently genera

George Chogovadze 52 Nov 29, 2022
This is a python project which detects color of an image when you double click on it.

This is a python project which detects color of an image when you double click on it. You have to press ESC button to close the pop-up Image window. There are mainly two library CV2 and Pandas that a

Yashwant Kumar Singh 0 Aug 16, 2022
粉專/IG圖文加工器

粉專/IG圖文加工器 介紹 給PS智障(ex:我)使用,用於產生圖文 腳本省去每次重複步驟 可載入圖片(方形,請先處理過,歡迎PR) 圖片簡易套用濾鏡 可將圖片切片 要求 Python 版本 3.9 安裝 安裝最新 python pip3 install -r requirement.txt 效果

Louis Tang 7 Aug 10, 2022
QR-Generator - An awesome QR Generator to create or customize your QR's

QR Generator An awesome QR Generator to create or customize your QR's! Table of

Tristán 1 Jan 28, 2022
A linear stairs generation add-on for Blender

Linear Stairs Generator Table of Contents Installation Usage Screenshots Important Notes Requirements Blender 3.0 or newer. Installation: Download a z

Elhanan Flesch 4 May 17, 2022
Python pygame project that turns your images to matrix rain

Matrix-Rain-An-Image This project implements the classic Matrix digital rain effect in python with pygame to build up an image provided with multiple

7 Dec 11, 2022
Group of interfaces interesting for users

Project: Interface to create GIF animation based on Fourier Series.

5 Aug 17, 2021
Glyph-graph - A simple, yet versatile, package for graphing equations on a 2-dimensional text canvas

Glyth Graph Revision for 0.01 A simple, yet versatile, package for graphing equations on a 2-dimensional text canvas List of contents: Brief Introduct

Ivan 2 Oct 21, 2022
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

53 Nov 15, 2022