The paint on the walls in my room has a random, almost fractal-like, 3-dimensional texture:

In this challenge you will write a program that generates random images that look like they could be part of my walls.

Below I've collected 10 images of different spots on my walls. All have roughly the same lighting and all were taken with the camera one foot away from the wall. The borders were evenly cropped to make them 2048 by 2048 pixels, then they were scaled to 512 by 512. The image above is image A.

These are only thumbnails, click images to view at full size!

A:B:C:D:E:

F:G:H:I:J:

Your task is to write a program that takes in a positive integer from 1 to 216 as a random seed, and for each value generates a distinct image that looks like it could have been the "eleventh image" of my wall. If someone looking at my 10 images and a few of yours can't tell which were computer generated then you've done very well!

Please show off a few of your generated images so viewers can see them without having to run the code.

I realize that the lighting in my images is not perfectly uniform in intensity or color. I'm sorry for this but it's the best I could do without better lighting equipment. Your images do not need to have variable lighting (though they could). The texture is the more important thing to focus on.

Details

You may use image processing tools and libraries.

Take the input in any common way you desire (command line, stdin, obvious variable, etc).

The output image can be in any common lossless image file format, or it can just be displayed in a window/bowser.

You may programmatically analyze my 10 images but don't assume that everyone running your code has access to them.

You must generate the images programmatically. You may not hard-code a slight variant of one of my images or some other stock image. (People would vote you down for this anyway.)

You may use built-in pseudorandom number generators and assume the period is 216 or more.

\$\begingroup\$I can't make wall images, so instead have a comic!\$\endgroup\$
– Sp3000Jan 7 '15 at 7:42

8

\$\begingroup\$@Sp3000 That's more or less how it happened. Though If I has been looking up I'd have probably chosen my ceiling, which could work as well...\$\endgroup\$
– Calvin's HobbiesJan 7 '15 at 8:07

3 Answers
3

GLSL (+ JavaScript + WebGL)

How to use

Reload the page for a new random image. If you want to feed in a particular seed, open your browser's console and call drawScreen(seed). The console should display the seed used on load.

I haven't really tested this on a lot of platforms, so let me know if it doesn't work for you. Of course, your browser needs to support WebGL. Errors are displayed either in the column on the left, or in the browser's console (depending on the type of error).

New: You can now bring the walls to life a bit, by ticking the "movable light source" checkbox.

What is this sorcery?

I've got this WebGL boilerplate code floating around my GitHub account, which I use every now and then to quickly prototype some 2D graphics things in WebGL. With some shader magic, we can also make it look slightly 3D, so I thought that was the quickest way to get some nice effects going. Most of the setup is from that boilerplate code, and I'm considering that a library for this submission and won't include it in this post. If you're interested, have a look at the main.js on GitHub (and the other files in that folder).

All the JavaScript does is to set up a WebGL context, store the seed in a uniform for the shader, and then render a single quad over the entire context. The vertex shader is a simple passthrough shader, so all the magic happens in the fragment shader. That's why I called this a GLSL submission.

The largest part of the code is actually to generate the Simplex noise, which I found on GitHub. So I'm omitting that as well in the code listing below. The important part is, it defines a function snoise(vec2 coords) which returns simplex noise without using a texture or array lookup. It's not seeded at all, so the trick to getting different noise is to use the seed in determining where to do the lookup.

Mathematica Spackling

The app below applies speckling to a random image. Clicking on "new patch" generates a new random image to work with, and then applies the effects according to current settings.
The effects are oil painting, Gaussian filter, posterization, and embossing. Each effect can be independently tweaked. The seed for the random number generator can be any integer from 1 to 2^16.

Update:
The Gaussian filter, which softens the edges, is now the last image effect applied. With this modification, the posterization effect was no longer needed and thus removed.

Explanation

The explanation is based on a slightly different version, in which posterization was employed and GaussianFilter was applied early on. But it still serves to clarify how each image effect alters an image. The end result is a paint texture with sharper edges. When the Gaussian filter is only applied at the end, the result will be smoother, as the above picture shows.

Let's look at some image effects, one at a time.

Generate a starting image.

r = RandomImage[1, {200, 200}]

Lena will show us how each image effect transforms a life-like picture.

A Gaussian filter effect applied to Lena (not to the oil painting effect version of Lena). The radius is 10 pixels. (In the final version, at the top of this entry, GaussianFilter is applied as the final effect.)

An intense posterization effect applied to Lena. (In the final version of the app, I removed posterization. But we'll leave it in the analysis, since the examples in the analysis were based on an earlier version with posterization.)

ImageEffect[Lena, {"Posterization", 2}]

A posterization effect applied to r2.

r3 = ImageEffect[r2, {"Posterization", 4}]

Embossing Lena

ImageEffect[Lena, {"Embossing", 1.2, 1.8}]

Embossing r3 completes the image processing. This is intended to look something like the OP's ceiling.

\$\begingroup\$... there's a built-in to get the Lena image? LOL.\$\endgroup\$
– immibisJan 7 '15 at 3:14

7

\$\begingroup\$Yes. There are roughly 30 built-in pictures in Mathematica used for image processing tests.\$\endgroup\$
– DavidCJan 7 '15 at 3:17

\$\begingroup\$With a slight modification, one could feed RandomInteger a seed, thereby guaranteeing a particular output. Or do you mean something else, like a starting, non-Random image to which effects are applied?\$\endgroup\$
– DavidCJan 7 '15 at 13:37

1

\$\begingroup\$It now accepts a seed from 1 to 2^16.\$\endgroup\$
– DavidCJan 7 '15 at 19:10

1

\$\begingroup\$+1 because Lena will show us how each image effect transforms a life-like picture made me LOL. The weird thing is, the final Lena image appears to have an Aztec or Inca facing left, wearing a headdress and weilding a twig as if it were a gun.\$\endgroup\$
– Level River StJan 5 '16 at 23:25

POV-Ray

A lot of golfing potential, run with povray /RENDER wall.pov -h512 -w512 -K234543

First it creates a random texture, but instead of stopping there it transforms the texture into a 3D-heightfield to make the radial shadows from the camera flash more realistic. And for good measure it adds another texture of little bumps on top.
The only way apart from hardcoding the random seed is to use the clock variable meant for animations, this is passed with the -K{number} flag

Your Answer

If this is an answer to a challenge…

…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.

…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.

…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.

More generally…

…Please make sure to answer the question and provide sufficient detail.

…Avoid asking for help, clarification or responding to other answers (use comments instead).

Code Golf Stack Exchange is a site for recreational programming competitions, not general programming questions. Challenges must have an objective scoring criterion, and it is highly recommended to first post proposed challenges in the Sandbox.