I'm generating new blending modes for Krita

Right now, I have 11 new blending modes created for Krita (10 working as expected, but interpolate blending modes still has issues with integer images because float aren’t accepted in integer images. Still, interpolate working beautifully on float images.). I’ll be creating 4 quadratic mode next to the reflect, heat, glow, and freeze - https://in.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/52513/versions/57/screenshot.png .That means I’ll end up creating 15 new blending modes for Krita.

EDIT: Found what extremity is, that means 16 new blending modes for Krita.

It turns out that not all quadratic modes are useful for 16-bit and higher. That’s because of their behaviors. Heat and freeze makes images extremely dark overall to the point of non-usefulness, but I believe the 4 new blending modes gets around those issues. Glow, and Reflect works beautifully on all color depth.

Here are some of the codes so far (heat and freeze issues with -inf has been fixed on my end.)

There’s also these things which I have no idea what they’re on about when researching blending modes -
source - http://myplace.frontier.com/~chooks9592/manual/html/imblend.html
RANDOMIZED MODES:
The ‘bomb’ mode applies a random piecewise-linear blend function of size AMOUNTxAMOUNT
The ‘bomblocked’ mode is the same as ‘bomb’, but without channel-independence
The ‘hardbomb’ mode applies a random piecewise-constant blend function of size AMOUNTxAMOUNT
Using the ‘verbose’ key with these modes will display the transformation matrix as a command string.
These can then be used with the mesh modes to reproduce a particular random blend.

Any guess on bomb blending modes?

1 Like

Two possibilities come to mind; blending between random patches rather than whole image, or the blend function itself is random per patch. Impossible to know without an algorithm or code to look at though…

Edit: it could also be a single random function applied to the entire image area, since it mentions being able to view the tranform matrix (that might give clues). Is it possible to ask the author?

Edit2: hah OK, answering too quickly I think :slight_smile:
What you’re asking is probably how to generate the matrix/patch shown at the bottom right of your first link. And now of course I run out of time! Perhaps somebody else can look now…

Awesome stuff. It is hard to wrap my mind around the Matlab figure. When you are done, it would be great if you could contribute a series of blended images and description. :wink:

I don’t think those random modes are terribly complex. as it says piecewise constant so for hardbomb something like “a<n1 AND b<n2 then v1” etc. (could be simplified with addition/subtraction probably). A quick and dirty G’MIC equivalent map can be used for testing:

gmic 256,256,1,1,x 256,256,1,1,255-y blend hardlight +f "i%16<1&&i>0?255:0" gcd_spectral.. max

hardlight

Perhaps I’ll take a closer look tomorrow, a bit too tired now :slight_smile:

Description can be found here - ⚙ D13624 Additional Blending Mode - Softlight (Pegtop-Delphi) ,Phoenix, Penumbra Blending Modes series, Negation, Signed Difference, and Interpolate

I’ll attach some images -

Reeze Blend Mode
Reeze

Penumbra A Blending Mode
Penumbra%20B

Frect Blending Mode
Frect

Penumbra B Blending Mode
Penumbra%20A

Reflect Blending Mode
ReflectGleat

Softlight (Pegtop-Delphi) Blending Mode
Softlight%20Pegtop%20Delphi

Freeze Blending Mode
Freeze

Heat Blending Mode
Heat

Helow Blending Mode
Helow

Interpolate Blending Mode
Interpolate

I don’t know when I would be using Krita or these modes but it is awesome to follow your progress.

I’m not sure about the quadratic modes myself, but I do think many of the new blending modes are useful. Here’s a document which shows Penumbra series, Softlight Pegtop, and quadratic modes compared with other blending modes - ⚙ D13624 Additional Blending Mode - Softlight (Pegtop-Delphi) ,Phoenix, Penumbra Blending Modes series, Negation, Signed Difference, and Interpolate . - Download .pdf to view.

If you look at these blending modes, you’ll note Reflect, and Glow are quadratic forms of color dodge. And then, you’ll note that the last 2 quadratic modes are arguably showing better properties than many lighten varient. They’re smooth (with minor discontinuity when zoomed in). Besides, the last and first two quadratic modes, they don’t show a useful property. Interpolate is basically a better version of average blend mode, so I’m not showing that there.

I actually think there’s a case to be made that the last two quadratic modes can be better than existing modes like overlay, color dodge and so on because they are not as discontinuous. For penumbra, it only usage seem to be on the painting side because of the fact that colors gets desaturated, and penumbra seem to emulate very light penumbra of objects with soft lights.

My PlayRaws entries often suffer when I try my hand at blending, though I never point out that I am unsatisfied with the results because it is hard to describe in words what I actually wanted to do.

For me, the right mode is more of an intuitive feeling rather than a mathematical or descriptive one. I.e., in GIMP, I usually flip through every blend mode to see which one matches my expectation.

Sorry, I am kind of confused when you use last two, first one, etc. :sweat_smile:

Well, I was talking about Helow, and Frect blending modes. They look a lot better than the existing lighten mode. There’s only one downside to those. The dark areas particularly can get dark (not as dark as vivid light). But by individual modes, their properties are much better and more consistent than every other lighten blend modes. I also looked at Pegtop-Delphi, and there is a slight advantage of being able to preserve details better on bright area.

I noticed someone referring to my junk on the Mathworks FEX, so I figured I’d touch on some of the questions and comments here and on Phabricator.

Regarding intent and utility of particular modes:
We need to differentiate between general classes of working images. Consider images such as photographs and life drawings or paintings. These referential images depict objects of which the viewer has some abstract preconceptions. To apply drastic changes (e.g. local intensity inversions or hue rotation) will result in an image which is at odds with the expected perception of the objects or image space. As I’ve said elsewhere, seeing a person with a purple face doesn’t make any sense to a pattern-recognition machine built on earth. It’s easy to see many of these modes as horribly useless when considering this sort of application.

As the MIMT is heavily focused on image analysis, obfuscation, and the generation of abstract images, many of the blend modes featured in IMBLEND are tailored for use on images which are non-referential. Blending two wholly abstract image fields in ridiculous or entirely random manners does not produce the same objectionable response in the viewer as it would with photographic content. To the point of image analysis, also consider that many blend modes are simply more utilitarian tools than aesthetically important effects. Consider modes such as ‘difference’, ‘divide’, ‘exclusion’ and many of the other modes in the “mathematical” or “arithmetic” category.

I’m hesitant to try rationalizing propriety based on the assumption that all users are painters or that all content is referential. If a superabundance of blending modes is seen as a problem for users who only need the “big five”, then I’m inclined to say that the solution is a user-configurable menu instead of restricted availability. I’m driven to that opinion, as IMBLEND was my way of getting tools that Krita and GIMP did not offer.

Regarding ‘bomb’ modes:
To understand ‘bomb’, first understand ‘mesh’. Consider the image of contour maps linked above. Intuitively, these contours describe a height map – or surface, which in turn represents a transfer function mapping two inputs to a single output within a unit cube. Consider any particular intuitive blend mode such as ‘average’. While this planar surface is normally expressed algebraically, we can instead approximate it using a 2-D map of arbitrary resolution and some interpolation. Given enough resolution and a means to directly apply this representative map as a transfer function, we can approximate any blend mode using a single common approach.

In IMBLEND, the ‘overlay’ and ‘hardlight’ complements use this mesh method to produce fractional iteratives of the named blend instead of doing expensive iterated algebraic blending. Besides improving computational efficiency (keep in mind that I’m operating in Matlab), the big benefit to this approach is that it allows the application of arbitrary or adjustable blends without needing to derive an algebraic expression. A user who can intuit a contour map can easily generate their own or adapt one from an existing algebraic mode.

The ‘bomb’ modes are a demonstration of both concepts discussed here. These modes simply generate random surfaces to apply as if they were transfer functions. The resolution can be specified via an extra AMOUNT parameter, and the interpolation is rolled into the case (‘bomb’ uses linear interpolation; ‘hardbomb’ uses nearest-neighbor interpolation). These modes are almost exclusively useful for operating on abstract non-referential images. The name implies what they conceptually do to the object content in referential images. It’s worth noting that in IMBLEND, this random transfer function is volatile. Invoking the blend routine again will produce different results.

For a single-channel image, we can reduce ‘bomb’ to the pseudocode:

	% generate reference grids to describe the domain of the transfer function
	c=0:1/amount:1;
	[gridb gridf]=meshgrid(c,c);

	% generate a random square transfer function of specified size
	tf = rand([amount amount]);

	% stretch range of tf to fill the unit interval
	mn = globalmin(tf);
	mx = globalmax(tf);
	tf = (tf-mn)/(mx-mn);

	% do 2D interpolation using grids, transfer function, and input image data
	result = interp2(gridb,gridf,tf,BG,FG,'bilinear');

Now we come to what I feel is one of the most important and unique aspects of IMBLEND, and what I feel is one of the biggest limitations in trying to apply some of its modes elsewhere. IMBLEND provides an extra scaling/configuration parameter for many blend modes. To my knowledge, this is not something implemented in Krita/GIMP or elsewhere. I don’t need to go on about why I think it’s useful; simply understand that I do, and understand that many of these blend modes owe their existence to the availability of that scaling/configuration parameter. Without the ability to specify the resolution of the mesh used in ‘bomb’, it becomes very difficult to use. The ‘mesh’ mode uses this configuration parameter as its means of accepting captured or user-derived transfer functions. Without an extra parameter, ‘mesh’ loses its primary utility, and ‘bomb’ is difficult and its results are volatile.

Regarding quadratic modes:
I’m surprised anyone is considering these. For what it’s worth, I think that ‘easydodge’, ‘easyburn’, and ‘flatlight’ have broader utility. The fact that most quadratic modes are largely saturated (i.e. a large percentage of their domain maps to either 1 or 0) makes them difficult to use except in the non-referential universe. As an aside, handling infinite slope at the steep corners is kind of a gamble; I can’t say my choices are definitive or even appropriate. Some of these modes will produce complex-valued output if their input range extends beyond [0 1] (don’t know if that’s even a problem in your environment).

Wherein I stop:
I’ve been on a long dry spell from painting and drawing, and my experience with Krita is limited. I’m curious to see what has been added. I’m curious if anyone has had a chance to run some images through IMCOMPOSE. It’s not exactly a friendly UI, and I doubt anyone wants to deal with Matlab, but it might be convenient to just browse the blends with your own familiar test images to see if they’re of any use or to see if the parameterization is of value.

2 Likes

Hi,

It is a surprise to see you here. The point of those quadratic modes is mainly to have artists have the option of painting with different falloff when shading objects. That can provide ease of use, and make painting a bit more efficient. While I do acknowledge other blending modes do exists, and most people may not need to use a lot, I do also acknowledge that there are some artists that would appreciate (like myself) different falloff when painting. This can be even useful for photography as you can alter the outcome by altering the overall looks.

I have made so much more than just quadratic modes. - Dropbox - File Deleted

That’s the list to most if not all blending modes I have made for Krita. Some points listed :

  • Penumbra is the same as soft dodge, and soft burn of the Pegtop website as Penumbra fits these blending modes better than their original name. Penumbra C, and D are based off arctangent.

  • Also, I added similar softlight modes to Krita as they’re functionally better than the ones that is offered in Krita as they don’t have a break when posterized.

  • Binary modes is really good for generating album cover art, and glitch art.

  • As for quadratic modes - Frect, and Helow don’t really go over 1 or under 0. All the other blending modes does, but they’re clamped in integer modes in Krita, but I can definitely force them to go over 0, and under 1 if I wanted to.

That being said, I’m wondering what’s the equation for bright, dark, superlight, easy dodge, easy burn, contrast, and flatlight. I would like to know so that I can those to Krita, and to allow artists to have more choices of blending modes, and to see if any of those are useful. Mesh probably wouldn’t be useful for anything other than strange abstract art.

EDIT: I may have a way to stimulate mesh with the use of modulus operation.

Thank you for explaining bomb blending mode. It’s probably possible with G’MIC as G’MIC enables us to bypass the problem of lacking adjustable factor for blending modes. @Joan_Rake1 , just calling you out here to see if this is of interest. Bomb, and Hard Bomb might be very interesting for abstract art.

With all this talking of blowing things up in the maritime museum thread, I might get a visit from some strange men in a van!

I already have a random deformation G’MIC command called jr_deform which does what I believe you’re talking about. I’ll be adding a GUI command for it when I update my .gmic file in the community repo.

image

image

That’s not what bomb blending modes does. If you take two grayscale layers with gradient that goes from 0.0F and 1.0F that are perpendicular to each other, you should get a output like the one observed in the first link. Hardbomb reduces color, but there is a irregular and smooth transition in the regular bomb mode.

I have absolutely no idea then and I need some sleep right now. I can try to recreate these filters in G’MIC.

I suppose using these for painting is something I didn’t really consider. I can’t exactly paint in Matlab. That said, I did use them a lot in the past.
The fact that IMBLEND is such a collection should tell you that I tend to assume someone will find a use for them even if I do not.

That said, I kind of figured you already had the code if you had the contour maps. The mathworks site might require an account for downloads, but it’s not dependent on having a matlab license or anything.
https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/93c2fff1-27b9-491a-9749-3e15ee2cac00/5deb54a1-1fda-4f08-a76d-da080bff6374/packages/zip
The contents of the archive can be browsed under the ‘functions’ tab.

Or I guess I can try to attach the archive.
blendtools.zip (2.6 MB)

If anyone is crazy enough to try running it in Matlab, just get the MIMT, since that’s the parent project and it includes the composition GUI.

I should point out that I’m hardly a programmer; you can probably tell by the fact that I tried doing this in Matlab of all things. MIMT is just a side-product of my image manipulation hobbies. If it looks ad-hoc or half-baked, that’s kind of how it started.

Joan, let me try to better describe ‘mesh’ and ‘bomb’:

‘mesh’ is a universal blend mode. Given enough resolution in its transfer function array, it can approximate any other blend mode, or it can effect arbitrary variations thereof. The user needs no algebra to modify things either. The transfer function is a simple 2D (or NxNx3) array, which can be manipulated like any other monochrome or RGB image.

Consider the example

% load test images
FG=imread('sources/pinlightblend.jpg');
BG=imread('sources/pinlightbase.jpg');

% generate small (10x10) gradients as test images
[bg fg]=meshgrid(linspace(0,1,10));

% generate a 10x10 transfer function array/image/thing for the 'overlay' mode
example_tf=imblend(fg,bg,1,'overlay');

% blend the image using the same mode
native_blend=imblend(FG,BG,1,'overlay');

% emulate 'overlay' using 'mesh' mode with the example transfer function
emulated_blend=imblend(FG,BG,1,'mesh',example_tf);

% compare the results
imcompare('native_blend','emulated_blend','invert')

Even for a 10x10 array, the approximation is reasonable for a smooth mode like ‘overlay’

‘bomb’ is basically what happens when you feed ‘mesh’ a random configuration array.

% each random blend is different
ashes1=imblend(FG,BG,1,'bomb');
ashes2=imblend(FG,BG,1,'bomb');

% changing the tf size increases likelihood of inversions
ashes3=imblend(FG,BG,1,'bomb',6);
ashes4=imblend(FG,BG,1,'bomb',10);

imshow2('cat(2,cat(1,ashes1,ashes2),cat(1,ashes3,ashes4))','invert','tools')

Again, ‘bomb’ is well suited to working with layered compositions of abstract content, where it doesn’t run at odds with expectations. It sometimes leads me in unexpected directions.

… i guess that wasn’t succinct at all.

I should add:
‘mesh’ and ‘bomb’ use bilinear interpolation to smooth the tf array
‘hardmesh’ and ‘hardbomb’ simply use nearest-neighbor interpolation

% since comparison requires repeatability, let's generate a couple random transfer function arrays
% and use 'mesh' and 'hardmesh' to effect the same results: (2x2x3 tf and 5x5x3 tf)
tf1=cat(3,[1 0.099021;0 0.25673],[0.79458 0;0.99999 0.66659],[0.76559 0.86561;1 0]);
tf2=cat(3,[0.98707 0.9984 0.0043272 0.21181 0.55072 0.71137;0.44406 ...etc ]);

ashes1=imblend(FG,BG,1,'mesh',tf1);
ashes2=imblend(FG,BG,1,'mesh',tf2);
ashes3=imblend(FG,BG,1,'hardmesh',tf1);
ashes4=imblend(FG,BG,1,'hardmesh',tf2);

imshow2('cat(2,cat(1,ashes1,ashes2),cat(1,ashes3,ashes4))','invert','tools')

I been looking at the codes in imblend.m, and I really am not understanding it.

		case 'superlight' % use piecewise-pnorm to create a superelliptic contrast mode
			amount=max(1,amount);
			if amount==1;
				R=2*M+I-1;
			else				
				lo=M<0.5;
				R=(1-((1-I).^amount + (1-2*M).^amount).^(1/amount)).*lo ...
					+ ((I.^amount + (2*M-1).^amount).^(1/amount)).*~lo;
			end

Meanwhile, I actually have found some new blending modes with the source I just got thanks to you.

EDIT: What with the flagged posts? I know DGM should use the edit function.

‘superlight’ is one of the modes that relies heavily on its scaling/configuration parameter, ‘amount’. In this case, as in ‘pnorm’, the configuration parameter controls the order of the p-norm, changing the shape of the level curves of the transfer function.

Consider the parameter sweeps for ‘pnorm’ and ‘superlight’ (i guess pdf attachments aren’t allowed):
http://myplace.frontier.com/~chooks9592/manual/contour_plots.pdf

The level curves shown by the contour plots for ‘pnorm’ are quadrants of superellipses. For the default parameter value, amount=1, the curves are simple diagonals (quadrants of a rhombus). in the case of ‘superlight’, the whole thing becomes equivalent to ‘linear light’, and we can simplify the math.

The second case in ‘superlight’ is the more general calculation. As things are superelliptic, we can effect a range of results between those available from more conventional modes.

From the synopsis:,

SUPER LIGHT:
Piecewise union of functions whose level curves are superelliptic. Allows transition between
behaviors of other blend modes. Useful in place of ‘pin light’ if a soft threshold is desired.
For AMOUNT=1, behavior matches ‘linear light’
For AMOUNT=2, behavior is similar to ‘hard light’
For AMOUNT>>2, behavior approaches ‘pin light’

EDIT:
hahaha aaaahhh. This is why i hardly communicate anymore.

1 Like

Now I understand the equations over there. If there is a condition like lo, that would mean at the end *lo implies that when lo meets criteria, the output is based on equation based on the *lo. Amount is just a modifying value. I think I can proceed to making new blending modes for Krita. They’re going to be using fixed amount though.

I think the reason why GIMP, PS, Krita, and so on doesn’t use amount is 1) lack of foresight, 2) most people don’t need it, 3) it would take a huge overtaking to enable amount mode for those softwares, 4) huge codebase prevents the overtaking attempt to happen. Amount would be really nice, but it’s just not going to happen in a long while.