Problem set 8 · Painterly Rendering
Where to hand in. Submit at
https://compphoto-portal.fredopdurand.workers.dev/
Make sure your files sit in the asst directory at the root of the zip. The
Submission section at the end of this handout has the details, along with the
questions the form will ask you.
AI policy.
You are only allowed to use the class's AI assistant at
https://comp-photo-book.pages.dev/
embedded in the book, notes, slides, and problem sets.it is built to help you think, not to hand you the answer
it knows our material: chapters, notes, demos, problem sets
Fine: brainstorming, explanations, editing, debugging, learning support.
Not fine: pasting problem statements into other (general) AI tools, asking for solutions to assigned problems, or submitting AI-written text, code, equations or analysis as your own.
Keep the line visible: distinguish your own work from AI-assisted work, and mention how the AI helped you (or not).
Extra credit. Percentages are of the regular points of your own version of the class, 6.8370 or 6.8371. An extension is worth what the handout says, 5% unless marked otherwise; for 6.8371, a part marked “6.8370 only” counts as extra credit at the percentage it gives. All extra credit on one problem set together is capped at 10%, so a problem set gives at most 110%.
Questions. Ask on Piazza, where the whole class sees the answer:
https://piazza.com/mit/fall2026/683701
Summary
Render a paintbrush onto an image
Single-scale painterly rendering
Importance sampling using rejection
Two-scale painting
Orientation computation using the structure tensor
Two-scale oriented painting
Paper review (6.8370)
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.

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.
Paintbrush splatting
- 1
Write a function
void brush(Image &im, int x, int y,that takes as input image
vector<float> color, const Image &texture)imand draws (“splats”) a single brush stroke centered atx, y. The appearance of the brush is specified by an opacitytextureand a 3-vectorcolor. To avoid boundary problems, ignore cases wherexandyare closer than half of the texture size away from the image boundary. This will also give you the nice rough edges shown in the above image.
texture is a regular 3-channel image that specifies the opacity at each pixel. It will be greyscale (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.
Painterly rendering
Single scale
- 2
Write a function
void singleScalePaint(const Image &im, Image &out, const Image &texture, int size=10, int N=10000, float noise=0.3)
that mutates theoutimage by splatting a paintbrush at random location.
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.
- 3
Write a function
void singleScalePaintImportance(const Image &im, const Image &importance, Image &out, const Imagethat creates a rendering by taking the importance parameter into account and debug it using some importance map of your choice.
&texture, int size=10, int N=10000, float noise=0.3)
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.
- 4
Fill in the function
Image sharpnessMap(const Image &im, float sigma=1.0f)that returns a sharpness map for Imageim. To obtain the sharpness map, you first should apply a Gaussian blur with standard deviationsigmato the luminance of the image. Then obtain the high frequencies by subtracting the blurred luminance from the original luminance. Then square the high frequency image, and then apply a Gaussian blur with standard deviation4*sigma, and then divide by the maximum value. - 5
Implement a function
void painterly(const Image &im, Image &out, const Image &texture, int N=10000, int size=50, float noise=0.3)
that mutatesoutto become a painterly rendering ofimwhere a first layer of coarse strokes is used, followed by a refinement with smaller strokes in regions of high detail. Your function should usesingleScalePaintImportance, and pass itNin each of the two passes; the same holds fororientedPaintbelow.



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, from Pset7 into
float factor=4.0f)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.
- 6.a
Write a function
Image testAngle(const Image &im, floatthat extracts the orientation of the features in the image. For visualization purposes, the angles should first be wrapped to [0, $2\pi$] and then mapped to [0,1]
sigmaG=3.0f, float factor=5.0f) - 6.b
Create three small images of your own to use for testing and debugging
testAngle, and include them in your submission, namedangle_1_… pngtoangle_3_… pngunderInput/debug/as described below. Choose images whose orientations you can predict, for example straight stripes at an angle you choose, or a ring. For each one, say what the image is, why you chose it, what parameters you runtestAnglewith, and what values you expect in its output, and where. (Answer in the form)
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$].

round.png.Single-scale
- 7
Write a function
void singleScaleOrientedPaint(const Image &im, const Image &importance, Image &out, constthat behaves similarly to the non-oriented version, except that brush strokes are oriented according to the provided
Image &tensor, const Image &texture, int size, int N, float noise, int nAngles=36)tensormap. Compute each stroke's angle fromtensordirectly rather than callingtestAngle: the grader tests each function on its own.
For this, we encourage you to fill in helper function vector<Image> which takes as input a single texture and returns a list of
rotateBrushes(const Image &im, int nAngles)nAngles textures rotated by $i 2\pi/n$.
Two scale
- 8
Write a function
void orientedPaint(const Image &im, Image & out, const Image &texture, int N=10000, int size=50, float noise=0.3)
that mutatesoutinto a painterly image where strokes are oriented along the image structure, that is, along the smallest eigenvector of the structure tensor, as above. Use a two-scale approach as above. You can use the same structure tensor for both approaches.
Debug your function by applying it to round.png.

Your image
- 9
Apply the function of your choice to a photograph of your own. Put the photograph and your painting in a folder
my_paintingat the top of your assignment folder, asmy_painting/input.pngandmy_painting/painting.png;make preparecopies that folder into your submission. Say in the form which function and parameters you used.
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
- 10
Write your paper review in the submission form. (Answer in the form)
See the text for details on what should be included. In addition please add paper title, authors, venue, year and valid link.
Extra credits
How to hand in extra credit.
Each extension comes with a test that runs it; an extension that is described but not tested earns at most about half its value.
Put the extension's code in
extraCredit.cpp, declared inextraCredit.h. It may call your other functions.Write
testExtraCredit.cpp, a program with its ownmain()that runs the extension on real inputs (the provided images inInput/, or your own inInput/debug/), writes its results as PNG files toOutput/extra_credit/, and prints what it checks: numbers, timings, comparisons.make ecbuilds and runs it.In the submission form's extra credit question, say what the extension does, which functions implement it, and what the test shows.
make prepareas usual: it already includes both files.
extraCredit.cpp is compiled together with your required code, so if it does
not compile, every regular test fails too: submit only extra credit code that builds.
The grader keeps the images in Output/extra_credit/ (or Output/) and
ignores PNG files anywhere else.
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.
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
Leave the input images we provide out of the zip: make prepare copies only
the images you made yourself (Input/debug/, or a file a question asks
for by name), the submission system
supplies the provided ones, and grading uses its own copy. Uploads are limited
to 100 MB.
In the submission system, there will be a form in which you should answer every written question this handout marks with “(Answer in the form)”, and these:
How long did the assignment take? (in minutes)
Potential issues with your solution and explanation of partial completion (for partial credit)
Any extra credit you may have implemented and their function signatures if applicable
Collaboration acknowledgment (you must write your own code)
What was most unclear/difficult?
What was most exciting?