9. Image Module

  CLASS Image.Image

Description

The main object of the Image.Image module, this object is used as drawing area, mask or result of operations.

basic:
Image.Image.clear, Image.Image.clone, Image.Image.create, Image.Image.xsize, Image.Image.ysize

plain drawing:
Image.Image.box, Image.Image.circle, Image.Image.getpixel, Image.Image.line, Image.Image.setcolor, Image.Image.setpixel, Image.Image.threshold, Image.Image.polyfill

operators:
Image.Image.`&, Image.Image.`*, Image.Image.`+, Image.Image.`-, Image.Image.`==, Image.Image.`>, Image.Image.`<, Image.Image.`|

pasting images:
Image.Image.paste, Image.Image.paste_alpha, Image.Image.paste_alpha_color, Image.Image.paste_mask

getting subimages, scaling, rotating:
Image.Image.autocrop, Image.Image.clone, Image.Image.copy, Image.Image.dct, Image.Image.mirrorx, Image.Image.rotate, Image.Image.rotate_ccw, Image.Image.rotate_cw, Image.Image.rotate_expand, Image.Image.scale, Image.Image.skewx, Image.Image.skewx_expand, Image.Image.skewy, Image.Image.skewy_expand

calculation by pixels:
Image.Image.apply_matrix, Image.Image.change_color, Image.Image.color, Image.Image.distancesq, Image.Image.grey, Image.Image.invert, Image.Image.modify_by_intensity, Image.Image.outline Image.Image.select_from, Image.Image.rgb_to_hsv, Image.Image.hsv_to_rgb,

Image.Image.average, Image.Image.max, Image.Image.min, Image.Image.sum, Image.Image.sumf, Image.Image.find_min, Image.Image.find_max

special pattern drawing:
Image.Image.noise, Image.Image.turbulence, Image.Image.test, Image.Image.tuned_box, Image.Image.gradients, Image.Image.random

See also

Image.Image, Image.Image.Font, Image.Image.Colortable, Image.Image.X


Method mirrorx

object Image.Image()->mirrorx()

Description

mirrors an image:
original ->mirrorx();

Returns

the new image object


Method mirrory

object Image.Image()->mirrory()

Description

mirrors an image:
original ->mirrory();


Method rotate
Method rotate_expand

object Image.Image()->rotate(int|float angle)
object Image.Image()->rotate(int|float angle, int r, int g, int b)
object Image.Image()->rotate_expand(int|float angle)
object Image.Image()->rotate_expand(int|float angle, int r, int g, int b)

Description

Rotates an image a certain amount of degrees (360° is a complete rotation) counter-clockwise:

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 Image.Image.skewx() and Image.Image.skewy() functions.

Parameter angle

the number of degrees to rotate

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method rotate_ccw

object Image.Image()->rotate_ccw()

Description

rotates an image counter-clockwise, 90 degrees.

original ->rotate_ccw();

Returns

the new image object


Method rotate_cw

object Image.Image()->rotate_cw()

Description

rotates an image clockwise, 90 degrees.

original ->rotate_cw();

Returns

the new image object


Method scale

object Image.Image()->scale(float factor)
object Image.Image()->scale(0.5)
object Image.Image()->scale(float xfactor, float yfactor)

Description

scales the image with a factor, 0.5 is an optimized case.

Parameter factor

factor to use for both x and y

Parameter xfactor
Parameter yfactor

separate factors for x and y

Returns

the new image object


Method scale

object Image.Image()->scale(int newxsize, int newysize)
object Image.Image()->scale(0, int newysize)
object Image.Image()->scale(int newxsize, 0)

Description

scales the image to a specified new size, if one of newxsize or newysize is 0, the image aspect ratio is preserved.

Parameter newxsize
Parameter newysize

new image size in pixels

Returns

the new image object

Note

resulting image will be 1x1 pixels, at least


Method skewx
Method skewx_expand

object Image.Image()->skewx(int x)
object Image.Image()->skewx(int yfactor)
object Image.Image()->skewx(int x, int r, int g, int b)
object Image.Image()->skewx(int yfactor, int r, int g, int b)
object Image.Image()->skewx_expand(int x)
object Image.Image()->skewx_expand(int yfactor)
object Image.Image()->skewx_expand(int x, int r, int g, int b)
object Image.Image()->skewx_expand(int yfactor, int r, int g, int b)

Description

Skews an image an amount of pixels or a factor; a skew-x is a transformation:

original ->skewx(15,255,0,0); ->skewx_expand(15);

Parameter x

the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

Parameter yfactor

best described as: x=yfactor*this->ysize()

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method skewy
Method skewy_expand

object Image.Image()->skewy(int y)
object Image.Image()->skewy(int xfactor)
object Image.Image()->skewy(int y, int r, int g, int b)
object Image.Image()->skewy(int xfactor, int r, int g, int b)
object Image.Image()->skewy_expand(int y)
object Image.Image()->skewy_expand(int xfactor)
object Image.Image()->skewy_expand(int y, int r, int g, int b)
object Image.Image()->skewy_expand(int xfactor, int r, int g, int b)

Description

Skews an image an amount of pixels or a factor; a skew-y is a transformation:

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.

Parameter y

the number of pixels

Parameter xfactor

best described as: t=xfactor*this->xsize()

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method noise

void Image.Image()->noise(array(float|int|array(int)) colorrange)
void Image.Image()->noise(array(float|int|array(int)) colorrange, float scale, float xdiff, float ydiff, float cscale)

Description

Gives a new image with the old image's size, filled width a 'noise' pattern.

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 );

Parameter colorrange

colorrange table

Parameter scale

default value is 0.1

Parameter xdiff
Parameter ydiff

default value is 0,0

Parameter cscale

default value is 1

See also

Image.Image.turbulence


Method random
Method randomgrey

object Image.Image()->random()
object Image.Image()->random(int seed)
object Image.Image()->randomgrey()
object Image.Image()->random(object(greyint) seed)

Description

Gives a randomized image;
original ->random() ->random(17) greyed
(same again)
color(red)
(same again)
...red channel

Use with ->Image.Image.grey() or ->Image.Image.color() for one-color-results.

Returns

a new image

See also

Image.Image.test, Image.Image.noise


Method turbulence

void Image.Image()->turbulence(array(float|int|array(int)) colorrange)
void Image.Image()->turbulence(array(float|int|array(int)) colorrange, int octaves, float scale, float xdiff, float ydiff, float cscale)

Description

gives a new image with the old image's size, filled width a 'turbulence' pattern

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}) );

Parameter colorrange

colorrange table

Parameter octaves

default value is 3

Parameter scale

default value is 0.1

Parameter xdiff
Parameter ydiff

default value is 0,0

Parameter cscale

default value is 1

See also

Image.Image.noise, Image.Image.Color


Method apply_curve

object Image.Image()->apply_curve(object array(int(0..255)
object Image.Image()->apply_curve(object array(int(0..255)
object Image.Image()->apply_curve(object stringchannel, object array(int(0..255)

Description

Apply a lookup-table on all pixels in an image. If only one curve is passed, use the same curve for red, green and blue. If 'channel' is specified, the curve is only applied to the specified channel.

Parameter curve_r
Parameter curve_g
Parameter curve_b
Parameter curve

An array with 256 elements, each between 0 and 255. It is used as a look-up table, if the pixel value is 2 and curve[2] is 10, the new pixel value will be 10.

Parameter channel

one of "red", "green", "blue", "value", "saturation" and "hue".

Returns

a new image object

See also

Image.Image.gamma, Image.Image.`*, Image.Image.modify_by_intensity


Method apply_matrix

object Image.Image()->apply_matrix(array(array(int|array(int))) matrix)
object Image.Image()->apply_matrix(array(array(int|array(int))) matrix, int r, int g, int b)
object Image.Image()->apply_matrix(array(array(int|array(int))) matrix, int r, int g, int b, int|float div)

Description

Applies a pixel-transform matrix, or filter, to the image.

                       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 Image.Image.grey image):
({({2, 1, 0}),
  ({1, 0,-1}),
  ({0,-1,-2})}), 128,128,128, 3
greyed

This function is not very fast.

Parameter array

the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.

Parameter r
Parameter g
Parameter b

base level of result, default is zero

Parameter div

division factor, default is 1.0.

Returns

the new image object


Method autocrop
Method find_autocrop

object Image.Image()->autocrop()
object Image.Image()->autocrop(int border)
object Image.Image()->autocrop(int border, object(Color) color)
object Image.Image()->autocrop(int border, int left, int right, int top, int bottom)
object Image.Image()->autocrop(int border, int left, int right, int top, int bottom, object(Color) color)
array(int) Image.Image()->find_autocrop()
array(int) Image.Image()->find_autocrop(int border)
array(int) Image.Image()->find_autocrop(int border, int left, int right, int top, int bottom)

Description

Removes "unneccesary" borders around the image, adds one of its own if wanted to, in selected directions.

"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 Image.Image.copy later.)

Parameter border
Parameter left
Parameter right
Parameter top
Parameter 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);

Returns

the new image object

See also

Image.Image.copy


Method bitscale

object Image.Image()->bitscale(float factor)
object Image.Image()->bitscale(float xfactor, float yfactor)

Description

scales the image with a factor, without smoothing. This routine is faster than scale, but gives less correct results

Parameter factor

factor to use for both x and y

Parameter xfactor
Parameter yfactor

separate factors for x and y

Returns

the new image object


Method bitscale

object Image.Image()->bitscale(int newxsize, int newysize)
object Image.Image()->bitscale(0, int newysize)
object Image.Image()->bitscale(int newxsize, 0)

Description

scales the image to a specified new size, if one of newxsize or newysize is 0, the image aspect ratio is preserved.

Parameter newxsize
Parameter newysize

new image size in pixels

Returns

the new image object

Note

resulting image will be 1x1 pixels, at least


Method box

object Image.Image()->box(int x1, int y1, int x2, int y2)
object Image.Image()->box(int x1, int y1, int x2, int y2, int r, int g, int b)
object Image.Image()->box(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)

Description

Draws a filled rectangle on the image.

original ->box
(40,10,
10,80,
0,255,0)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

box corners

Parameter r
Parameter g
Parameter b

color of the box

Parameter alpha

alpha value

Returns

the object called


Method cast

string Image.Image()->cast(string type)

Description

Cast the image to another datatype. Currently supported are string ("rgbrgbrgb...") and array (double array of Image.Image.Color objects).

See also

Image.Image.Color, Image.Image.X


Method change_color

object Image.Image()->change_color(int tor, int tog, int tob)
object Image.Image()->change_color(int fromr, int fromg, int fromb, object inttor, int tog, int tob)

Description

Changes one color (exakt match) to another. If non-exakt-match is preferred, check Image.Image.distancesq and Image.Image.paste_alpha_color.

Parameter tor
Parameter tog
Parameter tob

destination color and next current color

Parameter fromr
Parameter fromg
Parameter fromb

source color, default is current color

Returns

a new (the destination) image object


Method circle

object Image.Image()->circle(int x, int y, int rx, int ry)
object Image.Image()->circle(int x, int y, int rx, int ry, int r, int g, int b)
object Image.Image()->circle(int x, int y, int rx, int ry, int r, int g, int b, int alpha)

Description

Draws a circle on the image. The circle is not antialiased.

original ->circle
(50,50,
30,50,
0,255,255)

Parameter x
Parameter y

circle center

Parameter rx
Parameter ry

circle radius in pixels

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method clear

void Image.Image()->clear()
void Image.Image()->clear(int r, int g, int b)
void Image.Image()->clear(int r, int g, int b, int alpha)

Description

gives a new, cleared image with the same size of drawing area

original ->clear
(0,128,255)

Parameter r
Parameter g
Parameter b

color of the new image

Parameter alpha

new default alpha channel value

See also

Image.Image.copy, Image.Image.clone


Method clone

object Image.Image()->clone()
object Image.Image()->clone(int xsize, int ysize)
object Image.Image()->clone(int xsize, int ysize, int r, int g, int b)
object Image.Image()->clone(int xsize, int ysize, int r, int g, int b, int alpha)

Description

Copies to or initialize a new image object.

original clone clone(50,50)

Parameter xsize
Parameter ysize

size of (new) image in pixels, called image is cropped to that size

Parameter r
Parameter g
Parameter 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).

Parameter alpha

new default alpha channel value

Returns

the new object

See also

Image.Image.copy, Image.Image.create


Method color

object Image.Image()->color()
object Image.Image()->color(int value)
object Image.Image()->color(int r, int g, int b)

Description

Colorize an image.

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);

Parameter r
Parameter g
Parameter b

red, green, blue factors

Parameter value

factor

Returns

the new image object

See also

Image.Image.grey, Image.Image.`*, Image.Image.modify_by_intensity


Method copy

object Image.Image()->copy()
object Image.Image()->copy(int x1, int y1, int x2, int y2)
object Image.Image()->copy(int x1, int y1, int x2, int y2, int r, int g, int b)
object Image.Image()->copy(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)

Description

Copies this part of the image. The requested area can be smaller, giving a cropped image, or bigger - the new area will be filled with the given or current color.

original ->copy
(5,5,
XSIZE-6,YSIZE-6)
->copy
(-5,-5,
XSIZE+4,YSIZE+4,
10,75,10)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

The requested new area. Default is the old image size.

Parameter r
Parameter g
Parameter b

color of the new image

Parameter alpha

new default alpha channel value

Returns

a new image object

Note

Image.Image.clone(void) and Image.Image.copy(void) does the same operation

See also

Image.Image.clone, Image.Image.autocrop


Method create

void Image.Image()->create()
void Image.Image()->create(int xsize, int ysize)
void Image.Image()->create(int xsize, int ysize, object(Color) color)
void Image.Image()->create(int xsize, int ysize, int r, int g, int b)
void Image.Image()->create(int xsize, int ysize, int r, int g, int b, int alpha)
void Image.Image()->create(int xsize, int ysize, string method, object(method) ...)

Description

Initializes a new image object.

Image.Image
(XSIZE,YSIZE)
Image.Image
(XSIZE,YSIZE,255,128,0)

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:
  "Image.Image.test,"
  "Image.Image.gradients"
  "Image.Image.noise"
  "Image.Image.turbulence"
  "Image.Image.random"
  "Image.Image.randomgrey"
specials cases:
  "Image.Image.tuned_box" (coordinates is automatic)

Parameter xsize
Parameter ysize

size of (new) image in pixels

Parameter color
Parameter r
Parameter g
Parameter b

background color (will also be current color), default color is black

Parameter alpha

default alpha channel value

Bugs

SIGSEGVS can be caused if the size is too big, due to unchecked overflow - (xsize*ysize)&MAXINT is small enough to allocate.

See also

Image.Image.copy, Image.Image.clone, Image.Image.Image


Method distancesq

object Image.Image()->distancesq()
object Image.Image()->distancesq(int r, int g, int b)

Description

Makes an grey-scale image, for alpha-channel use.

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

Parameter r
Parameter g
Parameter b

red, green, blue coordinates

Returns

the new image object

See also

Image.Image.select_from


Method gamma

object Image.Image()->gamma(float g)
object Image.Image()->gamma(float gred, object floatggreen, object floatgblue)

Description

Calculate pixels in image by gamma curve.

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);

Parameter g
Parameter gred
Parameter ggreen
Parameter gblue

gamma value

Returns

a new image object

See also

Image.Image.grey, Image.Image.`*, Image.Image.color


Method getpixel

array(int) Image.Image()->getpixel(int x, int y)

Description

Parameter x
Parameter y

position of the pixel

Returns

color of the requested pixel -- ({int red,int green,int blue})


Method gradients

int Image.Image()->gradients(array(int) point, object ...)
int Image.Image()->gradients(array(int) point, object ..., object floatgrad)

Description

original 2 color
gradient
10 color
gradient
3 colors,
grad=4.0
3 colors,
grad=1.0
3 colors,
grad=0.25

Returns

the new image


Method grey

object Image.Image()->grey()
object Image.Image()->grey(int r, int g, int b)

Description

Makes a grey-scale image (with weighted values).

original ->grey(); ->grey(0,0,255);

Parameter r
Parameter g
Parameter b

weight of color, default is r=87,g=127,b=41, which should be pretty accurate of what the eyes see...

Returns

the new image object

See also

Image.Image.color, Image.Image.`*, Image.Image.modify_by_intensity


Method rgb_to_hsv
Method hsv_to_rgb

object Image.Image()->rgb_to_hsv()
object Image.Image()->hsv_to_rgb()

Description

Converts RGB data to HSV data, or the other way around. When converting to HSV, the resulting data is stored like this: pixel.r = h; pixel.g = s; pixel.b = v;

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();
 

Returns

the new image object


Method invert

object Image.Image()->invert()

Description

Invert an image. Each pixel value gets to be 255-x, where x is the old value.

original ->invert(); ->rgb_to_hsv()->invert()->hsv_to_rgb();

Returns

the new image object


Method line

object Image.Image()->line(int x1, int y1, int x2, int y2)
object Image.Image()->line(int x1, int y1, int x2, int y2, int r, int g, int b)
object Image.Image()->line(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)

Description

Draws a line on the image. The line is not antialiased.

original ->line
(50,10,
10,50,
255,0,0)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

line endpoints

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method map_closest
Method map_fast
Method map_fs
Method select_colors

object Image.Image()->map_closest(array(array(int)) colors)
object Image.Image()->map_fast(array(array(int)) colors)
object Image.Image()->map_fs(array(array(int)) colors)
array Image.Image()->select_colors(int num)

Description

Compatibility functions. Do not use!

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);


Method modify_by_intensity

object Image.Image()->modify_by_intensity(int r, int g, int b, int|array(int) ... vn)

Description

Recolor an image from intensity values.

For each color an intensity is calculated, from r, g and b factors (see Image.Image.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}));

Parameter r
Parameter g
Parameter b

red, green, blue intensity factors

Parameter v1
Parameter vn

destination color

Returns

the new image object

See also

Image.Image.grey, Image.Image.`*, Image.Image.color


Method outline
Method outline_mask

object Image.Image()->outline()
object Image.Image()->outline(int olr, int olg, int olb)
object Image.Image()->outline(int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object Image.Image()->outline(array(array(int)) mask)
object Image.Image()->outline(array(array(int)) mask, int olr, int olg, int olb)
object Image.Image()->outline(array(array(int)) mask, int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object Image.Image()->outline_mask()
object Image.Image()->outline_mask(int bkgr, int bkgg, int bkgb)
object Image.Image()->outline_mask(array(array(int)) mask)
object Image.Image()->outline_mask(array(array(int)) mask, int bkgr, int bkgg, int bkgb)

Description

Makes an outline of this image, ie paints with the given color around the non-background pixels.

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

Parameter mask

mask matrix. Default is ({({0,1,0}),({1,1,1}),({0,1,0})}).

Parameter olr
Parameter olg
Parameter olb

outline color. Default is current.

Parameter bkgr
Parameter bkgg
Parameter bkgb

background color (what color to outline to); default is color of pixel 0,0.

Parameter div

division factor, default is 1.0.

Returns

the new image object

Note

no antialias!


Method write_lsb_rgb
Method write_lsb_grey
Method read_lsb_rgb
Method read_lsb_grey

object Image.Image()->write_lsb_rgb(string what)
object Image.Image()->write_lsb_grey(string what)
string Image.Image()->read_lsb_rgb()
string Image.Image()->read_lsb_grey()

Description

These functions read/write in the least significant bit of the image pixel values. The _rgb() functions read/write on each of the red, green and blue values, and the grey keeps the same lsb on all three.

The string is nullpadded or cut to fit.

Parameter what

the hidden message

Returns

the current object or the read string


Method select_from

object Image.Image()->select_from(int x, int y)
object Image.Image()->select_from(int x, int y, int edge_value)

Description

Makes an grey-scale image, for alpha-channel use.

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 Image.Image.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.

Parameter x
Parameter y

originating pixel in the image

Returns

the new image object

See also

Image.Image.distancesq


Method setcolor

object Image.Image()->setcolor(int r, int g, int b)
object Image.Image()->setcolor(int r, int g, int b, int alpha)

Description

set the current color

Parameter r
Parameter g
Parameter b

new color

Parameter alpha

new alpha value

Returns

the object called


Method setpixel

object Image.Image()->setpixel(int x, int y)
object Image.Image()->setpixel(int x, int y, int r, int g, int b)
object Image.Image()->setpixel(int x, int y, int r, int g, int b, int alpha)

Description

original ->setpixel
(10,10,
255,0,0)

Parameter x
Parameter y

position of the pixel

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method test

object Image.Image()->test()
object Image.Image()->test(int seed)

Description

Generates a test image, currently random gradients.

original ->test() ...and again

Returns

the new image

Note

May be subject to change or cease without prior warning.

See also

Image.Image.gradients, Image.Image.tuned_box


Method threshold

object Image.Image()->threshold()
object Image.Image()->threshold(int level)
object Image.Image()->threshold(int r, int g, int b)
object Image.Image()->threshold(object(Color) color)

Description

Makes a black-white image.

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);

Returns

the new image object

Note

The above statement "any ..." was changed from "all ..." in Pike 0.7 (9906). It also uses 0,0,0 as default input, instead of current color. This is more useful.

See also

Image.Image.grey


Method tuned_box

object Image.Image()->tuned_box(int x1, int y1, int x2, int y2, array(array(int)) corner_color)

Description

Draws a filled rectangle with colors (and alpha values) tuned between the corners.

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)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

rectangle corners

Parameter 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).

Returns

the object called


Method xsize

int Image.Image()->xsize()

Returns

the width of the image


Method ysize

int Image.Image()->ysize()

Returns

the height of the image


Method apply_max

object Image.Image()->apply_max(array(array(int|array(int))) matrix)
object Image.Image()->apply_max(array(array(int|array(int))) matrix, int r, int g, int b)
object Image.Image()->apply_max(array(array(int|array(int))) matrix, int r, int g, int b, int|float div)

Description

This is the same as apply_matrix, but it uses the maximum instead.

This function is not very fast.

Parameter array

the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.

Parameter r
Parameter g
Parameter b

base level of result, default is zero

Parameter div

division factor, default is 1.0.

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions


Method make_ascii

string Image.Image()->make_ascii(object orient1, object objectorient2, object objectorient3, object objectorient4, object int|voidxsize, object int|voidysize)

Description

This method creates a string that looks like the image. Example:

   //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);

Returns

some nice acsii-art.

Note

experimental status; may not be exact the same output in later versions

      |      /    -    \
     hue=  0     64   128  192  (=red in an hsv image)

See also

Image.Image.orient, Image.Image.orient4


Method match

object Image.Image()->match(int|float scale, object objectneedle)
object Image.Image()->match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert)
object Image.Image()->match(int|float scale, object objectneedle, object objecthaystack_avoid, object intfoo)
object Image.Image()->match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert, object objecthaystack_avoid, object intfoo)

Description

This method creates an image that describes the match in every pixel in the image and the needle-Image.

   new pixel value =
     sum( my_abs(needle_pixel-haystack_pixel))

The new image only have the red rgb-part set.

Parameter scale

Every pixel is divided with this value. Note that a proper value here depends on the size of the neadle.

Parameter needle

The image to use for the matching.

Parameter 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.

Parameter needle_cert

The same, but for the needle-image.

Parameter foo
Parameter 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.

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions

See also

Image.Image.phasev, Image.Image.phaseh


Method phaseh
Method phasev
Method phasevh
Method phasehv

object Image.Image()->phaseh()
object Image.Image()->phasev()
object Image.Image()->phasevh()
object Image.Image()->phasehv()

Description

Draws images describing the phase of the current image. phaseh gives the horizontal phase and phasev the vertical phase.

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()

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions

Bugs

0 should not be set as explained above.


Method polyfill

object Image.Image()->polyfill(array(int|float) ... curve)

Description

fills an area with the current color

Parameter curve

curve(s), ({x1,y1,x2,y2,...,xn,yn}), automatically closed.

If any given curve is inside another, it will make a hole.

Returns

the current object

Note

Lines in the polygon may not be crossed without the crossing coordinate specified in both lines.

Bugs

Inverted lines reported on Intel and Alpha processors.

See also

Image.Image.setcolor


Method paste

object Image.Image()->paste(object image)
object Image.Image()->paste(object image, int x, int y)

Description

Pastes a given image over the current image.

Parameter image

image to paste (may be empty, needs to be an image object)

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

Image.Image.paste_mask, Image.Image.paste_alpha, Image.Image.paste_alpha_color


Method paste_alpha

object Image.Image()->paste_alpha(object image, int alpha)
object Image.Image()->paste_alpha(object image, int alpha, int x, int y)

Description

Pastes a given image over the current image, with the specified alpha channel value.

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.

Parameter image

image to paste

Parameter alpha

alpha channel value

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

Image.Image.paste_mask, Image.Image.paste, Image.Image.paste_alpha_color


Method paste_alpha_color

object Image.Image()->paste_alpha_color(object mask)
object Image.Image()->paste_alpha_color(object mask, int x, int y)
object Image.Image()->paste_alpha_color(object mask, int r, int g, int b)
object Image.Image()->paste_alpha_color(object mask, int r, int g, int b, int x, int y)
object Image.Image()->paste_alpha_color(object mask, object(Color) color)
object Image.Image()->paste_alpha_color(object mask, object(Color) color, int x, int y)

Description

Pastes a given color over the current image, using the given mask as opaque channel.

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.

Parameter mask

mask image

Parameter r
Parameter g
Parameter b

what color to paint with; default is current

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called