Some Programs for Image Editing

- giving the best possible precision and quality

Part One

Crop, size and transparency


    

In the left picture we have made the white sky transparent and placed the picture over the picture above.


ShowBMP


Download ShowBMP

  The program is put in the same folder as the pictures to be processed. The pictures must be in BMP format, and they ought to have short names, for instance "a", "b", ... or "01", "02", ... - only small letters and figures. The name of the picture is entered and Enter is pressed.

  The picture is shown instantly, but if it is large some seconds can go before the data of the picture are read (hereafter an alteration in the display can occur).

  The program is closed by Esc and the window is minimized by Pause or by clicking on the extreme right of the bar.

  Key K alternates between the screen-adapted display and full size.

  The window can be moved by pulling in the bar, or (if the picture is large and the bar is wanted outside the screen) by scrolling after pressing the key with the two arrows: one or two times for vertical and horizontal respectively.

  The size of the window is changed by pressing one of the vertical arrows and then scrolling. Fine-adjustment by the arrows.

  Click after this use of scrolling.

  The section of the picture shown is moved by scrolling: horizontally or vertically according to whether the cursor is above or below the diagonal respectively. Pressing the keys Home, End, PageUp and PageDown moves the picture to the positions farthest out (resp. left, right, top and bottom).

  After pressing Shift the steps of the scrolling are altered - for smaller pictures there are two stages, and for larger pictures three.

  By keying Q the frame of the window is removed or re-established.

  At the processing press S for save and Z for regret.

  Several pictures can be shown simultaneously. A picture is activated by clicking on it.

  By keying P the processed picture is rendered as a file (with a hyphen added to the name) and the program is closed. By keying O the actual part of the picture in the window is rendered as a file with "-screen" added to the name and the program is not closed.

  To alter the size, press key D. Then the new width or height or factor of magnification can be entered. When reducing, each pixel in the new (smaller) picture is "spread over" some pixels and parts of pixels in the original picture, and the program calculates the precise average value of the colour. When enlarging, "the domain between the pixels" is filled by using calculus of differences, and a factor is inlaid in the formula that determines the sharpness (see the theory below). The factor of sharpness is a decimal number, but when entering it has to be multiplied by 10 and the number entered must be a whole number. When the factor of sharpness is 0 the domain is filled by using linear interpolation; when it is 1 the domain is filled by using the correct formula; and when it is larger than 1 the effect of the formula is increased, but then there is a risk of discoloration.

In these two enlargements the factor is 0 and 1 respectively:

The method can be used to make a picture sharper, namely by enlarging it to (for instance) double size and using a large factor of sharpness (eg. 4), and then halving the picture. In this picture the factor has been set at 6, and this is a little on the large side:

    

  For cropping press key C and click at a place in the picture where the rectangle of cutting out can begin. Next move the cursor to a place where the rectangle can end, and fix it by right-clicking. The position and the size of the rectangle can now be fine-adjusted by the arrows, and pressing Shift alternates between the two kinds of effect. By clicking at the end corner of the rectangle (usually the lower right corner) it can be moved again, for instance after the visual domain has been changed. The width, the height and the ratio between width and height are shown on the bar.

  Transparency in a picture presupposes that a bit (representing "true" or "false") can be reserved for each pixel. As the BMP format does not allow this extra information, the picture must be accompanied by a monochrome (that is, black-and-white) picture (in BMP format). This picture is given the name of the original picture followed by a "z" (the names of the two pictures can for instance be "37a" and "37az"). When transparency is introduced in a picture, the transparent domain is coloured black and a monochrome picture (with name addition "z") is produced in which the transparent domain is white.

    

The process of introducing transparency is started by pressing key T. Then the display is altered to full size, and if there already is transparency in the picture, the transparent domain is coloured middle-grey. By scrolling, the tint of this grey can be adjusted. By left-clicking a square with centre in the position of the cursor is produced, and after this, by left-clicking, all the points within the square whose colour has a distance from the colour of the centre that is smaller than a given number, are removed. The removed points are temporarily coloured in the chosen grey tone. The size of the square is adjusted by the horizontal arrows and the distance of colour is adjusted by scrolling (small steps) and by the vertical arrows (large steps). The distance of colour (in pc) is shown on the bar. These two values have to be adjusted continuously. A press on key U extends the removal procedure to all the points in the visible section of the picture. By right-clicking, the removal procedure is temporarily suspended, and the chosen domain becomes really transparent. Likewise the procedure is suspended when the window or the section is altered. A press on key S saves the transparent domain, and key Z brings back the last picture saved. Now and then the picture should be rendered as a file (key P), and the work continued with the new picture.

When the size of a picture with transparency is changed, the same procedure is used for the transparency as for the colour values (at enlargement the sharpness factor for the transparency is 1). When altering the size of a picture with transparency, it is recommended to use the original picture (without transparency) together with the monochrome picture determining the transparency, so that the black domain is not involved in the change of size procedure - this implies that there will be miscolouring in the picture displayed, but this disappears when the size is altered.

A picture (with or without transparency) can be mixed with the background, that is, the material on the desktop behind the picture. By keying M, the picture is temporarily mixed with black, and by keying T the window disappears for a moment while the background is read. By scrolling or by using the vertical arrows, the mixing is now adjusted and the pc is written on the bar. Of course the background is completely visible through a transparent domain, but if the original picture (without transparency) exists, the transparent domain can be mixed with the background instead of the non-transparent domain: the original picture is used together with the monochrome picture, and key N is pressed instead of key M.



Part Two

Colour transformation - on the basis of the RGB values


Download Mod_RGB

This program can change the colours in a picture (in BMP format) in a way which may be regarded as the most natural and which is not possible with other picturing programs:

    

"The Origin of the Art of Painting" by Heinrich Eddelien (1830), the left picture is an Internet display.

The left picture is too dark owing to age, and we have pushed the colours in the direction opposite to the direction they have moved in the course of time.

A colour is given by its composition of the three primary colours red, green and blue, and their proportions are measured in whole numbers between 0 and 255. Accordingly all the colours correspond to the entire points in a cube with side length 256. Black has coordinates (0, 0, 0) and white has coordinates (255, 255, 255).

We choose a colour and displace all the colours in the picture towards or away from this colour. The chosen colour can be "imaginary" (that is, have RGB values that do not correspond to a colour), and the effect of two such transformations can be combined.

The operation of the program:

  The name of the picture is entered

  The numbers in the form are adjusted by scrolling or by entering new values

  When the editing is finished the new file is produced by pressing a (random) letter key - it has a hyphen added to the name

The top and the bottom column of numbers is for the first and the second chosen point respectively. Each column states the RGB values of the chosen point and a pc "displace" determining the displacement (positive/negative for moving towards/away from the point). The number "weight" between the two columns is a pc stating the distribution of the two transformations: 0 means that only the top transformation is used and 100 means that only the bottom transformation is used. Usually we need only one column; the top. The RGB values of the colour can be arbitrary, eg. (600, 500, 400) or (0, -100, 0), and if we call this point P, a displacement of n pc means that each of the colours in the picture is moved n pc towards P. For n positive/negative the contrast becomes less/larger.

When the number "weight" between the two columns is different from 0 and 100, the effect of the two transformations is combined - the weight 50 gives a picture that is the average of the two transformations. The weight can be negative or larger than 100, and it can be used to compare two transformations by letting it be alternately 0 and 100.


Examples

This black-and-white photo is toned by making a displacement towards a light brown colour, this also makes the damage less visible. In order to increase the contrast a little, this displacement is combined with a displacement away from the complementary colour of the brown:

    

This picture is too dark and bleak:

We displace strongly (-60 pc) away from the point (-40, -20, 0), and in order to adjust and tone down the colours a little, we combine (10 pc) with a displacement (-30 pc) away from the point (200, 150, 100):

In this picture the colours are displaced -120 pc away from the point (-30, -20, -30):

    


Colour transformation - on the basis of the HSL values


Download Mod_HSL

In this version of the previous program, the HSL values of the colours are used instead of the RGB values. The HSL values of a colour are (here) whole numbers from 0 to 240, and they are respectively the hue H, the saturation S and the luminosity L of the colour. The hue H is the pure colour corresponding to the colour. The primary colours red, green and blue are pure and have hue 0, 80 and 160 respectively. Every colour is produced by mixing a pure colour with white and black. Every degree of grey has saturation 0, and the pure colours have saturation 240. Black and white have luminosity 0 and 240 respectively, and the pure colours are assigned luminosity 120.

In the same way as the RGB values are associated to the points in a cube, we imagine the HSL values as associated to the points in a double cone. The pure colours correspond to the points of a circle. The points within this circle are the colours of luminosity 120, the centre being the middle-grey. We imagine the two cones as having this circle as their base and having black and white respectively as their vertex.

The principle of displacement is the same as for the cube of RGB values, and we can let the chosen points be outside the double cone, that is, let the saturation be larger than 240 and let the luminosity be negative or larger than 240. As the pure colours make up a cycle, to every whole number n we can associate a pure colour, namely the colour with hue n modulo 240. To the number -90 corresponds, ie. the pure colour with hue -90 + 240 = 150. Note that the complementary colour to the pure colour with hue n is the pure colour with hue n + 120.

As the double-cone is invariant with respect to rotation around the axis of rotation (consisting of the grey tone colours), we can "rotate" the colours in a picture. A rotation of 15 means that the red goes a little towards the orange.

Furthermore, we can adjust the saturation of the colours in the picture. The number "saturation" is measured in pc of the original saturation, and is therefore initially set to 100. If the saturation is set to 0, we get the corresponding grey tone picture.

 

Examples

In this picture we want the light to have a more reddish tint, therefore we rotate the blue a litte towards the red (-5). We also want the sun sharper, therefore we displace away from the black (-20). And we want much more saturation, we double this (200):

We want the red fern made yellow and the green more greenish:

We first rotate by 40, then the fern is made yellow, and then a displacement (-20) away from the point (170, 160, 150) gives the green the right tint:

We want this fractal desert landscape to be more natural. We want the green oasis-like preserved, but the shadowy hill sides ought to have the same tint as the sunny sides only darker, that is, the dark blue must be transformed to dark red:

We combine the effect of displacements away from two points, namely (180, 120, 130) and (0, 120, 140), both by -20 pc, but with weight -300. Furthermore, we rotate by -6 and lessen the saturation to 75 pc:



Supplement


Exact colour transformation


Download Mod_XRGB and BMP_XBMP

This program is a special version of the program "Mod_RGB" in which an other file format is used, so that it is possible to work with so large precision that frequent adjustments of the colours do not impair the picture. The program is for the professional photographer who is always finding things that could be better, but who is annoyed by having to go back to the original picture and make notes about how the picture is made up. By converting to a new, but more memory-demanding file format, it is possible to prevent the adjustments from impairing the picture. The left picture is the original picture, the picture below is a working up and the right picture is a working up of this picture in exactly the opposite direction:

    

In this case we have displaced by 80 pc towards the colour (128, 0, 0), and such a strong deformation should only be performed for the sake of the experiment: after all we do not work with maximal precision, because the file then would be too large. The larger precision goes on by multiplying the colour values by 256, so that, instead of being of the type byte (whole numbers from 0 to 255) they become of the type word (whole numbers from 0 to 256256 - 1 = 65535) - this implies that the file will be twice as big. The program "Mod_XRGB" works in the same way as "Mod_RGB", but before using the program, the picture (in BMP format) must be converted to the new format. This is done with the program "BMP_XBMP" - the new file names end with "_x.bmp". When the picture is worked up with "Mod_XRGB", the file (in _X.BMP format) is changed and at the same time the new picture is produced in BMP format with the original name followed by a hyphen.

The composition of the displacement from the point p1 with the rate α and the displacement from the point p2 with the rate β, is the displacement with the rate γ = α+β-αβ from the point p3 = (1 - κ)p1 + κp2, where κ = β/γ. This means that if we know that the actual picture is produced by a displacement from the point p1 with the rate α, and if, instead of this, we want it to be produced (from the not existing original) by a displacement from the point p3 with the rate γ, then it must be displaced from the point p2 = (1 - γ/β)p1 + (γ/β)p3 with the rate β = (γ - α)/(1 - α). Note that the opposite displacement to the displacement with the rate α, is the displacement with the rate -α/(1 - α). Thus, if we displace with the rate 0.9 (that is, 90 pc), which means that the picture becomes almost of one colour, then we can reconstruct the picture by displacing with the rate -9 (that is, -900 pc).



Mixing of two pictures


Download MixBMP

Using the mixing procedure with the program "ShowBMP" explained above, we only mix within the window. Two pictures (in BMP format) of possibly different size can be mixed with the program "MixBMP". The pictures are given the names "1" and "2". Picture "1" is regarded as the lower, but it must at least be the same size as picture "2". The mixing can be adjusted by scrolling, after pressing Shift the scrolling is in smaller steps. Picture "2" can contain transparency, and in this case it must be accompanied by a monochrome picture with the name "2z". The picture "2" can be displaced by the arrows, after pressing Shift in steps of one pixel. By keying O or P the mixed picture is produced and the program closed: P gives the whole picture "1", O gives only the part covered by "2".

Try the program on these two pictures: "1" and "2", "2z".

The following two pictures (which are the same fractal motif made by different methods) are mixed in the ratio 50 pc (press on the third to see it in full size):



A little more on transparency

Transparency is often problematic. The picture must be with no deterioration in the quality (and therefore not in JPG format), and even then the boundary between the motif to be saved and the domain outside to be removed can be unclear. For instance one would think that in a black text on a white screen, the boundary between the text and the background is sharp: the text is black and the background is white. But the text is not black, it is in grey tones in order to give the illusion of some lines being thinner than a pixel. If we therefore remove all the white and place the text on a coloured background, the thin lines will be of grey tone, but they should be of the same colour as the background only darker. We can extend the removed domain, but then the letters become thinner:

One way to solve the problem of transparency, is to make the picture twice as large, then introduce transparency, and hereafter halve the picture:

    

As an example of a paradox with transparency, we regard a picture that is composed of two colours with pixels alternating between yellow and green. We can get two, and even many different results, depending on which type of pixel we have clicked on. We can put two pictures produced in this way over another picture:

    

Such a picture, where there are jumps in the colours from pixel to pixel, is unacceptable: it has to be seen in natural size and in JPG format it will size unreasonably much. We can repair this defect by making the picture twice as large (with factor of sharpness 0) and then halving it. The jumps now disappear.

A more advanced sort of mixing consists in using a varying ratio of mixing determined by a function. This function can, for instance, be the distance to a chosen colour, so that the background is more visible the nearer the colour of the point comes to the chosen colour. This technique is possible with the text program available on the juliasets.dk/Calligraphy website.



The theory of enlargement

The enlargement of a picture is based on the following theory: If the function f(x) is differentiable, and x1 and x2 are two x-values of distance 1, and m is the point halfway between them, then f(m) is approximately given by both

f(m) = f(x1) + f'(x1)/2  and  f(m) = f(x2) - f'(x2)/2.

If we take the average value, we have that f(m) is approximately given by

f(m) = (f(x1) + f(x2))/2 + (f'(x1) - f'(x2))/4.

Now let x0, x1, x2 and x3 be 4 pixels forming up a row, for instance in the x-direction, and let f(x) be the value of one of the primary colours red, green, or blue. If m is the point halfway between x1 and x2, then f(m) will, according to the above, approximately be given by

f(m) = (f(x1) + f(x2))/2 + ((f(x2) - f(x0)) - (f(x3) - f(x1)))/8.

The first term is the average of the colours of m's two neighbour points x1 and x2, the second term is formed by the two difference coefficients (f(x2) - f(x0))/2 and (f(x3) - f(x1))/2 formed from points of distance 2.

We have to fill up a square where we know the colour values of the corners p1, p2, p3 and p4. Using the formula we can calculate the colour values of the midpoints m1, m2, m3 and m4 of the sides of the square. To the centre we associate the colour value

(f(m1) + f(m3))(f(m2) + f(m4))/(f(p1) + f(p2) + f(p3) + f(p4)).

The rest of the square is filled up by linear interpolation. The factor of sharpness is the number by which we multiply the second term above (the term with the figure 8). That this factor is 0, means that we fill up the whole square by linear interpolation.



Updated: October 2009


This site is a subsection of juliasets.dk