basic:
clear,
clone,
create,
xsize,
ysize
plain drawing:
box,
circle,
getpixel,
line,
setcolor,
setpixel,
threshold,
polyfill
operators:
`&,
`*,
`+,
`-,
`==,
`>,
`<,
`|
pasting images:
paste,
paste_alpha,
paste_alpha_color,
paste_mask
getting subimages, scaling, rotating:
autocrop,
clone,
copy,
dct,
mirrorx,
rotate,
rotate_ccw,
rotate_cw,
rotate_expand,
scale,
skewx,
skewx_expand,
skewy,
skewy_expand
calculation by pixels:
apply_matrix,
change_color,
color,
distancesq,
grey,
invert,
modify_by_intensity,
outline
select_from,
rgb_to_hsv,
hsv_to_rgb,
average, max, min, sum, sumf, find_min, find_max
special pattern drawing:
noise,
turbulence,
test,
tuned_box,
gradients,
random
2 2 pixel(x,y)= base+ k ( sum sum pixel(x+k-1,y+l-1)*matrix(k,l) ) k=0 l=0
1/k is sum of matrix, or sum of matrix multiplied with div. base is given by r,g,b and is normally black.
blur (ie a 2d gauss function):
({({1,2,1}), ({2,5,2}), ({1,2,1})}) | ||
original | ||
sharpen (k>8, preferably 12 or 16):
({({-1,-1,-1}), ({-1, k,-1}), ({-1,-1,-1})}) | ||
edge detect:
({({1, 1,1}), ({1,-8,1}), ({1, 1,1})}) | ||
horisontal edge detect (get the idea):
({({0, 0,0}), ({1,-2,1}), ({0, 0,0})}) | ||
emboss (might prefer to begin with a grey image):
({({2, 1, 0}), ({1, 0,-1}), ({0,-1,-2})}), 128,128,128, 3 | ||
greyed |
This function is not very fast.
argument(s) | description |
array(array(int|array(int))) | the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation. |
int r int g int b | base level of result, default is zero |
int|float div | division factor, default is 1.0. |
This function is not very fast.
argument(s) | description |
array(array(int|array(int))) | the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation. |
int r int g int b | base level of result, default is zero |
int|float div | division factor, default is 1.0. |
"Unneccesary" is all pixels that are equal -- ie if all the same pixels to the left are the same color, that column of pixels are removed.
The find_autocrop() function simply returns x1,y1,x2,y2 for the kept area. (This can be used with copy later.)
argument(s) | description |
int border int left int right int top int bottom | which borders to scan and cut the image;
a typical example is removing the top and bottom unneccesary
pixels:
img=img->autocrop(0, 0,0,1,1); |
average() and sumf() may also wrap, but on a line basis. (Meaning, be careful with images that are wider than 8425104 pixels.) These functions may have a precision problem instead, during to limits in the 'double' C type and/or 'float' Pike type.
argument(s) | description |
float factor | factor to use for both x and y |
float xfactor float yfactor | separate factors for x and y |
argument(s) | description |
int newxsize int newysize | new image size in pixels |
original | ->box |
argument(s) | description |
int x1 int y1 int x2 int y2 | box corners |
int r int g int b | color of the box |
int alpha | alpha value |
argument(s) | description |
int tor int tog int tob | destination color and next current color |
int fromr int fromg int fromb | source color, default is current color |
original | ->circle |
argument(s) | description |
int x int y | circle center |
int rx int ry | circle radius in pixels |
int r int g int b | color |
int alpha | alpha value |
original | ->clear |
argument(s) | description |
int r int g int b | color of the new image |
int alpha | new default alpha channel value |
original | clone | clone(50,50) |
argument(s) | description |
int xsize int ysize | size of (new) image in pixels, called image is cropped to that size |
int r int g int b | current color of the new image, default is black. Will also be the background color if the cloned image is empty (no drawing area made). |
int alpha | new default alpha channel value |
The red, green and blue values of the pixels are multiplied with the given value(s). This works best on a grey image...
The result is divided by 255, giving correct pixel values.
If no arguments are given, the current color is used as factors.
original | ->color(128,128,255); |
argument(s) | description |
int r int g int b | red, green, blue factors |
int value | factor |
original | ->copy |
->copy |
argument(s) | description |
int x1 int y1 int x2 int y2 | The requested new area. Default is the old image size. |
int r int g int b | color of the new image |
int alpha | new default alpha channel value |
Image.Image |
Image.Image |
The image can also be calculated from some special methods, for convinience:
channel modes; followed by a number of 1-char-per-pixel strings or image objects (where red channel will be used), or an integer value: "grey" : make a grey image (needs 1 source: grey) "rgb" : make an rgb image (needs 3 sources: red, green and blue) "cmyk" : make a rgb image from cmyk (cyan, magenta, yellow, black)generate modes; all extra arguments is given to the generation function. These has the same name as the method: "test," "gradients" "noise" "turbulence" "random" "randomgrey" specials cases: "tuned_box" (coordinates is automatic)
argument(s) | description |
int xsize int ysize | size of (new) image in pixels |
Color color int r int g int b | background color (will also be current color), default color is black |
int alpha | default alpha channel value |
Method for scaling is rather complex; the image is transformed via a cosine transform, and then resampled back.
This gives a quality-conserving upscale, but the algorithm used is n*n+n*m, where n and m is pixels in the original and new image.
Recommended wrapping algorithm is to scale overlapping parts of the image-to-be-scaled.
This functionality is actually added as an true experiment, but works...
argument(s) | description |
int newx int newy | new image size in pixels |
It write's dots on stderr, to indicate some sort of progress. It doesn't use any fct (compare: fft) algorithms.
The given value (or current color) are used for coordinates in the color cube. Each resulting pixel is the distance from this point to the source pixel color, in the color cube, squared, rightshifted 8 steps:
p = pixel color o = given color d = destination pixel d.red=d.blue=d.green= ((o.red-p.red)²+(o.green-p.green)²+(o.blue-p.blue)²)>>8
original | distance² to cyan | ...to purple | ...to yellow |
argument(s) | description |
int r int g int b | red, green, blue coordinates |
argument(s) | description |
int r int g int b | weight of color, default is r=87,g=127,b=41, same as the grey() method. |
Intensity of new pixels are calculated by:
i' = i^g
For example, you are viewing your image on a screen with gamma 2.2. To correct your image to the correct gamma value, do something like:
my_display_image(my_image()->gamma(1/2.2);
argument(s) | description |
int g int gred int ggreen int gblue | gamma value |
argument(s) | description |
int x int y | position of the pixel |
original | 2 color gradient |
10 color gradient |
3 colors, grad=4.0 |
3 colors, grad=1.0 |
3 colors, grad=0.25 |
original | ->grey(); | ->grey(0,0,255); |
argument(s) | description |
int r int g int b | weight of color, default is r=87,g=127,b=41, which should be pretty accurate of what the eyes see... |
When converting to RGB, the input data is asumed to be placed in the pixels as above.
original | ->hsv_to_rgb(); | ->rgb_to_hsv(); |
tuned box (below) | the rainbow (below) | same, but rgb_to_hsv() |
HSV to RGB calculation:
in = input pixel out = destination pixel h=-pos*c_angle*3.1415/(float)NUM_SQUARES; out.r=(in.b+in.g*cos(in.r)); out.g=(in.b+in.g*cos(in.r + pi*2/3)); out.b=(in.b+in.g*cos(in.r + pi*4/3));
RGB to HSV calculation: Hmm.
Example: Nice rainbow.
object i = Image.Image(200,200); i = i->tuned_box(0,0, 200,200, ({ ({ 255,255,128 }), ({ 0,255,128 }), ({ 255,255,255 }), ({ 0,255,255 })})) ->hsv_to_rgb();
original | ->invert(); | ->rgb_to_hsv()->invert()->hsv_to_rgb(); |
original | ->line |
argument(s) | description |
int x1 int y1 int x2 int y2 | line endpoints |
int r int g int b | color |
int alpha | alpha value |
//Stina is an image with a cat. array(object) Stina4=Stina->orient4(); Stina4[1]*=215; Stina4[3]*=215; string foo=Stina->make_ascii(@Stina4,40,4,8);
| / - \ hue= 0 64 128 192 (=red in an hsv image)
Replacement examples:
Old code:
img=map_fs(img->select_colors(200));New code:
img=Image.Colortable(img,200)->floyd_steinberg()->map(img);
Old code:
img=map_closest(img->select_colors(17)+({({255,255,255}),({0,0,0})}));New code:
img=Image.Colortable(img,19,({({255,255,255}),({0,0,0})}))->map(img);
new pixel value = sum( my_abs(needle_pixel-haystack_pixel))
The new image only have the red rgb-part set.
argument(s) | description |
int|float scale | Every pixel is divided with this value. Note that a proper value here depends on the size of the neadle. |
object needle | The image to use for the matching. |
object haystack_cert | This image should be the same size as the image itselves. A non-white-part of the haystack_cert-image modifies the output by lowering it. |
object needle_cert | The same, but for the needle-image. |
int foo object haystack_avoid | This image should be the same size as the image itselves. If foo is less than the red value in haystack_avoid the corresponding matching-calculating is not calculated. The avoided parts are drawn in the color 0,100,0. |
original | ->mirrorx(); |
original | ->mirrory(); |
For each color an intensity is calculated, from r, g and b factors (see grey), this gives a value between 0 and max.
The color is then calculated from the values given, v1 representing the intensity value of 0, vn representing max, and colors between representing intensity values between, linear.
original | ->grey()->modify_by_intensity(1,0,0, 0,({255,0,0}),({0,255,0})); |
argument(s) | description |
int r int g int b | red, green, blue intensity factors |
int|array(int) v1 int|array(int) vn | destination color |
The random seed may be different with each instance of pike.
Example:
->noise( ({0,({255,0,0}), 0.3,({0,255,0}), 0.6,({0,0,255}), 0.8,({255,255,0})}), 0.2,0.0,0.0,1.0 );
argument(s) | description |
array(float|int|array(int)) colorrange | colorrange table |
float scale | default value is 0.1 |
float xdiff float ydiff | default value is 0,0 |
float cscale | default value is 1 |
orient gives an HSV image (run a hsv_to_rgb pass on it to get a viewable image). corresponding to the angle of the orientation:
| / - \ hue= 0 64 128 192 (=red in an hsv image) purple cyan green redRed, green and blue channels are added and not compared separately.
If you first use orient4 you can give its output as input to this function.
The orient4 function gives back 4 image objects, corresponding to the amount of different directions, see above.
Default is to paint above, below, to the left and the right of these pixels.
You can also run your own outline mask.
The outline_mask function gives the calculated outline as an alpha channel image of white and black instead.
original | masked through threshold |
...and outlined with red |
argument(s) | description |
array(array(int)) mask | mask matrix. Default is ({({0,1,0}),({1,1,1}),({0,1,0})}). |
int olr int olg int olb | outline color. Default is current. |
int bkgr int bkgg int bkgb | background color (what color to outline to); default is color of pixel 0,0. |
int|float div | division factor, default is 1.0. |
argument(s) | description |
object image | image to paste (may be empty, needs to be an image object) |
int x int y | where to paste the image; default is 0,0 |
An alpha channel value of 0 leaves nothing of the original image in the paste area, 255 is meaningless and makes the given image invisible.
argument(s) | description |
object image | image to paste |
int alpha | alpha channel value |
int x int y | where to paste the image; default is 0,0 |
A pixel value of 255 makes the result become the color given, 0 doesn't change anything.
The masks red, green and blue values are used separately. If no color are given, the current is used.
argument(s) | description |
object mask | mask image |
int r int g int b | what color to paint with; default is current |
int x int y | where to paste the image; default is 0,0 |
A pixel value of 255 makes the result become a pixel from the given image, 0 doesn't change anything.
The masks red, green and blue values are used separately.
argument(s) | description |
object image | image to paste |
object mask | mask image |
int x int y | where to paste the image; default is 0,0 |
phaseh gives an image where
max falling min rising value= 0 64 128 192
0 is set if there is no way to determine if it is rising or falling. This is done for the every red, green and blue part of the image.
Phase images can be used to create ugly effects or to find meta-information in the orginal image.
original | phaseh() | phasev() | phasevh() | phasehv() |
argument(s) | description |
array(int|float) curve | curve(s), ({x1,y1,x2,y2,...,xn,yn}),
automatically closed.
If any given curve is inside another, it will make a hole. |
original | ->random() | ->random(17) | greyed (same again) |
color(red) (same again) |
...red channel |
Use with ->grey() or ->color() for one-color-results.
The string is nullpadded or cut to fit.
argument(s) | description |
string what | the hidden message |
original | ->rotate(15,255,0,0); | ->rotate_expand(15); |
The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.
This rotate uses the skewx() and skewy() functions.
argument(s) | description |
int|float angle | the number of degrees to rotate |
int r int g int b | color to fill with; default is current |
original | ->rotate_ccw(); |
original | ->rotate_cw(); |
argument(s) | description |
float factor | factor to use for both x and y |
float xfactor float yfactor | separate factors for x and y |
argument(s) | description |
int newxsize int newysize | new image size in pixels |
This is very close to a floodfill.
The image is scanned from the given pixel, filled with 255 if the color is the same, or 255 minus distance in the colorcube, squared, rightshifted 8 steps (see distancesq).
When the edge distance is reached, the scan is stopped. Default edge value is 30. This value is squared and compared with the square of the distance above.
argument(s) | description |
int x int y | originating pixel in the image |
argument(s) | description |
int r int g int b | new color |
int alpha | new alpha value |
original | ->setpixel |
argument(s) | description |
int x int y | position of the pixel |
int r int g int b | color |
int alpha | alpha value |
original | ->skewx(15,255,0,0); | ->skewx_expand(15); |
argument(s) | description |
int x | the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color. |
float yfactor | best described as: x=yfactor*this->ysize() |
int r int g int b | color to fill with; default is current |
original | ->skewy(15,255,0,0); | ->skewy_expand(15); |
The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.
argument(s) | description |
int y | the number of pixels |
float xfactor | best described as: t=xfactor*this->xsize() |
int r int g int b | color to fill with; default is current |
original | ->test() | ...and again |
If any of red, green, blue parts of a pixel is larger then the given value, the pixel will become white, else black.
This method works fine with the grey method.
If no arguments are given, it will paint all non-black pixels white. (Ie, default is 0,0,0.)
original | ->threshold(100); | ->threshold(0,100,0); |
Tuning function is (1.0-x/xw)*(1.0-y/yw) where x and y is the distance to the corner and xw and yw are the sides of the rectangle.
original | tuned box | solid tuning (blue,red,green,yellow) |
tuning transparency (as left + 255,128,128,0) |
argument(s) | description |
int x1 int y1 int x2 int y2 | rectangle corners |
array(array(int)) corner_color | colors of the corners:
({x1y1,x2y1,x1y2,x2y2})each of these is an array of integeres: ({r,g,b}) or ({r,g,b,alpha})Default alpha channel value is 0 (opaque). |
The random seed may be different with each instance of pike.
Example:
->turbulence( ({0,({229,204,204}), 0.9,({229,20,20}), 0.9,Color.black}) );
argument(s) | description |
array(float|int|array(int)) colorrange | colorrange table |
int octaves | default value is 3 |
float scale | default value is 0.1 |
float xdiff float ydiff | default value is 0,0 |
float cscale | default value is 1 |
argument(s) | description |
object operand | the other image to divide with; the images must have the same size. |
Color color int value | if specified as color or value, it will act as a whole image of that color (or value). |
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
Comparision is strict and on pixel-by-pixel basis. (Means if not all pixel r,g,b values are correct compared with the corresponding pixel values, 0 is returned.)
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
a>=b and a<=b between objects is equal to !(a<b) and !(a>b), which may not be what you want (since both < and > can return false, comparing the same images).
This can be useful to lower the values of an image, making it greyer, for instance:
image=image*128+64;
argument(s) | description |
object operand | the other image to multiply with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
argument(s) | description |
object operand | the image which to add. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |