void R2Image::AddNoise(double factor);Adds noise to an image. The amount of noise is given by the factor in the range [0.0..1.0]. 0.0 adds no noise. 1.0 adds a lot of noise.
![]() 0.0 |
![]() 0.25 |
![]() 0.5 |
![]() 0.75 |
![]() 1.0 |
void R2Image::Brighten(double factor);Changes the brightness of an image by interpolating between the original image and a black image (factor = -1.0) or a white image (factor = 1.0). Interpolation with the black image darkens the image, and interpolation with the white image brightens it. See Graphica Obscura.
![]() 0.0 |
![]() 0.5 |
![]() 1.0 |
![]() 1.5 |
![]() 2.0 |
void R2Image::ChangeContrast(double factor);Changes the contrast of an image by interpolating between a constant gray image (factor = 0) with the average luminance and the original image (factor = 1). Interpolation reduces contrast, extrapolation boosts contrast, and negative factors generate inverted images. See Graphica Obscura.
![]() -0.5 |
![]() 0.0 |
![]() 0.5 |
![]() 1.0 |
![]() 1.7 |
void R2Image::ChangeSaturation(double factor);Changes the saturation of an image by interpolating between a gray level version of the image (factor = 0) and the original image (factor = 1). Interpolation decreases saturation, extrapolation increases it, and negative factors preserve luminance but invert the hue of the input image. See Graphica Obscura.
![]() -1.0 |
![]() 0.0 |
![]() 0.5 |
![]() 1.0 |
![]() 2.5 |
Image* R2Image::Crop(int x, int y, int w, int h);Extract a sub image from the image, at position (x,y), width w, and height h.
![]() |
![]() Crop(42,147,85,93) |
void R2Image::ExtractChannel(int channel);Extract a channel of an image. Leaves the specified channel intact. Sets all other ones to zero.
![]() Original |
![]() Red |
![]() Green |
![]() Blue |
void R2Image::Quantize(int nbits);Converts an image to nbits bits per channel using uniform quantization.
The number of output levels per channel is L = 2nbits, which are evenly distributed so that the lowest level is 0.0, the highest is 1.0. Every input value is to be mapped to the closest available output level.
![]() 1 |
![]() 2 |
![]() 3 |
![]() 4 |
![]() 5 |
void R2Image::RandomDither(int nbits);Converts an image to nbits bits per channel using random dithering. It is similar to uniform quantization, but random noise is added to each component during quantization, so that the arithmetic mean of many output pixels with the same input level will be equal to this input level.
![]() 1 |
![]() 2 |
![]() 3 |
![]() 4 |
![]() 5 |
void R2Image::OrderedDither(int nbits);Converts an image to nbits bits per channel using ordered dithering. It is similar to uniform quantization, but a pattern is added to each component before quantization. The following examples used the pattern
Bayer4 | = | 15 | 7 | 13 | 5 |
3 | 11 | 1 | 9 | ||
12 | 4 | 14 | 6 | ||
0 | 8 | 2 | 10 |
![]() 1 |
![]() 2 |
![]() 3 |
![]() 4 |
![]() 5 |
void R2Image::FloydSteinbergDither(int nbits);Converts an image to nbits per channel using Floyd-Steinberg dither with error diffusion. Each pixel (x,y) is quantized, and the quantization error is computed. Then the error is diffused to the neighboring pixels (x + 1, y), (x - 1, y + 1), (x, y + 1), and (x + 1, y + 1) , with weights 7/16, 3/16, 5/16, and 1/16, respectively.
![]() 1 |
![]() 2 |
![]() 3 |
![]() 4 |
![]() 5 |
void R2Image::Blur(double sigma);Blurs an image by convolving it with a Gaussian filter. In the examples below, the Gaussian function used was
G(x) = exp(-x^2/(2*sigma^2))
and the integer below each image indicates the sigma of the filter. You can limit the filter width to
ceil(3*sigma)*2+1.
![]() original |
![]() 0.125 |
![]() 0.5 |
![]() 2 |
![]() 8 |
void R2Image::EdgeDetect();Detect edges in an image by convolving it with an edge detection kernel. In the example below, the kernel used was
-1 |
-1 |
-1 |
-1 |
8 |
-1 |
-1 |
-1 |
-1 |
Image *R2Image::Scale(double sx, double sy);Scales an image in x by sx, and y by sy. The result depends on the current sampling method (point, bilinear, or Gaussian). In the example below, the size of the Gaussian filter is 3x3.
![]() Point |
![]() Bilinear |
![]() Gaussian |
Image *R2Image::Rotate(double angle);Rotates an image by the given angle, in radians (a positive angle implies counter-clockwise rotation) . The result depends on the current sampling method (point, bilinear, or Gaussian). In the example below, the size of the Gaussian filter is 3x3.
![]() Point |
![]() Bilinear |
![]() Gaussian |
void R2Image::Composite(Image *bottom, Image *top, Image *result);Composites the bottom and top images into the result image. You can use an image editor of your choice to generate the input images you need.
Original Images
Brazilian soccer team ("seleção") Me
Auxiliary Images
Final Image
void R2Image::Fun();Warps an image using a creative filter of your choice. In the following example, each pixel is mapped to its corresponding scaled polar coordinates. The artifacts of point sampling are very noticeable in this example.
![]() Original |
![]() Point |
![]() Bilinear |
![]() Gaussian |
void R2Image::Morph (const R2Image& target, R2Segment *source_segments, R2Segment *target_segments, int nsegments, double t, int sampling_method);Morph two images using [Beier92].
I0
and I1
are before and after images.
source_segments
and L1
are corresponding line
segments. t
is the morph time, between 0
and 1.
![]() before |
![]() after |
void R2Image::MotionBlur(int amount);Blurs an image in the horizontal direction with a linear ramp kernel with amount non-zero entries.
![]() Original |
![]() amount = 4 |
![]() amount = 8 |
![]() amount = 16 |