Skip to content

A Python implementation of Graph-Cut algorithm for texture synthesis, accelerated with FFT.

Notifications You must be signed in to change notification settings

Suffoquer-fang/GraphCut

Repository files navigation

Graph Cut

A Python implementation of Graph-Cut algorithm for texture synthesis, accelerated with FFT.

Installation

Git clone this repo.

git clone https://github.com/suffoquer-fang/graphcut.git

Install the required packages.

pip install -r requirements.txt

Quick Start

To generate texture images, use patch_fitting method.

im_name = 'data/akeyboard_small.gif'
    
Gamma = 0.8
use_old_cut = True 
use_grad = False

im = Image.open(im_name).convert('RGB')
im_input = np.array(im, dtype=np.uint8)
h, w, _ = im_input.shape
height, width = 2 * h, 2 * w
im_src = np.zeros([height, width, _])
src_map = np.zeros([height, width]).astype(np.bool)
seam_map = SeamMap(height, width)

while not src_map.all():
    region_size = (h // 2, w // 2)
    error_region = get_error_region(im_src, src_map, seam_map, region_size)
    
    offset = get_offset_auto(im_src, src_map, im_input, error_region, region_size, Gamma)
    patch_fitting(im_src, src_map, im_input, offset, seam_map, use_old_cut, use_grad)

Image.fromarray(im_src.astype(np.uint8)).show()

Example Results

Different Offset Matching

Input texture --- Random Matching / Entire Matching / Subpatch Matching offset-matching

Old Seam

w/o old seam vs w/ old seam old-seam

Surrounded Region

before patching vs after patching surrounded

FFT Acceleration

Time Cost (s) Original FFT-based
Entire Matching 188.7 6.1
Subpatch Matching 62.3 4.2

About

A Python implementation of Graph-Cut algorithm for texture synthesis, accelerated with FFT.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages