|
Sounds cool, I wish I had more free time this century.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
which algorithm will search on a unordered list fastly?
|
|
|
|
|
The luckiest one!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
well... I guess regular iteration will, including a break when it is found.
If you have to do this more than once you could sort it first, because then you could make it a lot faster, but if it's a one time search, just iterate.
<br />
for (int i = 0; i < list.Count; i++)<br />
{<br />
if (list[i] == desiredValue)<br />
{<br />
return i;<br />
}<br />
}<br />
or something similar. for sorts, google BubbleSort or preferably wikipedia.
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
Hi! Please tell me about dithering algorithm clearly. I try to change color depth of bmp 24 bits to 4 bits, but my algorithm is not good...Then someone tell me about dithering, but not clearly, they don't give me an algorithm or clear idea but that's an introduction about dithering...So if you can, please tell me about dithering algorithm clearly.
Thanks and waiting for your replies.
Best regards,
FlytotheBlueSky
|
|
|
|
|
A simple, efficient, and effective solution is error diffusion. The idea is to find the error between the color you want and the color you can produce. You move that error into neighboring pixels. The error accumulates until it reaches the threshold for the next representable color. The effect is surprisingly good.
The algorithm as documented is good for one dimension of color (monochrome). The full color spectrum has three dimensions, so you'll have to apply error diffusion on all three individually. Try it with the red, green, and blue values and see how it works out. If that doesn't look good enough, post again and I'll dig up my HLS color code.
|
|
|
|
|
My answer does not address your question directly, since a good answer has already been given. I just wanted to remind you that if you are doing this to conserve space you will only get a gain of 6x at the expense of a very significant quality loss (at least on photographic images). A compression such as JPEG can give you a gain of 20x without losing nearly as much quality (in fact very little quality loss), and I think that even at 50x compression ratio it will still have better quality than any 4bpp BMP diethering. There is a number of JPEG libraries out there, some highly optimized (like INTEL's).
I hope this helps,
Rogério
|
|
|
|
|
I'm trying to come up with an algorithm that will compare 2 values and pick the lower-value more often, but not always. So if the values are 10 and 50, then the node with 10 will be chosen 4 out of 5 times. Or if the values are 25 and 50 the lower value will be chosen twice as many times as the higher value.
These are just numbers and ratios I've just pulled out of thin air to give you an idea of what I'm trying to do. But I can't seem to come up with anything that makes sense.
If it helps I'm using an AVL tree to store the values and at each node I am comparing the Max and Min value of the leaf nodes. I want to distribute the number of times each leaf node is chosen based on it's value with lower values being chosen more often.
Thanks in advance.
|
|
|
|
|
if you actually meant 5 out of 6 times for the first example...
if (rand(val1+val2) > va1)
choose val2
else choose val1
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Thanks for the quick response, but if the values are 10 and 50 then: 10 + 50 = 60. And 60 will be chosen more often than 10, and I want the lower value chosen more often. Of course, in this case I could do the opposite. if > val1 then choose val1. I'll experiment with this a bit.
Thanks
|
|
|
|
|
Thanks,
Simply chosing the opposite worked:
<br />
class Class3<br />
{<br />
static void Main(string[] args)<br />
{<br />
Random rand = new Random();<br />
<br />
int cnt1 = 0, cnt2 = 0;<br />
double val1 = 20.223, val2 = 37.882;<br />
int tot = Convert.ToInt32(val1 + val2);<br />
<br />
for (int i = 0; i < 10000; i++)<br />
{<br />
if (rand.Next(tot) > val1)<br />
cnt1++;<br />
else<br />
cnt2++;<br />
}<br />
<br />
Console.WriteLine("Total: " + tot);<br />
Console.WriteLine("Val1 ({0}): {1}", val1, cnt1);<br />
Console.WriteLine("Val2 ({0}): {1}", val2, cnt2);<br />
}<br />
}<br />
The output is consitent no matter which values I choose, the lower value is chosen more than the higher value by a ratio that matches the ratio which matches the values themselves. I'm going to try this next with my AVL tree and watch those results. After this testing I think already I have the answer to my next problem and that was going to be with selecting a random value at each node. But I figure I can get the random value once at the top and use the same result all the way down the tree. I'll try it each way and see which method has better distribution.
Thanks again,
Mark
|
|
|
|
|
|
I'm eating 4.52*pi/6 in3 apple pie for pi day...
----
...the wind blows over it and it is gone, and its place remembers it no more...
|
|
|
|
|
Mmm... apple pie I think I will have to get some pie with my lunch today.
--
Marcus Kwok
|
|
|
|
|
pizza pi for lunch today. Might get some of the other kind for dinner.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
hi,ashee here.implementing face recognition Algorithm in MATLAB namely PCA and LDA.can anyone please help me.
|
|
|
|
|
Hi, i am making a Windows Media Player Visualization and i need some help with an algorithm.
I am making a snake like curve that moves around the screen. It uses 3 point bezier curves joined together to form one long curve. The head continually grows while the end disappears. I need to make each new one connect to the old head but my code doesn't work. Here is some of the code:
typedef struct tagBezier{
float x, y;
POINTF P0, P1, P2;
float t, t2;
} Bezier;
void CViz3D::calculateBezier(Bezier& b, float time) {
b.t2 = b.t; b.t = time;
b.x = (pow(b.P0.x*(1 - b.t),2) + b.P1.x*2*b.t*(1 - b.t) + pow(b.P2.x*b.t,2));
b.y = (pow(b.P0.y*(1 - b.t),2) + b.P1.y*2*b.t*(1 - b.t) + pow(b.P2.y*b.t,2));
}
void CViz3D::drawBezierCurve(Bezier b[CURVES]) {
float iStart = 0, iEnd = 1;
if (b[start].t < b[start].t2) {
int sOld = start;
start = (start+1)%CURVES;
end = (end+1)%CURVES;
float distX=b[sOld].P2.x-b[sOld].P1.x, distY=b[sOld].P2.y-b[sOld].P1.y;
b[start].P0.x = b[sOld].P2.x; b[start].P0.y = b[sOld].P2.y;
b[start].P1.x = b[sOld].P2.x+distX; b[start].P1.x = b[sOld].P2.y+distY;
b[start].P2.x = (RAND-0.5f); b[start].P2.y = (RAND-0.5f);
}
for (int j = 0; j < CURVES; j++) {
if (j == start) { iStart = 0; iEnd = bezTime; }
else if (j == end){ iStart = bezTime; iEnd = 1; }
else { iStart = 0; iEnd = 1; }
glBegin(GL_LINE_STRIP);
for (float i = iStart; i < iEnd; i += 0.01f) {
calculateBezier(b[j], i);
glVertex2f(b[j].x, b[j].y);
}
glEnd();
}
}
Can someone figure out what's going on.
Thanx
|
|
|
|
|
Hi, may I suggest you expand on "does not work" before you expect anyone to dig in ?
Does it compile ? run ? behave for a while ? then what ?
|
|
|
|
|
Sorry i should have mentioned, the curves don't match up. That is, when a new curve is made it should smoothly match up with the one before it. Here is an image that explains it. I can't be bothered posting an image of the actual result but basically point B2 seems to be at any random spot instead of being in line with A2.
http://img89.imageshack.us/img89/318/bezierlt5.png
|
|
|
|
|
Hi,
some remarks:
1. you managed to confuse yourself and me by using different numbering in code and drawing;
2. your code makes two distances equal: A3-A2 = B2-B1 in drawing's notation, although
drawing's annotation says otherwise.
3. you are aware I trust that RAND is called twice and will return two different numbers;
this yields independent x and y for B3 (is OK).
4. but I would make the distance B3-B2 random, so I prefer something like:
b[start].P2.x = b[start].P1.x+maxStepX*(RAND-0.5f);
b[start].P2.y = b[start].P1.y+maxStepY*(RAND-0.5f);
with maxStepX and maxStepY some reasonable constants (maybe equal).
Hope this helps.
|
|
|
|
|
"1. you managed to confuse yourself and me by using different numbering in code and drawing"
yeah, sorry about that. I draw the picture before i wrote the code, to give me an idea of what to do... that didn't help
"2. your code makes two distances equal:..."
yes, i changed that to make it easier to code
"4. but I would make the distance B3-B2 random..."
isn't that basically the same as what i did, except i picked random points.
Thanks for your help. But my problem it that B2 isn't lined up with A2 and i don't know why?
|
|
|
|
|
Hi,
I looked at your code again and discovered you are squaring the coordinates !?!?
b.P0.x and the like should not be inside pow(...,2) !
Also I would suggest to keep the bezier curves large enough, i.e. I hope you are
not trying to draw a bezier that only spans a few pixels (would waste CPU cycles
and might be off due to quantization effects).
|
|
|
|
|
Thanks for that. I never would have found that out. I got the formula for Bezier curves off the internet and coded it in C++ but i didn't keep the original formula so i just assumed i copied it right.
Thanks again.
|
|
|
|
|
You're welcome.
When in doubt about some formula, I check the edge conditions, in your case the
Bezier must yield P0 and P2 for the special values t=0 and t=1.
Furthermore, squaring a physical thing (such as a coordinate) does not
occur often.
Best regards,
|
|
|
|
|
There is still just one little problem. Sometimes the curves don't go from one to the other and stay there. That is, one curve keeps repeating over and over as if if (b[start].t < b[start].t2) doesn't evaluate to true???
Here is a link to download the viz so you can see for yourself. http://www.savefile.com/files/550244[^]
Read the readme, it tells you how to install it. If you can't get it to install tell me and i'll post some pics instead.
|
|
|
|