MATLAB exercise program (texture synthesis)

Source: Internet
Author: User

The most classic paper on texture synthesis should be about Texture Synthesis by non-parametric sampling of Efros. the reference amount is nearly 2000.

The synthesis here is based on the example, that is, there is a small texture image first, and then a large one is synthesized.

In my personal understanding, a large random image is generated first, and then each pixel in the random image and its neighboring pixels are compared with small texture images, find the nearest neighbor between the current neighbor of a random image and a small texture image, and assign the nearest pixel to a large random image. In this way, each time we process the pixels in a random image, we need to traverse all the pixels in a small texture image, so the running time is very slow.

First look at the effect:

Small texture image:

Synthetic texture image:

The Matlab code is as follows:

Clear all; close all;clc?mask=mat2gray(imread('wen.jpg '); % small texture image [m n] = size (mask); imgn = mat2gray (RAND (256,256 )); % The final large texture image is now a random image W = 2; % L radius I = [1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1; 1 1 0 0 0]; % L neighborhood, here is 5*3, of course, it can also be 7*4 or 9*5 for I = 1 + W: 256 for j = 1 + W: 256-w MI = inf; for p = 1 + W: m for q = 1 + W: n-w tmp = mean2 (ABS (imgn (I-W: I, j-W: J + W ). * I-Mask (p-W: p, q-W: q + W ). * I); If TMP <mi %, obtain the smallest difference pixel MI = TMP; II = P; JJ = Q; end imgn (I, j) = mask (II, JJ); endendfigure; imshow (imgn, []);

Reference blog: http://blog.sina.com.cn/s/blog_50a6faf801009fry.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.