Skip to content

tito21/st-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stylization of Photographs using Tractography

Original Image Stylized Image

Using the concepts from diffusion tensor imaging (DTI) and image processing, this project aims to stylize photographs in painterly style.

For details, read the preprint here.

Usage

Install uv and run:

uv run main.py INPUT_IMAGE OUTPUT_IMAGE [--params PARAMS_JSON] \
                                        [--orientation-vector {structural,gradient}] \
                                        [--rho RHO] [--sigma SIGMA] \
                                        [--method {grid,continuous}] \
                                        [--brush {simple,angle,img,line}] \
                                        [--brush-img BRUSH_IMG]

The optional PARAMS_JSON file can be used to specify parameters for the algorithm. It should be a JSON file with the following structure:

[
    { // First layer
         "sigma": 1.0,               // Standard deviation for Gaussian smoothing
         "num_lines": 10000,         // Maximum number of lines to draw in this layer
         "length_lines": 10000.0,    // Maximum length of lines in this layer
         "width": 2.0,               // Width of lines in this layer
         "min_length": 10.0,         // Minimum length of lines to draw
         "color_threshold": 50.0     // Minimum color difference to draw a line in grid mode or the minimum color
                                     // difference to continue drawing lines in continuous mode
    },
    { // Second layer
        ...
    },
    ...
]

The settings used in the preprint can be found in test-images/params.json.

The orientation-vector argument specifies how to compute the orientation. If structural it uses the primary eigenvector of the structure tensor (proposed improvement), if gradient it uses the image gradient (for reference). For the structural tensor you can also specify the rho and sigma parameters (default 1.0) which control the scale of the tensor computation.

Since the preprint support for different brush types has been added. You can choose between simple (default), angle, img, and line. The brush-img argument can be used to provide a custom brush image when using the img brush type.

The method argument specifies the rendering method to use. You can choose between grid (as described in the preprint) and continuous (default). The continuous method draws lines continuously until the color difference of the whole image is below the color_threshold parameter or a maximum number of lines specified by the num_lines parameter is reached.

Reproducibility

To reproduce the results in the preprint, run the following commands:

# Fig 1
uv run main.py test-images/cubain.jpg out_cubain.png --params test-images/params.json --orientation-vector structural

# Fig 3
uv run main.py test-images/picasso.jpg picasso_st.png --params test-images/params_st_vs_gt.json --orientation-vector structural
uv run main.py test-images/picasso.jpg picasso_gt.png --params test-images/params_st_vs_gt.json --orientation-vector gradient

# Stylization of all images in the test datasets (Figures 4-11)
source .venv/bin/activate  # MacOS/Linux
& .\.venv\Scripts\Activate.ps1  # Windows PowerShell
cd test-images
bash run_all.sh # MacOS/Linux
& run_all.ps1 # Windows PowerShell
bash make_montage.sh # MacOS/Linux (requires ImageMagick)

TODO

  • Use np.random.Generator for random numbers (and set seed for reproducibility)
  • Parallelize line drawing
  • Normalize parameters to be independent of image size
  • Add tests

Releases

No releases published

Packages

 
 
 

Contributors