mxgmn/ConvChain — 773★ trên GitHub (C#). Bitmap generation from a single example with convolutions and MCMC
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
ConvChain is a Markov chain of images that converges to input-like images. That is, the distribution of NxN patterns in the outputs converges to the distribution of NxN patterns in the input as the process goes on.
In the examples a typical value of N is 3.
How to construct such a process? We want the final probability of a given pattern to be proportional to the pattern's weight, where pattern's weight is the number of such patterns in the input. For this it is sufficient that a stronger condition is satisfied: the probability of a given state (image) S should be proportional to the product of pattern weights over all patterns in S.
p(S) ~ product of pattern weights over all patterns in S
Fortunately, there are general methods to build a Markov chain that has the desired probability distribution over states as its stationary distribution.
Additional definitions:
For the ease of reasoning about the algorithm, it's convenient to introduce an energy function E, E(S) := - sum over all patterns P in S of log(weight(P)) so the probability distribution over states becomes p(S) ~ exp(-E(S)). Note that this energy function is a generalization of the Ising model energy. In the Ising model patterns are 1x2 instead of NxN.
To expand possible applications, it's convenient to introduce a temperature parameter T so the probability distribution over states becomes p(S) ~ exp(-E(S)/T). Low temperatures make the distribution more concentrated in energy wells, high temperatures make the distribution more uniform. If one uses ConvChain to generate dungeons, low temperatures correspond to accurate newly built dungeons while high temperatures correspond to ruins.
For the speed of convergence, it's convenient for weights of all patterns to be nonzero. So let's redefine the weight(P) of a pattern P to be the number of patterns P in the input if that number is more than zero and some small number eps otherwise, 0 < eps < 1.
Algorithm
Read the input image and count NxN patterns.
(optional) Augment pattern data with rotations and reflections.
Initialize the image (for example, with independent random values) in some state S0.
Repeat the Metropolis step:
Compute the energy E of the current state S.
Choose a random pixel and change its value. Let's call the resulting state S'.
Compute the energy E' of the state S'.
Compare E' to E. If E' < E assign the current state to be E'. Otherwise, assign the current state to be E' with probability exp(-(E'-E)/T).
If there are more than 2 colors, Gibbs sampling may converge faster than Metropolis:
Repeat the Gibbs step: change the current state S to a state S' according to the probability distribution p(S'|S) ~ exp(-E'/T).
Comments
ConvChain supports constraints, so you can easily combine it with other generators or handcrafted content.
In the language of WFC readme ConvChain satisfies strong condition 2 (Strong C2), but not condition 1 (C1).
If you freeze out the system as the Metropolis simulation goes on, you'll get a variant of the simulated annealing algorithm.
The detailed balance condition for ConvChain is exp(-E1/T)p(S2|S1) = exp(-E2/T)p(S1|S2), so both Gibbs p(S2|S1) ~ exp(-E2/T) and Metropolis p(S2|S1) = min(1, exp(-(E2-E1)/T)) chains converge to the desired distribution over states.
Related work
Stuart Geman and Donald Geman, Stochastic Relaxation, Gibbs Distributions, and the Bayesian Restoration of Images, 1984.
Kris Popat and Rosalind W. Picard, Novel cluster-based probability model for texture synthesis, classiffcation, and compression, 1993.
Rupert Paget and I. Dennis Longstaf, Texture Synthesis via a Non-parametric Markov Random Field, 1995.
Vivek Kwatra, Irfan Essa, Aaron Bobick and Nipun Kwatra, Texture Optimization for Example-based Synthesis, 2005.
How to build
ConvChain is a console application that depends only on the standard library. Get .NET Core for Windows, Linux or macOS and run
dotnet run --configuration Release ConvChain.csproj
ConvChain.cs contains the basic program, ConvChainFast.cs contains an equivalent faster program (~100 times faster on a 4-core CPU), but in a less human-readable form.
Notable ports, forks and spinoffs
Kevin Chapelier made an interactive vanilla JavaScript port of the faster version and a 1KB adaptation of it.
Amit Patel made a web port of the older slower version, with the main algorithm ported to TypeScript.
buckle2000 made a Processing (Java) port and a MoonScript port.
Kevin Chapelier adapted ConvChain to run on a GPU and made an interactive WebGL2 demo.
mxgmn/ConvChain thuộc nhóm Backend trên TopGit, cùng 8 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về mxgmn/ConvChain ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/mxgmn/ConvChain là nguồn chính thức.
mxgmn/ConvChain có bao nhiêu sao?
mxgmn/ConvChain có 773 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/mxgmn/ConvChain. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
mxgmn/ConvChain có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho mxgmn/ConvChain. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
mxgmn/ConvChain còn đang phát triển không?
Commit gần nhất trên mxgmn/ConvChain là 4.2 năm trước (theo timestamp GitHub). Repo có 46 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
mxgmn/ConvChain là gì?
mxgmn/ConvChain (mxgmn/ConvChain) là dự án C# trên GitHub. Theo mô tả gốc: Bitmap generation from a single example with convolutions and MCMC
mxgmn/ConvChain viết bằng ngôn ngữ gì?
mxgmn/ConvChain chủ yếu viết bằng C#. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc ConvChain có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về ConvChain.