Message Boards Message Boards

Generating water color like paintings

Posted 8 years ago

Here's a thing I played around with the other night: how do you generate graphics that look like the soft strokes of a water color painting? I started with ListDensityPlot.

img = ListDensityPlot[
  Table[Sin[i - .5 + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}] + 
   RandomReal[6, {31, 31}], Mesh -> None, PlotRangePadding -> None, 
  Frame -> None]

List density plot of a sine function with random noise

ListDensityPlot has a "softer" feeling than ArrayPlot.

To give an impression of strokes in the painting I "warp" the density plot with a vector field.

licPlot = LineIntegralConvolutionPlot[{{x + y, x - y}, img
   }, {x, 1, 100}, {y, 1, 100}, RasterSize -> 1000, 
  LineIntegralConvolutionScale -> 30, PlotRangePadding -> None, 
  PlotRangeClipping -> False, ImageMargins -> 0, ImagePadding -> None,
   Frame -> None, PlotRange -> {{1, 100}, {1, 100}}, 
  ImageSize -> {700, 700}]

LineIntegralConvolutionPlot with

OK, that looks nice. Let's mirror it.

raw = ImageAssemble[{licPlot, ImageReflect[licPlot, Right -> Left]}]

Mirror image of LineIntegralConvolutionPlot

The new image looks nice, but it's too uniform. My first idea here is to apply some digital tilt-shift photography effects, see demonstration http://demonstrations.wolfram.com/DigitalTiltShiftPhotography/ This gives the impression that some parts are more emphasized than others.

mask

newmask = 
  ImageResize[ImageRotate[mask, 3 \[Pi]/2], ImageDimensions[raw]];
composed = ImageCompose[raw, SetAlphaChannel[Blur[raw, 14], newmask]]

ImageCompose

To make it even less uniform I apply an ImageTransformation, and remove the border.

f[x_, y_] := {x + 5 Sin[.05 x], y + 7 Sin[.1 y]}
transformed = 
 ImageTransformation[composed, f @@ # &, DataRange -> Full];
 ImageTake[transformed, {5, -1}, {1, -5}]

Production image

There we go!

What's next? How about creating an APIFunction that generates you a new "random" picture every day with a random PlotTheme and then set your smartphone's wallpaper to it?


As a bonus, I tried to expand the image using Inpainting:

inpainting input

dims = ImageDimensions[clipped];
clippedPadded = ImageCrop[clipped, 2*dims, Padding -> White];
mask = ImageCrop[ConstantImage[Black, dims], 2*dims, Padding -> White];
Grid[{{clippedPadded, mask}}, Frame -> All]

HighlightImage[
 Inpaint[clippedPadded, mask, Method -> "TextureSynthesis"], 
 Dilation[MorphologicalPerimeter[mask], 5], "HighlightColor" -> Brown,
  Method -> "Solid"]

inpainted water color computer generated art

Read more about inpainting in this blog: Extending Van Gogh’s Starry Night with Inpainting

POSTED BY: Johan Rhodin
3 Replies
Posted 8 years ago

Nice! This is fun.

POSTED BY: Vincent Meade

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the tops of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: Moderation Team

This is very nice! I wonder if this could be applied to a photo to restyle it in watercolor.

POSTED BY: Marina Shchitova
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract