Photo Laborer Manual - Computer Science Department, Technion

advertisement
Photo Laborer
C
C
O
M
U
R
G
O
R
A
O
R
–
2
3
4
3
2
6
CO
OM
MPPPU
UTTTEEER
RG
GRRRAAAPPPHHHIIICCCSSS LLLAAABBBO
OR
RA
ATTTO
OR
RYYY –
–2
23
34
43
32
26
6
W
W
2
0
0
7
2
0
0
8
WIIINNNTTTEEERRR 2
20
00
07
7---2
20
00
08
8
NO
ON
N-RE
EA
ALLIIS
ST
TIIC
C RE
EN
ND
DE
ER
RIIN
NG
G
B
Byy M
Miilleennaa N
Naattaannoovv
S
Su
up
pe
errvviisse
ed
db
byy G
Ge
errssh
ho
on
nE
Ellb
be
err
1
Photo Laborer
TABLE OF CONTENTS
TABLE OF CONTENTS ................................................................................................................................. 2
ACKNOWLEDGEMENTS .............................................................................................................................. 3
INTRODUCTION ............................................................................................................................................ 5
PHOTO LABORER USERS .......................................................................................................................... 5
TERMS ................................................................................................................................................................. 6
PHOTO LABORER REQUIREMENTS ..................................................................................................... 7
APPROACH ..................................................................................................................................................... 10
APPROACH DESCRIPTION ................................................................................................................................ 10
DEFINITIONS ................................................................................................................................................... 11
MAIN PAINTING ALGORITHM ........................................................................................................................... 13
STROKE BUILDING ALGORITHM ...................................................................................................................... 13
CHOOSING BEST CONTROL POINTS OF THE STROKE..................................................................................... 14
PAINTING STYLE.............................................................................................................................................. 14
EXAMPLE/SIMULATION ................................................................................................................................... 18
APPROACH SUMMARY ...................................................................................................................................... 20
APPLICATION DESIGN AND IMPLEMENTATION ...................................................................... 21
USE-CASE DIAGRAM ....................................................................................................................................... 21
COMPONENT DIAGRAM .................................................................................................................................... 22
CODE .................................................................................................................................................................. 25
PHOTO LABORER COMPILATION ...................................................................................................... 31
PHOTO LABORER MANUAL .................................................................................................................... 34
RESULTS .......................................................................................................................................................... 48
REFERENCES ................................................................................................................................................. 54
2
Photo Laborer
Acknowledgements
This project was developed in Computer Graphics Laboratory at the Department of
Computer Science, Technion, Israel Institute of Technology.
I want to say special thanks to Gershon, my supervisor, for the given opportunity to
learn and practice my very basic knowledge in this, new for me, area. This was very
interesting and challenging experience that I’ve gained in the end of my first degree.
Abstract
Non-photorealistic rendering (NPR) is an area of computer graphics that focuses on
enabling a wide variety of expressive styles for digital art and producing “drawn by
hand” images using computer. NPR is inspired by artistic styles such as painting,
drawing, technical illustration, and animated cartoons.
NPR is very popular and required area. The most important uses for it are:
1. Scientific and medical illustrations.
Scientific and medical illustration is the area of illustration that has achieved the
highest level of sophistication. Medical books are full of beautiful samples of
unique illustrations.
2. Technical Illustrations. Technical illustrations made by hand tend to be simpler
and less varied than scientific or medical illustrations. No doubt this is because
they tend to portray industrial products with a more uniform surface structure
than, for example, the human body. Illustrative images in user manuals are part
of this area, as well as illustrations in other kinds of technical documentation.
3. Archaeological Illustration. In some branches of science, specific styles of
graphics have become the methods of choice for capturing visible phenomena.
One such area is archaeology. A great many illustrations in archaeology are
drawn primarily using stippling, where the drawing consists of small dots to cover
surfaces.
4. Storytelling. The art of using comics and animation to support telling stories was
brought to perfection by the Walt Disney Company. Visualizations convey
information to augment what is spoken by the characters.
Various terms have been used in the literature for the general area that we call NPR:
Non-realistic rendering was first used by the organizers of the Eurographics’ 99
conference
3
Photo Laborer
Non-photorealistic rendering by Lansdown and Schofield (1995)
Sketch rendering by Strothotte et al. (1994)
Pen-and-ink illustration by Winkenbach and Salesin (1994)
Stipple rendering by Deussen et al. (1999b)
Comprehensible rendering by Saito and Takahashi (1990)
Artistic rendering by Lansdown and Schofield (1995)
Illustrative rendering by Dooley and Cohen (1990a, 1990b)
And many others…
4
Photo Laborer
Introduction
This project is based on the work Paint by Relaxation that was published by Aaron
Hertzmann in May 2000. There are few main aspects this research is focused on:

Creation of painting by converting original image (photo) into painted image using
“strokes”. The painted image is created by adding “strokes” to the clean “canvas”.

The ability to create painted image using original image with minimal energy.

Painting style varies in accordance to different parameters which can be changed
by a user. This feature allows creation of painted image in different painting styles.
The application, implemented in this project, is called Photo Laborer and it produces
real-time painted imagery using the original image:

User provides the original image
•

Different formats are accepted; for example, jpg, png, bmp, gif, etc.
User specifies the painting style
•
Maximal and minimal brush length
•
Maximal and minimal brush thickness
•
Stroke curvature
•
Stroke texture (darkening and brightening the color inside the stroke)

User chooses curve, area or the whole image he wants to “paint”.

Photo Laborer creates and renders the painted result.
•
User can save the painted image to file.
Photo Laborer Users
Photo Laborer application can be used by artists in different areas, for example,
advertising and TV program creators, interior and exterior designers.
Also, it can help to professional painters: if the painter is not sure the result of what he
wants to draw will be satisfying, he can take a picture of this scene (nature, still life,
portrait, etc.), create painted image using Photo Laborer, and make sure the produced
sketch is looks good.
In addition, Photo Laborer can be useful for regular users. For example:

Making portrait of family members or colleagues.

Designing picture postcards for friends.

Making art posters for home interior.
5
Photo Laborer
Terms
To provide clarity, terms and definitions are defined as follows:
Term
Definition
Brush
A brush is a real ‘brush’ stamp on the paper in specific point on the
canvas. In the current Photo Laborer version, brush is characterized by:
Stroke
•
brush min and max radius (width = radius * 2 + 1)
•
color texture (solid or with dark bright lines)
A stroke is a thick curve defined by a list of control points, curvature,
and brush parameters such as radius, color and texture. Control points
are the points, the curve should pass through them.
A new stroke is created, starting from a given point on the image. Next
control points are added to the stroke, using the contour-approximating
method. The curve is drawn over the control points using cardinal curve
algorithm.
Painted image
A painted image is defined as a collection of brush strokes.
The painted image size is the same as the size of the original image.
A painting is rendered by compositing the brush strokes in order they
appear onto the canvas.
Energy
The energy computations, used in this project, will be described later.
Direction
Photo Laborer searches for object contours on the image and associates
Direction with each pixel identified as a contour. Later, when stroke
points are selected, Photo Laborer uses the direction information to
make the strokes close as possible to the original drawing.
6
Photo Laborer
Photo Laborer Requirements
Priority level:

P1 - features that we can’t ship without

P2 - features that are not mandatory but significantly enhance the product competitiveness

P3 - Nice to have features (should be taken only if simple to implement)
1. Non-functional requirements
1.1.
Priority
The Photo Laborer application will be implemented in C++
Done
P1
language.
1.2.
The wxWidgets toolkit will be used in order to edit and render
P1
images.
1.3.
The Photo Laborer application will run on operating system
P1
that supports wxWidgets.
1.4.
The Photo Laborer application logically divided into two
P1
modules: GUI and image processor (the logic).
2. Functional requirements
2.1.
Priority
First, user, using the Photo Laborer GUI, should provide the
P1
original image, in any format supported by wxWidgets (bmp,
jpg, gif, png, tiff, etc.), he wants to convert to the “painted”.
2.2.
GUI module
2.2.1.
The GUI displays both the original image, provided by
P1
the user, and the painted one.
2.2.2.
Creation of painted image is real-time process.
2.2.2.1.
Photo Laborer will re-render the painted image,
P2
thus allowing to user to see how the painted image is
created stroke by stroke.
2.2.2.2.
During the painting process Photo Laborer will
P3
show time-bar that displays (in percentage) how much
work is already done.
2.2.3.
The GUI provides style dialog, allowing the user to
P1
choose painting style.
2.2.4.
User may change the painting style by:
2.2.4.1.
Select brush width range.
P1
2.2.4.2.
Select stroke length range.
P1
7
Done
Photo Laborer
2.2.4.3.
Select stroke curvature.
P1
2.2.4.4.
Select stroke texture (by specifying darkening
P2
and brightening parameter).
2.2.5.
User can place individual brush strokes, as
P2
suggestions.
2.2.6.
User can place individual brush strokes by decree.
P2
2.2.7.
User can apply selected style on the selected area on
P1
the paint. *This area should be clear on the painted image,
because the painting algorithm paints only over not-covered
surface.
2.2.8.
User can apply selected style on the whole paint.
P1
2.2.9.
User can undo changes.
P2
2.2.10.
User can save current style to file.
P1
2.2.11.
User can load/reuse saved style.
P1
2.2.12.
User can delete created by him style.
P2
2.2.13.
List of built-in styles is provided
P2
2.3.
Trade-off: undo requires large allocations.
Image Processor module:
2.3.1.
Image Processor gets bitmap of the original image,
P1
style parameters and image region, converts the specified
region on the bitmap into painting based on the given style
and returns painted image in bitmap format.
2.3.2.
Image processor style parameters are:
2.3.2.1.
Brush’s minimal and maximal widths.
P1
2.3.2.2.
Stroke length range.
P1
2.3.2.3.
Stroke curvature.
P2
2.3.2.4.
Stroke texture (darkening and brightening).
2.3.3.
User can apply selected style on specified area on the
P1
image.
2.3.4.
User can apply selected style on the whole image.
P1
2.3.5.
User can add brush stroke with selected style as
P2
suggestions.
2.3.6.
User can add brush stroke with selected style by
P2
decree.
2.3.7.
Image Processor allows saving the current painted
image to file.
8
P1
Photo Laborer
2.3.8.
Image Processor allows undo changes (returning an
P2
image that was before applying last user request)
3. Future requirements
3.1.1.
Priority
Provide special GUI features in order to make the
Done
P3
interaction with the painting more handy and convenient.
3.1.2.
User can add his own stroke textures and save them as
P3
option in style dialog.
Requirements Summary
1. All P1 requirements were done.
2. Only two of P2 requirements weren’t done.
3. All P3 requirements were done.
4. In addition, extra-feature (progress bar) was implemented. In the beginning I used it
for operation-time testing purposes and in the end I decided to add it as a part of the
Photo Laborer to allow stopping the long operations in the middle.
Progress-bar: During the painting process Photo Laborer will show progress bar that displays
how much work is already done and estimated time left.
9
Photo Laborer
Approach
This section includes definition and description of the main algorithms,
techniques and data structures that were used in Photo Laborer implementation.
Approach description
In the Paint by Relaxation work, made by Aaron Hertzmann, the main effort was
to achieve good quality painted image with minimum energy. Reducing the
number of brush strokes, the painted image is consists of, by adding only “good”
ones is the solution which allows to create ultimate painting algorithm.
The author suggests relaxation technique. This technique described by the
following general algorithm:
P ← empty painting
While not done
C ← SUGGEST()
// Suggest change
if (E(C(P)) < E(P))
// Does the change help?
P ← C(P)
// If so, adopt it
In his experiments, Hertzmann uses highly random suggestions, such as adding
a disc stroke in a random location with a random size. Most of the computation
time was spent on suggestions that were rejected. Because the space of
paintings has very high dimensionality, it is possible to make many suggestions
that do not substantially reduce the energy.
This method is useful for producing pleasing results. But, on the other hand,
there is no guarantee that the algorithm will converge to a result that is globally
optimal or even locally optimal. In his work, Hertzmann underlines the need in
improve in algorithm that generates strokes.
In my project I’ve tried to achieve the situation where most of the suggestions
are accepted. By reducing the random choices and by, primordially, computing
10
Photo Laborer
the first control points of the more appropriate strokes I was able to reduce the
computation time from hours to minutes.
In my project I used special pre-computed tables that significantly improved the
quality of generated strokes, making them similar to the picture as possible.
These tables are: Energy table and Directions table.
Definitions
Energy difference
Ideally, each stroke should consist of pixels that have similar or almost similar hue.
Energy difference between two colors is Euclidean distance between RGB values of
these colors:
Euclidean distance
Euclidian distance between two colors is defined as:
When stroke energy (energy difference) is calculated, I use only the one color only,
which is the primary stroke color. The ‘textured’ is applied after calculation of the
energy, when the stroke is actually rendered. Ideally, I wanted strokes to have the
lowest energy difference as possible, making the painting closest to the original image.
Energy table
Energy table describes the energy of each pixel relative to its neighbors. Neighbors are
defined by the stroke average radius (width = radius*2 + 1): I am using pixels on the
circle with this radius as neighbors.
This table is pre-computed before painting. I am using this table for two purposes.
1. Selecting the next stroke ‘start point’:
During the painting, I am sorting the pixels that left unpainted using their energy: first
in table will be the pixel with lowest energy. Then, when I need to start new stroke, I
select the start point of it from this sorted list.
11
Photo Laborer
The reason for selecting pixels with lowest energy is that the stroke that starts from
this pixel has a good chance to be accepted because pixels around have similar color.
2. Calculate direction table (see below)
Direction table
Each stroke should compliment object’s contour and not pass across it. In my
algorithm I am checking for each pixel whether or not it is ‘on the contour’ and if yes,
what is the ‘contour direction’ in this pixel. This information is stored in special table,
pre-computed before painting, in the same structure as the energy table.
To check if the pixel is contour or not, I am using the following algorithm:
•
Go over all pixels-neighbors in given radius (same radius as in energy table).
•
Count pixels that have energy difference > pixel_energy * 1.6 as high.
•
Count pixels that have energy difference < low_energy_resolution as low.
o
pixel_energy is taken from the energy table
o
low_energy_resolution is defined by user’s style, although it always has
its default and user cannot change it in this version. Low energy resolution
is an estimated energy for which user eye does not perceive the difference
between two colors.
•
If [ (low / number of pixels in given radius) > 33%] and [(high / number of pixels
in given radius)) > 25%]):
o
If there is a sequence of pixels that were counted as ‘low’ this pixel is
defined as a contour and I calculate ‘suggested direction’ for this pixel. To
get the direction, I am using the sequence of similar colors: direction is set
using the first and the last pixels in this sequence, as shown in this figure:
Note: the above percentages were chosen by trial and error till good results were
achieved.
12
Photo Laborer
Main painting algorithm
(function ImageProcessor::PainterLoop)
{Input: image (bmp; different formats supported by the wxWidgets are converted into
wxImage), style}
1. Calculate energy table
2. Calculate direction table (by using energy-table)
3. Define minimal energy difference bar for stroke to be rendered (starts with 0)
4. While (number of uncovered pixels left > 0)
{
4.1. Choose the next set of non-covered pixels on the image from the beginning of
the list of pixels sorted by their energy (lowest come first). These pixels will be
used as first control points for the new strokes. By choosing first elements from
the sorted list, I actually first choose pixels with low energy, i.e., pixels that have
the same or very similar color as the pixels surrounding them.
4.2. For each starting pixel, build the stroke (see below) and calculate its energy
difference.
4.3. If stroke’s energy difference is less than the current bar, Render stroke (see
below).
4.4. Otherwise, store the stroke in list of failed strokes.
4.5. If list of failed strokes has grown too much (>= 500), than it is time to change
the acceptance bar for the next strokes:
{
4.5.1. Sort the failed strokes by their energy difference.
4.5.2. Take the first 5% (25 strokes) of strokes and render them.
4.5.3. Update energy bar to be the maximal energy difference of those 5%.
4.5.4. Drop the remained failed strokes.
}
}
Stroke building algorithm
(functions ImageProcessor::SelectStrokeControlPoints and BuildStroke)
{Input: first control point, painting style, painting area}
1. // Select control points of the stroke
2. While (stroke’s length < required)
{
13
Photo Laborer
2.1. Find next control point. Next control point is calculated using direction table by
searching for suggested direction around the current pixel or randomly if not
found.
2.2. Add it to list of selected control points.
}
3. // Build the stroke
4. Using cardinal spline algorithm, build stroke over the control points selected. Cardinal
spline algorithm is described here:
http://en.wikipedia.org/wiki/Cardinal_spline#Cardinal_spline
5. For each pixel in the stroke, apply the brush on it:
5.1. To apply the brush, I need first to calculate the angle of the brush and then
request brush texture for the specified angle. To calculate the angle, I am using
the angle of the (current index - radius) and (current index + radius) points.
5.2. Create brush texture for the radius and calculated angle. Brush texture includes:
5.2.1. Coordinates of each brush pixel (relative to its center, which is stroke
point)
5.2.2. Strength of the color (dark or bright), relative to stroke’s primary color
5.3. For each pixel, calculate image coordinates and save to stroke’s list of pixels
6. Once all the pixels are collected, calculate the average color of this stroke (primary
color) and the energy difference of this stroke relative to the original image
Choosing best control points of the stroke
There are different ways to choose best control points. In the Hertzmann’s research, for
each control point calculated next control point by finding the most similar (in terms of
color) pixel.
In my algorithm I use the same technique, but the calculations are made differently: my
calculations are based on the direction and energy tables which are pre-calculated in
order to choose next control point. Thus, the calculation time is perceptibly reduced.
Painting Style
14
Photo Laborer
An artist (user) must have control over painting style. In addition, artist can use
different painting styles in different areas of the image. Also, user can “paint” the stroke
by providing curve control points. All those features allow creating customized painting.
Painting style is defined by below parameters:
Name: style name. This parameter should be unique.
Brush [minimal, maximal] radius: brush radius in pixels.
Stroke processing algorithm will randomly choose brush radius in the provided range
[minimal, maximum].
Brush width = (brush radius * 2) + 1
Stroke [minimal, maximal] length: stroke length in pixels.
Stroke processing algorithm will choose appropriate stroke length in the provided range
[minimal, maximum] in accordance to the energy and directions tables in stroke’s area.
Stroke curvature: in fact, this parameter represents number of control points in stroke.
Higher the number more curved the stroke. Stroke processing algorithm uses this
parameter as maximal number of control points and chooses number of control points
randomly in the range [2, maximal].
Texture brightening/darkening: this parameter allows creation of textured stroke.
Both parameters should be in the range [0, 64]. User can set [0]/[0] if texture is not
desired. Brush small strokes processing algorithm, which is used by stroke processing
algorithm, adds dark and bright lines to the stroke in random positions, so each stroke
has different texture.
15
Photo Laborer
Example from Photo Laborer:
Photo Laborer built-in styles and their parameters:
Name
Hyperrealism
Brush
Brush
Stroke
Stroke
min
max
min
radius
radius
1
1
Texture
Texture
max
brighten
darkeni
length
length
ing
ng
1
5
0
0
16
Curvature
2
Photo Laborer
Realism
1
4
2
20
3
5
5
Pointillist
3
3
5
7
2
15
15
Impressionism
2
7
4
100
4
1
1
Expressionism
5
20
20
100
2
20
20
Watercolor
1
15
3
30
6
10
2
*Note: You can find explanation and definition of these styles in
PhotoLaborerBuiltinPaintingStyles.doc.
17
Photo Laborer
Example/Simulation
Those two examples demonstrate data structures that were presented below in action.
Example 1
Given:
a. Original image Test1.bmp
b. Selected style parameters:
Brush radius: [1, 4]
Stroke length: [2, 20]
Stroke curvature: [3]
Texture brightening/darkening [5, 5]
Brush radius parameter involved in the calculations of energy difference, border-pixels
and direction-pixels for each pixel on the image.
Result:
a. Energy table
Energy table was converted to white/black image. High energy pixels are colored in black
and low energy pixels are colored in white. You can see in (ii) that the pixels with the
high energy located on the contour of the objects (rectangle, circle and oval).
b. Direction-pixels table
Direction-pixels table was converted to white/black image too. Pixels that can serve as а
direction guide for stroke creation algorithm are colored in black and all the rest pixels
are colored in white. You can see in (iii) that the pixels that define the stroke direction
for this image are located on the contour of the objects.
In this case the energy table and the direction points table look the same. The reason is
that the objects on the original image have only one solid color each one of them and
their contour is well-defined.
18
Photo Laborer
Example 2
Given:
c. Original image Test2.bmp
d. Selected style parameters:
Brush radius: [1, 4]
Stroke length: [2, 20]
Stroke curvature: [3]
Texture brightening/darkening [5, 5]
Result:
c. Energy table
This image has different hues. In some cases difference between hues in one color is
very bold and in some cases it’s delicate. This example (ii) demonstrates in better way
when the energy is high and when it’s low.
d. Direction-pixels table
In this case the energy table and the direction points table are different (as opposed to
the example 1).
19
Photo Laborer
Approach Summary
The main concepts, presented in Hertzmann’s work, combine great ideas in terms of NRP
software system features:

