The human eye perceives planar shapes using both local and global features of the shape. However, the extent to which the local features contribute to perception is currently unclear. To advance research in this area, we employ a methodology that captures the local curvature properties of shape contours within a given dataset of natural shapes and aims to generate closed, non-intersecting contours that accurately replicate the naturalistic shapes in terms of their expected local curvature properties. This study uses a Markov Chain Monte Carlo (MCMC) method that develops five different generative models based on combinations of statistics drawn from these local features. These models provide a valuable tool for studying and analyzing shape perception, offering insights into how the human eye perceives shapes. Furthermore, these generated shapes can serve as stimuli to evaluate computational models for object perception, in addition to behavioral and neuropsychological experiments. Overall, this study contributes to the field of visual perception by introducing a methodology that allows for a detailed examination of the relationship between local and global cues in visual processing of shapes, paving the way for further investigations in the domain of visual cognition.
Code was written in Python 3.11.4. The mcont package contains the core logic of shape
deformation and sampling statistics. Shape generation related scripts are located in
shape_generation folder. The mcmc.py script in the root folder is the main entry
point for users, it provides a CLI tools to embed, train and generate new sets of shapes.
I recommend you use either anaconda or miniconda to run this project. Follow these
instructions to install
miniconda on your machine. Once installed, use the anaconda prompt shell to cd into the project's
root directory. Run the command conda create --name mcmc-env --file environment.yml to create
a new conda environment with all the requirements installed. Run conda activate mcmc-env.
If you are using some other package manager other than conda you may have to manually install the following dependencies.
- Python 3.11
- NumPy
- SciPy
- H5PY
- Pillow
- OpenCV Python
- Shapely
Since data will be stored in an HDF5 file, I would recommend you install HDFView on your machine so that you can inspect the contents of the file from a GUI.
I added jupyter notebook (*.ipynb) files to .gitignore
because version control for notebooks is messy... So
notebooks will not be pushed to the GitHub repository.
To see the usage of mcmc.py run the command python mcmc.py --help
Before we get to generating interesting constrained shapes, we first need to train our model. In order to train our model we first need a few shapes that are generated without any constraints. These "unconstrained" shapes can be generated using the following command.
python mcmc.py -u --nedges 120 --data data/shape_data.hdf5 --num-chains 10 --samples-per-chain 200 --thinning 20 --burn-in 500 --step 0.1
Here the nedges argument defines the number of equilateral edges in our shape. The data argument
is a path to a HDF5 file where the generated shapes will be saved. The num-chains argument along
with samples-per-chain determine how many shapes will be generated in total, here we are using 10
MCMC chains, each generates 200 shapes for a total of 2000. Use the help command to read about the other
arguments.
The following is an illustration of how an initial shape can be iteratively deformed to generate new shapes while preserving the edge lengths of the initial shape.
Now we need to convert our target set of images into digitized equilateral contours. This can be done
using the -e flag. An example command could be.
python mcmc.py -e --image-dir data/contours/animals --nedges 120 --data data/shape_data.hdf5 --shape-class animals --k-iter 8
the image-dir argument specifies the folder in which target set of images are located. Note,
the images need to have transparent background/alpha channel in either .png or .gif format.
This may take a while depending on the number of images and k.
With that done, we can now train one of the pre-defined models. Use the help command to see a list
of all the available models. The following example trains the varonly model which constrains the turning
angle variance of generated contours to match those from the target contours.
python mcmc.py -t --nedges 120 --data data/shape_data.hdf5 --shape-class animals --model-name varonly --num-chains 10 --samples-per-chain 200 --thinning 20 --burn-in 500 --step 0.1
To train other models, replace the --model-name argument with the desired model name.
Once the model is trained we can use it to generate shapes with the following command.
python mcmc.py -g --nedges 120 --data data/shape_data.hdf5 --shape-class animals --model-name varonly --num-chains 10 --samples-per-chain 200 --thinning 20 --burn-in 500 --step 0.1








