BookNotesSlidesP-sets Syllabusdraft · v0.2.64.1
◀▲⌂▶
💬Comments welcome. To leave a note, select any text and click the note / highlight button that pops up — or open the panel with the tab at the top-right (‹). Notes are visible only inside our private review group.

45.11 Problem Set 8 — Non-photorealistic rendering⧉

Problem Set 8: Painterly Rendering. Due Wednesday November 18, 9:00pm.

45.11.1 Summary⧉

In this assignment, we will take photographs as input and turn them into a painterly rendition. We will stochastically splat brush strokes on the image, varying the size, angle, and density of strokes. Below is an example of the type of rendition we will generate.

Problem set 8, villeperdue-oriented
Problem set 8, villeperdue-oriented

In a nutshell, we generate random locations $x, y$, read the color in a reference photograph, and splat a small image of a brush stroke at this location in the output image. We modulate the size and orientation of the brush strokes to make things more interesting.

45.11.2 Paintbrush splatting⧉

texture is a regular 3-channel image that specifies the opacity at each pixel. It will be grayscale (all three channels are the same) in practice. An opacity of zero means that the pixel is unaffected, and 1 means that the pixel is updated with color. For values between 0 and 1, the output is a linear combination of the original value and color.

Test your image with a few brush locations and the provided brush.png file.

45.11.3 Painterly rendering⧉

Single scale⧉

First, scale the texture image so that it has maximum size size. Use the provided scaleLin function or your own method. For each of N random locations ($x, y$) splat a brush in your output image using the above function. Generate random locations using rand(). Note that rand() returns an integer between 0 and RAND_MAX; wherever this handout needs a uniform random number $r$ in $[0, 1]$, use rand()/(float)RAND_MAX. The color of the brush should be read from im at ($x, y$). To make things more interesting, modulate the color by multiplying it by a random amount proportional to noise. We recommend multiplying by $(1-\mathtt{noise}/2+\mathtt{noise}\cdot r)$, with $r$ uniform in $[0,1]$.