The ability to “paint” in different painting styles by using a single algorithm.

The ability to create painted image as much as possible similar to the original
image.
The only lack in this research is imperfection of computation time. By changing an inner
implementation computations and data structures I was able significantly to reduce
computation time, while preserving the quality of the painting.
The main contributor in time reducing process is Energy Table, introduced above, a data
structure which holds energy difference for each pixel and is calculated before painting
process even starts. This data structure, together with two additional data-structures,
allows improving of good strokes proposal.
20
Photo Laborer
Application Design and Implementation
This section describes the Photo Laborer design and implementation.
Photo Laborer application is implemented in C++ programming language and can run on
any operating system supporting wxWidgets.
The wxWidgets toolkit is used in order to edit and render images.
Use-case Diagram
The use-case diagram overviews the usage of a Photo Laborer system.
21
Photo Laborer
Component diagram
Photo Laborer application is logically divided into two main components: GUI and image
processor (the logic of the system).
Photo Laborer Main Frame is the GUI (graphical user interface).
Image Processor is the component holding both the logic and the data structures.
22
Photo Laborer
Photo Laborer Main Frame
Image Processor
Stroke Algorithm
Shape Algorithms
GUI (PhotoLaborerMainFrame) is responsible for user interaction and image
rendering. The main frame class represents the GUI of Photo Laborer and includes:
•
Navigation and toolbar menus
•
Two photo controls
•
Style control
Navigation and toolbar menus allow defining paint style and run the painting algorithms
(such as paint image or paint area). They also allow loading the source file and saving
the painted image to file.
Photo controls are used to render the original image and the painted one on the screen,
so the user will be able to see the result of painting process. Also, those controls allow
area choosing on the image, so the user can define area for painting.
PhotoLaborerMainFrame responsible for:
•
GUI controls creation
•
events definition for created controls
•
binding of events to event handlers (methods that will treat in raised events)
•
processing of user’s commands (using PhotoLaborerProcessor)
ImageProcessor implements the main functionality of the PhotoLaborer. It holds the
main painting algorithm and other helper methods such as LoadImage. It makes use of
other components as StrokeAlgorithms and ShapeAlgorithms to calculate the tables
(such as energy table) and build the strokes.
23
Photo Laborer
ShapeAlgorithms component defines different shapes processing algorithms such as
line, circle, rectangle and cardinal spline. Other modules use these algorithms for various
purposes. For example, the PhotoControl control uses rectangle algorithm to draw user
selection area on the rendered images.
StrokeAlgorithms component is responsible for cardinal spline curve processing. It
uses the curve processor defined in ShapeSlgorithms to calculate curve points.
24
Photo Laborer
Code
This section introduces files and classes Photo Laborer application consists of.
As was mentioned above, Photo Laborer application is implemented in C++ and can run
on any operating system supporting wxWidgets, - package that was used in order to edit
and render images.
Note: wxWidgets is a toolkit for creating graphical user interfaces for cross-platform
applications. This converts Photo Laborer application to be multi-platformed, i.e. it can
run on both Microsoft Windows or Unix/Linux (and others).
Photo Laborer development was based on OOP paradigm.
File
Class
Definition
DebugInfo.h (header
only)
DebugInfo
This class is used to catch memory leaks
when program exists.
When Visual Studio ends running the
program in Debug mode, it prints the
memory leaks to see which object has
leaked.
Special class codes are used; to use this,
inherit from this class and initialize the
base using four characters code, for
example:
class MyClass : DebugInfo
{
MyClass() : DebugInfo('MyCl') {}
}
When leaked memory is printed, the
application outputs the memory blocks. If
MyClass is leaked, its code will be printed
in reverse form: <lCyM>.
25
Photo Laborer
Direction.h (header
only)
Direction
This class calculates a point movement (in
terms of X, Y steps) relatively to the initial
axis coordinates.
ImageEnergy.h
ImageEnergy
This class calculates and holds energy
weights and other relative information for
each pixel on the image.
Energy table is created for average radius.
Radius represents the thickness of the
painting brush (width = radius * 2 + 1).
The energy is a Euclidian distance between
the color of the given pixel and the colors
of the pixels that surround it in the given
radius.
The smaller the color distance (Euclidian
distance) the lower the energy of that
pixel.
In addition, based on the energy table,
suggested directions table is calculated.
This table allows to choose better stroke
direction (accordingly to the contours of
the elements on the image).
ImageProcessor.h
ImageProcessor
This class performs the image processing
logic.
All requests, made by the user through the
GUI, redirected to this class. The main
functionality of Photo Laborer is
implemented here:
26

Load image

Paint the whole image

Paint area on the image

Paint curve on the image

And more…
Photo Laborer
PaintBrush.h
PaintBrushPixel
This class represents single pixel
information within the brush.
Coordinates in this pixel are relative to
brush's center, which is (0, 0).
Once created, the pixel is read-only
PaintBrushTexture
This class represents paint brush texture,
returned by brush. This texture is drawn
on the image when texture's center
matches the control point of the stroke.
textures are read-only for the user, once
created user cannot modify them.
Only PaintBrush can create/modify them
using CreateTexture call.
PaintBrush
Abstract class that represents brush used
to draw the strokes.
PaintBrushCache
This class caches the results of other
brushes for fast performance.
for each radius and angle, the brush is
generated only once and saved in cache.
PaintBrushSolidLine
Brush that draws texture with width = 3
with same color (without texture effects).
PaintBrushRandom
Brush that draws texture with width = 3
with random lines.
Darkness and brightness are defined by
the user's style.
PaintStyle.h
PaintStyle
This class defines style components and
holds style info, user chose.
PaintStyleDialog.h
PaintStyleDialog
Defines dialog allowing see, edit, add new
and delete existing painting styles.
PaintStyleManager.h
PaintStyleManager
This class manages (add new, delete/edit
existing) styles directly in the xml file that
holds painting styles.
27
Photo Laborer
PhotoControl.h
PhotoControl
This class inherits from wxWidgets’ class
called wxScrolledWindow.
It creates scrolled window rendering
images.
This class is responsible for images
rendering on the screen and allows user to
select area over rendered image.
PhotoLaborerMainFra
me.h
PhotoLaborerMainFr
ame
This is the main frame – GUI of the Photo
Laborer.
This class inherits from wxWidgets’ class
called wxFrame. It creates main Photo
Laborer frame consisting of:
Randomizer.h
Randomizer

Menus

Toolbar

Two scrolled windows (defined by
PhotoControl class)
This class produces randomized number
using different distributions (uniform, high
results are preferred, low results are
preferred, etc.).
It is used for first control point selection in
BuildStroke algorithm.
28
Photo Laborer
ShapeAlgorithms.h
This file includes declarations of several
methods that have similar structure and
purpose:
Those methods are intended for shape
processing (line, rectangle, circle and
curve). In this process, each pixel within
the boundaries of the required shape will
be visited by the method. When pixel is
visited processPoint method is called (see
explanations below).
All those methods use two templates:
class Processor and class Method.
Processor – reference to class that includes
declaration of this Method.
Method – reference to method
processPoint defined in Processor. In each
Processor class this method will implement
different functionality, so it’s convenient to
use one algorithm for pixels visiting, but
treat it in different ways in accordance to
the purpose.
StrokeAlgorithms.h
ProcessStroke
(method)
Processes the new stroke with given
control points
WorkerThread.h
LongTask,
LongTaskGroup and
WorkerThread
Hence the painting process can take
minutes and even more, it’s necessary to
update user how much time this procedure
can take.
Thus, the paint jobs are running in
separate threads while the main thread is
serving the process dialog. When the
painting job completes, it sets the
progress to 100% and the dialog is closed.
wxPrecompiled.h
This file includes almost all "standard"
wxWidgets headers needed in this project.
It’s used in order to reduce number of
similar includes in project.
29
Photo Laborer
PhotoLaborerApp.cpp
PhotoLaborerApp
This class inherits from wxWidgets’s class
wxApp. OnInit method represents the start
point of the Photo Laborer application: the
application runs, the main frame (GUI) is
displayed.
30
Photo Laborer
Photo Laborer Compilation
Hence Photo Laborer application uses wxWidgets toolkit, wxWidgets should be
downloaded, installed and compiled on the machine before you compile Photo Laborer.
The next sections describe step-by-step how to do it.
1. Download wxWidgets
a. Go to: www.wxwidgets.org
b. Download the latest stable release
i. Photo Laborer is compiled and tested with 2.8.9 version on Windows
platform.
ii. I didn’t test Linux or other platforms, although, since Photo Laborer
includes only wxWidgets header files, I assume, it will work on them.
iii. If you want to compile and use it only on Windows, you can download
only the wxMSW package.
c. Install wxWidgets on your machine (follow the instructions of wxWidgets
installer).
i. After the installation you’ll find the wxWidgets sources and other files
in C:\wxWidgets-<version> which is the default installation folder.
2. Compile wxWidgets
a. I’ve used Visual Studio 2005 to compile wxWidgets. If you want to compile
wxWidgets in different way, please follow the instructions in “Compiling
wxWidgets” in Start menu.
b. Photo Laborer uses the below libraries from wxWidgets:
i. Unicode Release
ii. Unicode Debug
1. Compile Unicode Debug only if you want to debug the
application.
c. Open <wxWidgetsRoot>\build\msw\wx.dsw in Visual Studio.
i. Visual Studio will ask you to convert the project files to the new format
– press “Yes to all”.
d. To compile Unicode Release libraries:
i. Select “Unicode Release” configuration under Solution Configuration in
Visual Studio.
31
Photo Laborer
ii. Build the following projects in the exact order:
1. core
2. base
3. net
4. xml
5. wxjpeg
6. wxpng
7. wxtiff
8. right-click on the solution and select “Build Solution” to compile
all the rest. Note that the order of compilation is important: it
looks like the original solution does not have proper build
dependencies.
e. To compile Unicode Debug libraries, select “Unicode Debug” configuration and
compile the above projects again in the same order under the new
configuration.
3. Set WXWIN environment variable used by Photo Laborer to find
wxWidgets include files and libraries.
a.
Go to Control Panel => System => Advanced => Environment Variables.
b. Under “System Variables” or “User Variables” press “New” button and add
new variable:
i. Name: WXWIN
ii. Value: C:\wxWidgets-2.8.9
1. Replace 2.8.9 if you use different version.
4. Compile Photo Laborer to test new wxWidgets installation.
a. Open Photo Laborer solution in Visual Studio (Sources\PhotoLaborer.sln).
b. To compile Release version:
i. Select Release in Configuration Manager.
ii. Build Photo Laborer project.
iii. The output files will be in Sources\Release folder.
c. To compile Debug version:
i. Select Debug in Configuration Manager.
ii. Build Photo Laborer project.
iii. The output files will be in Sources\Debug folder.
32
Photo Laborer
iv. Note that when Photo Laborer is running in debug mode, it is very
slow; use only small images when debugging the application.
33
Photo Laborer
Photo Laborer Manual
This section describes how to use Photo Laborer using main menu.
File
Open menu item
Before user gets started, the original image should be uploaded:

Use Open in menu bar in order to choose the file.

Upload image that should be “painted”.
Save As menu item
User can save painted image in file.
Exit menu item
Exit menu item closes Photo Laborer program.
34
Photo Laborer
Original image rendering
Once, image has chosen, it will be rendered in the left image pane:
Selecting area on the image
User can select area either on the original image or on the painted one; the area will be
marked as selected on both sides. The selection is done with the mouse:

Press on the left button on the image

Drag the mouse over the area you want to select to its opposite corner

Release the mouse to stop the selection
35
Photo Laborer
Edit
Copy Selection menu item
Use Copy Selection menu item if you want to copy part of painted image to the
clipboard: first, select the area on the image and then click on this menu item.
Select All menu item
Use Select All menu item if you want to select the whole image.
Clear Selected Area menu item
This operation will clear the selected area on the painted image. User can use this for
repainting this area with different style.
*Note: painting process is applied only on the clear area on the painted image.
Erase the painted image menu item
36
Photo Laborer
This operation will clear the painted image. User can use this for repainting the whole
image with different style.
37
Photo Laborer
View
View Original Image menu item
The original image will be displayed on the screen (in the left image pane).
View Painted Image menu item
The painted image will be displayed on the screen (in the right image pane).
View Energy Table Image menu item
Energy table image will be displayed on the screen (in the right image pane).
*Note: Read about energy table in the Project Book.
View Direction Points Image menu item
38
Photo Laborer
Direction points image will be displayed on the screen (in the right image pane).
*Note: Read about direction points in the Project Book.
Auto scale menu item
User can select this menu item if he wants the original and painted images to be
displayed in the original size. If not selected, both sides are auto-scaled to the view
area.
Image panes:
Original image is displayed in the left pane.
Painted image is displayed in the right pane. Painted image can be one of those:
painted image, energy table image and direction points image.
39
Photo Laborer
40
Photo Laborer
Paint
Paint Image menu item
Starts painting the whole image – user will see the results on the right side.
Paint Selected Area menu item
Like Paint, but works on the selected area only. Users can use this feature:
To ‘test’ the painting style.
To apply different styles on different areas.
Draw Curve menu item
User can paint single curve. To do this he should select curve’s control points and then
press on Draw Curve menu item. First and last control points represent beginning and
41
Photo Laborer
end of the curve. User should provide at least two control points in order to paint a
curve.
The point selection is done with the mouse:

Place the mouse in the desirable position.

Press on the right button on the mouse.
Clear User Points menu item
This operation clears curve control points selected by user.
Style Manager menu item
42
Photo Laborer
This operation will open Style Dialog. In this dialog user can see available painting styles
and their details, create new style, change and delete existing.
Photo-Laborer has several built-in painting styles, like, Pointillist, Expressionism,
Realism and more. Those styles can not be changed by the user.
User can create his own styles, which are editable and can be deleted.
*Note: Style name should be unique (without duplications).
43
Photo Laborer
Style Manager
Buttons
•
Edit: Edit selected style. Not available for built-in styles.

Save: Save changes. Not available if Edit was not pressed.

Cancel: Don’t save changes. Not available if Edit was not pressed.
•
Delete: Delete selected style. Not available for built-in styles.
•
Add New: Create new style. Provide unique style name.
•
Close: Closes styles dialog.
Style parameters
•
Name: style name. This parameter should be unique.
•
Brush [minimal, maximal] radius: brush radius in pixels.
Brush width = (brush radius * 2) + 1
•
Stroke [minimal, maximal] length: stroke length in pixels.
44
Photo Laborer
•
Stroke curvature: in fact, this parameter represents number of control points in
stroke. Higher the number more curved the stroke. Stroke processing algorithm uses
this parameter as maximal number of control points.
•
Texture brightening/darkening: this parameter allows creation of textured
stroke. Both parameters should be in the range [0, 64]. Set 0/0 for solid colors (no
textures), increase the numbers for textured appearance.
45
Photo Laborer
Help
About menu item
This dialog displays wxWidgets and OS versions.
46
Photo Laborer
Toolbox
In addition user can execute almost all the operations, available in the main menu, using
the toolbar.
47
Photo Laborer
Results
Photo Laborer’s final results are introduced in this section.
Example 1
48
Photo Laborer
49
Photo Laborer
Example 2
50
Photo Laborer
51
Photo Laborer
52
Photo Laborer
53
Photo Laborer
References
[1] Aaron Hertzmann 2000
Paint by Relaxation
[2] Thomas Strothotte and Stefan Schlechtweg 2002
Non-Photorealistic Computer Graphics
Modeling, Rendering, and Animation
54
Download