Subject: 2-D Gradients

From: Shlomi Fish <[email-masked]>
Date: Wed, 6 Dec 2000 08:58:27 +0200 (IST)

If anybody is familiar with the Gimp's gradient editting capabilities then
he is probably familiar with the state-of-the-art one dimensional (1-D)
gradient editting. My problem is that it's only one dimensional and does
not allow you to edit a gradient in a plane.

Does anybody know of any methodologies and algorithms for creating a
two-dimensional gradient editting. I.e: I will be able to define points
and shapes on the plane with colors that correspond to those handles, and
then use blending methods between them, so that I'll eventually have a
gradient that spreads across the 2-D plane.

The question is: how do I do it?

When I asked Omer Mussaev about it, he suggested that I take the courses
"Artificial Intelligence" and "Game Theory" in the Technion. While, they
may help, this seems like something that is related to computer graphics
or image processing. 

Today I tried to find somebody who can help me with that within the EE
faculty of the Technion but I reached a dead end when I discovered that
the engineer of the image processing lab was absent because he was sick. 

A lecturer who specializes in computer graphics said 2-D gradients had
nothing to do with computer graphics and that in computer graphics they
discuss "normals". Even though it was her office hours, she refused to
tell me what was the difference between a gradient and a normal, because
it was not related to my concurrent studies. There was no one else waiting
to talk to her, BTW. Maybe I should try in the CS faculty, but the fact is
that I'm not a CS or a Computer Engineering student.

So, if anybody can enlighten me or point to a reference or link about it,
please do.

TIA,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked] 
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

The prefix "God Said" has the extraordinary logical property of 
converting any statement that follows it into a true one.

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 6 Dec 2000 11:17:04 +0200

> may help, this seems like something that is related to computer graphics

Then following his lead, I suggest you take the "Physics 2M" course (consider
your 2D objects conductors, and see how the electric field positions itself
between them) and "Partial Differential Equations" (you're looking for a
f(x,y) that has boundary conditions on the borders of the given objects and
that should remain differentiable throughout the plane). :)

Seriously, it depends on what exactly you're looking for this "gradient" to
be. A simple solution (although it is simple conceptually, you'll have to
think of an efficient algorithm for implementing it - I didn't try to think of
one) is simple interpolation: given a point (x,y) in the plane, and N objects
in the plane with "colors" x[i], find the distance of (x,y) to each of these
objects (the distance of the point to an object is the minimum of the distances
of the point to any of the object's points), and then do a simple weighted
avergage of these colors, weighted according to relative distance. You'll
want your method to degenerate to the usual 1D case, i.e., if you have two
objects, two parallel infinte lines (or, for all you care, half-planes), then
the strip between those lines will be colored exactly like in the 1D case:
points on one line will get its color, points on the other line will get the
other color, and points between them will get a weighted-average color. The
averaging function should give strong preference to low distances: when you're
very close to a certain object, the color becomes very close to the object's
color.

But if you want the "gradient" map to have some differential properties
(I guess you called it a "gradient" for a reason...) you might want to have
a differential equation in the plane, such as laplace's equation, the heat
equation, or something like that, and solve a PDE with boundary conditions
of a given color at the boundaries of the given objects.
I'm not sure the added complication is worthwhile - maybe someone on this
list has experience in such a "2D gradient" like you wanted, and share their
experiences.

> that I'm not a CS or a Computer Engineering student.

She doesn't sound very friendly, but I think she has one good point: I
doubt these "2D gradients" you're looking for have any real use in computer
graphics - correct me if I'm wrong (I never fealt the need for such a thing
myself).
Anyway, make use of your being in the Technion - feel free to talk to anyone
in any department! Prof. Even is in CS too (at least he was, last time I
checked).

-- 
Nadav Har'El                        |     Wednesday, Dec 6 2000, 9 Kislev 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |My password is my dog's name. His name
http://nadav.harel.org.il           |is a#j!4@h, but I change it every month.

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 6 Dec 2000 14:12:32 +0200 (IST)

> that should remain differentiable throughout the plane). :)

I took those courses. <sarcastic>Great Fun</sarcastic>. Well, Physics 2M
at least is one of the hardest courses EE students have to take. I got 64
but I know something who got a 100 in it.

But at least I got 98 in Electromagnetic Fields... :-)

> very close to a certain object, the color becomes very close to the object's

But this will create gradients of circular nature, which may only be a
partial solution to what I'm looking for. I'd like to define a path (that
is a directed acyclic graph) which can be used to render the intermediated
colors within a plane, rather then to get one circularily spread of them.

As for the heat equation: that sound nice, but the question is how good it
can be done interactively. And one of the thing I'd like to have is a
variable blending function (like linear, sinousidial, quadratic,
exponential, etc.), as well as support for HSV _and_ RGB gradients.

> graphics - correct me if I'm wrong (I never fealt the need for such a thing

Well, I do. Pictures are two-dimensional rather than one dimensional, and
I'd like to make use of this fact to have some cool effects.

> in any department! Prof. Even is in CS too (at least he was, last time I

I talked with Prof. Shimon Even twice already (I'll write a separate
message with what he said about my graph isomorphism algorithm). In any
case, I doubt he can help me a lot with 2-D gradients, unless he is really
interested in computer graphics, which I doubt, because that's not what he
sais so on his homepage. I'll try to go to Taub (= the CS building) and
ping-pong my way to someone who can help me.

Regards,

	Shlomi Fish

> To unsubscribe from this group, send an email to:
> [email-masked]
> 
> 
> 
> 

----------------------------------------------------------------------
Shlomi Fish        [email-masked] 
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 6 Dec 2000 14:53:44 +0200

> but I know something who got a 100 in it.

Physics 2M was actually nice, once I realized that I should ignore the teacher
and read the material from that Berkley book (I forgot its name) on my own...

> But at least I got 98 in Electromagnetic Fields... :-)

I should have guessed that an electrical engineer knows a bit about electrical
fields :)

> colors within a plane, rather then to get one circularily spread of them.

I wouldn't exactly call them circular... If you take the pseudo-1D example
I talked about, of the two objects being two parallel infinite lines, then
you get a 1D pattern, nothing like circular. Another example, if you take
one object to be, say, a flower shape in the middle of the plane, and the
second object to be a triangle at a certain distance from it, you'll have
interesting color blending between them. True, far away from these objects,
if they are finite, you'll get a circular-like pattern (assuming, of course,
that you have another "object", the point at infinity, with its own color -
otherwise the color is fixed outside the area of interest) - I'm sure you
know all about this (dipole, remember? ;)).

> exponential, etc.), as well as support for HSV _and_ RGB gradients.

I don't understand how some of the terms you use here have anything to do
with the issue (I considered color to be a single number - if you want it
to be a vector encoded as RGB, HSV, or CMYK, or whatever, then it's the
exactly the same thing, for 3 or 4 numbers...).

In my "interpolation" scheme, you can choose whatever 1D interpolation
function you want, to choose how quickly a color changes when you get away
from one object and nearer another, although I don't see why you'd want this
relationship to be "sinusoidal"... As for the PDE-solution idea, I don't see
how you can control such things - it should come out of the equation.

> I'd like to make use of this fact to have some cool effects.

Perhaps, but there's a problem - when you do a two-dimensinal effect like that,
you're in effect rendering the whole plane, leaving no room for creativity
of the artist (or whatever), no place to put in "information". It's like the
"cloud" effect you'll find in many graphic programs - it's "cool" but because
it just fills up an entire section of the space, it's not useful too frequently.
At least that's how I see it - but perhaps you have other uses for it.

> ping-pong my way to someone who can help me.

Of course I wasn't suggesting you should talk to him about graphics ;) He's
an excelent Mathematician and theoritician, but I'm sure you can find people
who are more directly interested in these graphics issues.

-- 
Nadav Har'El                        |     Wednesday, Dec 6 2000, 9 Kislev 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Live as if you were to die tommorrow,
http://nadav.harel.org.il           |learn as if you were to live forever.

---

From: Shlomi Fish <[email-masked]>
Date: Thu, 7 Dec 2000 16:19:15 +0200 (IST)

> and read the material from that Berkley book (I forgot its name) on my own...

My lecturer was OK, but the problem was that in the test there was a
question which I completely forgot how to solve. We had a similiar problem
in the homework but I had a blackout. So I got only 64.
 
> I should have guessed that an electrical engineer knows a bit about electrical

Actually, most Electrical Engineers have little concern for electro-mag
fields. Usually, the Kirchoff Laws and the I-V correlation of the various
components are enough. And in signal processing we deal with Fourier
Transforms and higher-level abstractions.

Some of the things that fall under the category of Electrical Engineering
can actually be performed by programmers who have the adequate knowledge.

> exactly the same thing, for 3 or 4 numbers...).

A pattern can change its color by following a line on the RGB cube, or it
can change by following a line or some kind of arc on the HSV tree.

> At least that's how I see it - but perhaps you have other uses for it.

I don't think so, I think for example a text that will be filled with a
2-D gradient will be really cool. The closest thing there is to it is
Gimp's shape burst. But that's also 1-D in nature.
 
> who are more directly interested in these graphics issues.

I'll try to find some of them.

Regards,

	Shlomi Fish