(This should run fast: it should take under 5 minutes even for N=10,000. If your code is running too slowly, make sure you're not iterating over the entire image in your implementation of brush.)

Importance sampling with rejection⧉

We will vary the density of strokes according to an importance map importance, which is encoded as a regular image where all 3 channels are the same. We want the density of the strokes to be proportional to this map. The simplest way to do this is to use rejection sampling. For this, you reject samples with a probability proportional to importance(x,y). Draw a uniform random number $r$ in $[0, 1]$ and reject the sample if $r$ is greater than importance(x,y). Note how samples are always accepted when importance is 1, always rejected when it's 0, and in general, accepted with a probability equal to the importance value.

Since we reject a number of samples, we do not splat the required N strokes. In order to fix this, multiply N by a normalization factor based on the average probability of accepting samples. You can also use a while loop, but it involves less probabilistic calculation and is therefore less fun.

Two-scale painterly rendering⧉

We will now create a simplistic rendering with two different passes. In the first pass, we will use brushes of size size, and in the second pass, brushes of size size/4. The first pass should use a constant importance map and the second finer pass will only add strokes where the image has strong high frequencies, as indicated by a sharpness map.

Problem set 8, villeperdue-ct
Problem set 8, villeperdue-ct

Figure 1. Two-scale painterly rendering

Problem set 8, out-first
Problem set 8, out-first
Problem set 8, out-second
Problem set 8, out-second

Figure 2. Contributions of the first pass (left) and second pass (right)

45.11.4 Oriented painterly rendering⧉

We now seek to orient the stroke direction according to the content of the input image. For this, we will rely on the structure tensor used for Harris corner detection. The structure tensor is better than the gradient for this purpose.

Orientation extraction⧉

We know that the structure tensor characterizes how much an image changes in all directions. The eigenvectors of the structure tensor indicate the directions of maximum and minimum variation. We want to align our strokes along edges and oriented structures, which means that they should follow the smallest eigenvector. We will first experiment with orientation extraction before using it for our painterly rendering.

Copy your computeTensor(const Image &im, float sigmaG=1.0f, float factor=4.0f) from Pset7 into npr.cpp (the starter only has a stub) and use it to extract a structure tensor at a slightly large scale. Use Eigen::EigenSolver<Matrix> to extract the eigenvectors and compute the angle of the smallest one with respect to the horizontal direction. The function atan2 might come handy. At each pixel, build the $2\times2$ matrix from the three tensor values; “the smallest eigenvector” is the eigenvector whose eigenvalue is the smaller of the two. EigenSolver returns complex numbers even for this symmetric matrix, so take their real part (.real()), and do not assume the eigenvalues come sorted.

Debug your function by applying it to all the pixels in the image round.png.

Your test images.

Put the images you make in Input/debug/, lowercase, at most $256\times256$ pixels, named angle_<n>_<what>.png. make prepare copies Input/debug/ into your submission, so they travel with your code. Keep the code that makes them and runs testAngle on them in a8_main.cpp, and write the results into Output/ under the same name with _out added.

Figure 3 shows the expected output for round.png. Note that the eigenvectors are defined to a sign, and that the orientation of an edge or structure is equivalently defined up to $\pi$. The extracted orientation should be in [0, $2\pi$].

Problem set 8, angles
Problem set 8, angles

Figure 3. Visualization of the angles extracted from round.png.

Single-scale⧉

For this, we encourage you to fill in helper function vector<Image> rotateBrushes(const Image &im, int nAngles) which takes as input a single texture and returns a list of nAngles textures rotated by $i 2\pi/n$.

Two scale⧉

Debug your function by applying it to round.png.

Problem set 8, china-oriented
Problem set 8, china-oriented

45.11.5 Your image⧉

45.11.6 Paper Review (6.8370 only)⧉

Unlike the previous psets, it's going to be all reading and writing. Your job is to review a recent publication in computational photography. This will hopefully give you some more insight into the review process that these papers go through.

You should select one paper from the provided papers.html file (if the link is dead, search for the paper on Google), or a computational photography paper from the SIGGRAPH lists here: <http://kesen.realtimerendering.com/>. If there's another relevant paper that you're particularly interested in reading, ask us about it and we'll probably be okay with it (unless it's something that you're already supposed to read for one of the problem sets). If you're not sure if a particular SIGGRAPH paper falls under computational photography, feel free to ask us on piazza.

You should use the SIGGRAPH review form, available at the following URL: <https://sa2018.siggraph.org/en/submitters/technical-papers/review-form>. For “Explanation of Rating", try to come up with at least one outstanding question that you think the authors didn't address in the paper. You can skip the “Private Comments". Try to be thorough! Probably a paragraph or two for each question, and more for “Explanation of Rating".

One final note: don't be compelled to like a paper because it was already published. Every paper has some shortcomings. Maybe the method is very elegant and general but doesn't end up producing very impressive results. Maybe the results are spectacular, but the method itself has some mathematical holes. Maybe everything seems great, but there just aren't enough details to reproduce the results. It's up to you as a reviewer to weigh the strengths and weaknesses of each paper

See the text for details on what should be included. In addition please add paper title, authors, venue, year and valid link.

45.11.7 Extra credits⧉

Relaxation

Treat the painterly rendering as a stochastic process and optimize for the output painting to match an input photograph over a certain number of iterations. <https://dl.acm.org/doi/pdf/10.1145/97880.97902>, Haeberli 1990.

Curved brush strokes

Create brush strokes using a Bézier curve spline. <https://dl.acm.org/doi/pdf/10.1145/280814.280951>, Hertzmann 1998.

Adjustments for brush thickness and length

Add a UI or a heuristic to account for brush thickness and length. <https://people.csail.mit.edu/fredo/PUBLI/Drawing/drawing.pdf>, Durand et al 2001.

Stained glass images

Use a voronoi diagram to create stained glass images. <https://diglib.eg.org/bitstream/handle/10.2312/egs20021036/short75.pdf> Dobashi et al 2002.

Deep Learning

Use deep learning to create painterly renders. <https://arxiv.org/pdf/2108.03798.pdf>, Liu et al 2021.

45.11.8 Submission⧉

Turn in your files to the online submission system and make sure all your files are in the asst directory under the root of the zip file. If your code compiles on the submission system, it is organized correctly. The submission system will run code in your main function, but we will not use this code for grading. The submission system should also show you the image your code writes to the ./Output directory

In the submission system, there will be a form in which you should answer the following questions: