@Rojo Consider the easy case first: You have 3 components and you can assign one component red, one green and one blue. My idea was the following, every pixel inside a component, gets the true component color only. As soon as you have a pixel outside the components, you calculate a mixture of the three colors depending on the distance of this pixel to each component.
For n objects, you can of course assign unique colors for each component. However, it is possible that two outside pixels can get the same color accidentally.
The underlying problem is, that for n objects, you get an n-dimensional distance vector {d1, d2, ..., dn} where each di is the distance to object i. Since the colorspace is not n-dimensional you won't get a unique color for all distance vectors.
@halirutan As far as I think I understand, you suggest building an n-color-channel image where the i-th channel corresponds to the distance to object i. And if the pixel was already determined to be part of the i-component, it will only have values on the corresponding channel. Or alternatively, a separate image keeps the information on the already segmented pixels.
@Rojo The basic behavior can be grasp by the following. Assume you have 5 object, that are incidentally arranged like the vertices of a pentagon. Now, we choose 5 different colors:
The following is not absolutely correct, but if we give each vertex of the pentagon one the colors, we get:
So inside the vertex points, you will have the specified color. Everywhere else, it is interpolated.
@Rojo The problem is that RGB is only 3 dimensional, so in reality and depending on the position of your objects it can happen that some points get the same color.
Yeah, but assume we had 3 colors for now. Then there's the task of assigning a single color to each pixel in a way that there's a single red puddle, a single green puddle and a single blue puddle
(we started, say, with 10 nodes, of 3 colors)
@halirutan Do you see simple good solutions to that part?
@halirutan in 3D I think it's easier. And the data is supposed to be nice for this, at least most of the times. If it's not, then if should be solved on a previous step.
If it's not, I'm happy enough with a function that returns "go to hell"
In short, if you have the non-overlapping objects of your already connected puddles, my idea of how to color the black space between them might work. For the task of connecting, I have no bright idea.
Maybe with graphs, or with some topology thing, one could enumerate the different ways to connect the parts with lines. Then deform. Then use your idea to "fatten"
Also, partitioning the image into small chunks, solve there, then use bigger chunks, etc, might make sense.
@Rojo Above, we have 4 green objects. Get the center of each object with ComponentMeasurements. Draw a line between from one object to the next, but only if they differ in the x-coordinate. Then, use Dilation and as kernel, you use one of your objects.
If I just choose randomly which color to start with, and add some noise to the solution, and in every step I just take care not to go over the other colors that have been already established, it might work
I would wish it wouldn't be so "efficient" way of running Mma into using vast amounts of CPU time and RAM just by doing a Reduce on something like ForAll inside Exists on relatively simple geometric statements...
I have a function that calculates the rank of a restricted growth string defined like so,
rankKRGS[{}] = 0;
rankKRGS[string_] :=
With[{n = Length@string, k = Max@string + 1, alone = !MemberQ[Most@string, Last@string]},
rankKRGS@Most@string +
If[alone, k*StirlingS2[n - 1, k], Last@string*St...
@Mr.Wizard Lamenting the facts a) that such problems lead to more or less infinite-memory expansions in a way or another and b) that apparently (geometric) intuition of the system on such problems seems to be so absurdly low.
The problem at hand was like, "what angles of a line drawn from a specific corner of a non-convex polygon leave interior of the polygon (the first time) through a specific side of the polygon?"
Clearly one can't rely on Mma to cope with such a problem stated in relatively obvious way.
Did you know that you can demonstrate the non-linearity of the human ear with an audio sample that can be generated using a single line of Mathematica? szhorvat.net/pelican/combination-tones.html
@MichaelE2 I think the situation is misleading. If you look at NIntegrate[f[x], {x, 0, 1}] // Trace, you see that many messages are generated and in the usual case only one makes it to the surface. I'm not sure why using = changes this behavior.
@MichaelE2 In any case it is curious. Usually, NIntegrate should collect all Overflow messages and generate one message of its own. I have no idea what happens.
@halirutan traceView2 shows two evaluations of NIntegrate. I suspect the return value of Set is being evaluated. It's not just limited to NIntegrate. res = Plot[x, {x, 0, Null}] fails twice.
@halirutan Yes, if you put a Print[x] statement inside the def. of f or glurg, you see the sampling is done twice, too. (I changed it to Pause above, because I thought the timing showed it just as clearly.)
Do you think it's a bug? Your f example shows it's not always the behavior.
@MichaelE2 I don't now whether it has further implications. For me it is at least very unexpected and does not follow the rules of the normal evaluation chain. Initially, I thought that only the messaging/error reporting mechanism is flawed but as it is now, it can introduce bugs that are hard to track.
@MichaelE2 The question is, does this only appear in some very high-level function or can we reproduce it with simpler functions too? Obviously, your initial f generates a system message as well, but is never evaluated twice when you call
@halirutan The same happens with Identity@NIntegrate[..] and Identity@f[]. -- Yes, I've been suspecting it might have something to do with high-level functions that have complicated parameter checking.
If it indeed also happens in simpler functions, than an f with side-effects will compute the wrong output.
@MichaelE2 Yes, I have already found that Identity shows the same thing.
Maybe someone with a good overview of the questions like @Mr.Wizard can tell if there is already a question reporting this issue.
@Mr.Wizard Consider a simple f that throws an overflow message and is used in NIntegrate, did you ever came across a question that reports why the NIntegrate call is evaluated several times? Consider this simple example
Is there anyone with earbuds around? If yes, try this:
Play[{Sin[300 2 Pi t], Sin[500 2 Pi t]}, {t, 0, 1}]
Listen to only the left stereo channel. It will be a low tone. Listen to only the right channel. It will be a high tone. They are not mixed.
Now try this:
Audio@Play[{Sin[300 2 Pi t], Sin[500 2 Pi t]}, {t, 0, 1}]
On my computer (macOS Sierra), both the left and right earbuds play both the high and low tones simultaneously. In other words, the sound is downmixed to mono before playback.
According to an appropriately minimalist definition, my computer is auto-generating complete games now. My hope is that by taking an abstract approach I'll avoid traditional genres and giving up.
@halirutan I have a notoriously poor memory so I'm not sure why you would turn to me. :^) I cannot at the moment recall something like that, for what it's worth.