|
So you know the following:
1. d ≤ v ≤ x1 - d/2
2. ∀xn, d/2 ≤ xn % v ≤ v - d/2
My dumb algorithm in C# would be (untested):
int FindV(List<int> x, int d) {
int halfD = (d + 1) / 2;
d = 2 * halfD;
for (int v = x[0] - halfD; v >= d; --v) {
int upper = v - halfD;
bool solved = true;
foreach (int xn in x) {
int mod = xn % v;
if (mod < halfD || upper < mod) {
solved = false;
break;
}
}
if (solved) return v;
}
return -1;
}
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
can any developer help me
|
|
|
|
|
Post an actual question, this is too vague... look to use something like RTP for audio/video network transfers, but other than that, ask more specific questions.
|
|
|
|
|
i need some audio watermarking algorithm codes such as spread spectrum, cepstrum , chirp , echo hiding.
who can help me?and how can i get this codes?
with the best regardes.
|
|
|
|
|
Try here:
Codez[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
how can i get audio watermarking attacks codes?
|
|
|
|
|
Can anyone explain to me how exactly works the Super2xSal, SuperEagle or hq2x algorthm for scaling images? I need the exact pattern written in pseudo code. For example, the Scale 2X algorithm uses the following pattern:
A B C
D E F
G H I
E0 E1
E2 E3
if (B != H && D != F) {
E0 = D == B ? D : E;
E1 = B == F ? F : E;
E2 = D == H ? D : E;
E3 = H == F ? F : E;
} else {
E0 = E;
E1 = E;
E2 = E;
E3 = E;
}
Thanks for any useful answer.
|
|
|
|
|
Wiki has some discussion on these and other similar algorithms: Super2xSaI[^]
|
|
|
|
|
I'm studying how to convert between image file formats in low-level programming (without using converter libraries), to do this way, I have to know the file format structure but it seems not such easy, because of complex compression algorithms used in graphics files...
Another problem is how to convert from pixel to pixel such as if an image file with each pixel encoded by 24 bits is converted to another image file with each pixel encoded by 8 bits, that means we have to map 2^24 color palette to a 2^8 color palette, we surely have to choose 2^8 colors from 2^24 colors to put in the new color table and if so how we do that? Which colors we choose?
Could anyone here who have worked on the same projects please tell me step-by-step guide on how to convert between these image file formats? I don't need detailed code, I need a guide to do, if possible your codes will be very helpful to me but if not, that'll be fine. Plus If you have any documents on image file formats, could you please post some download link here to help me, I am very in need of such documents.
Thank you very much in advance and anyway!
|
|
|
|
|
To get the documentation use your favorite search engine with "<image type> file format specification". You should get links to the official specifications on the first result page(s).
|
|
|
|
|
"...we have to map 2^24 color palette to a 2^8 color palette, we surely have to choose 2^8 colors from 2^24 colors to put in the new color table and if so how we do that? Which colors we choose?"
One solution is error diffusion with the Floyd-Steinberg Algorithm (can't find a good reference to link to). The basic idea is when you replace a pixel with one from a smaller palette, you will have a small amount of error. This error is propagated to the right and down, which allows a close approximation of the original image with the new smaller palette.
This allows, for example, a decent representation of grayscale portraits with only black and white pixels, as you see in the Wall Street Journal.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
|
Hi,
In a C++ software projetc I'm working with they gets
number of bytes = ((number of bits)* 7) / 8
Why isn't
number of bytes = (number of bits) / 8
Thanks!
|
|
|
|
|
marca292 wrote: number of bytes = ((number of bits)* 7) / 8
It should really be (note the plus sign)
number of bytes = ((number of bits) + 7) / 8 to round up any odd bits to a byte boundary.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Is there a generic algorithm for ordering non-crossing (poly) lines? The "order" is hard to define, but any child could do it if they saw the lines drawn on paper...from the first line, to the last line, the inside line to the outside line etc. The order might end-up being L->R or T->B or somewhere in between.
I'm thinking you might be able to work with the distance to the line end points from the centroid of all the lines...or something like that.
Do the end points with the "extreme-est" coordinates, definitely locate the "first" and "last" lines?
Anyone?
|
|
|
|
|
This is a partially-ordered set. One line can come before another, or they may be incomparable. You can choose whatever heuristic that makes sense for your application for ordering them.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
I have a set of parallel-ish lines (they may not be parallel, but they don't cross) that define an area. On each line, I calculate two points (lets say P1 and P2) which define an operating region. With an ordered set of lines, I know for line 1 (L1), the polygon showing the operating region starts at P1 and ends at P2. The next point in the polygon is L2P1, whereas the (n-1)th point is L2P2 (where n is the number of lines I have).
My problem is:
1) Lines may be drawn either way, so P1 and P2 in two 'adjacent' lines may not be on the same side.
2) Lines may not be in order.
So, knowing the number of lines, and which points belong to the same line (i.e., I know which points are paired),
can I calculate the order of the lines / points, so that I can draw my polygon?
It seems like a hulling problem, but is there a way to say 'all these points are on the hull boundary'?
Wouldn't that lead to multiple solutions for certain sets of points?
|
|
|
|
|
Actually - is this a travelling salesman problem?
|
|
|
|
|
Can you show some diagrams of the possible scenarios? I'm not sure I have it entirely clear in my head.
If the hull is known to be convex, and we're talking 2D, I would take an approach like:
- find a point inside the shape (the average location of all the control points should do)
- go around the control points in order of angle from that central point
I don't think the pairing of points on the same line matters, once you have the collection of points.
|
|
|
|
|
This is a very simple example, but I want to draw the polygon defined by the black lines and the green and red spots.
This[^]
|
|
|
|
|
Okay, so if you can find that it's the green and red lines you want, my solution will work for creating the polygon. (The average point will be somewhere in the middle and then G1, R1, R2, G2 are in order of angle from it.)
To find which lines you want, order them based on how far along the 'black axis' they cross the black lines, i.e. by r.b where r is any point on a line and b is the direction vector of the black lines.
(Sorry for not responding for a while, I forgot about this forum.)
|
|
|
|
|
Thanks - that just leaves me with the ordering problem (see my other post). Since my lines may have been draw either way around, and in a "random" order...ordering them is not as easy as it sounds. I've come up with a method that will work most of the time (I think) (Here[^]).
I think throwing the points at a Travelling Salesman algorithm might be less complicated.
|
|
|
|
|
Kyudos wrote: I think throwing the points at a Travelling Salesman algorithm might be less complicated.
No need for that. When the lines are almost parallel, and don't cross each other, you can define some kind of distance, calculate that, and order them all based on it.
Example: take one of the lines, calculate its equation in the form f(x,y)=a*x+b*y+c.
All points on the line itself have f(x,y)=0 by definition.
The green/red points have a non-zero f value, take one of them, or the average, and use that as a distance.
|
|
|
|
|
I think that is along the lines of what I described in my Physics Forum post (see above). But a TSP solution will generically work for both lines and polylines with minimum complication.
|
|
|
|
|
I answered that as well in the last paragraph . I'm assuming that the black lines are in some known direction, otherwise you have to pick a direction vector ... but just choosing the perpendicular to any one of the lines should work fine. It doesn't actually matter whether the order ends up as ABCD or DCBA, and picking a perpendicular will guarantee one of those will be the case if the lines are close to parallel. (The average perpendicular for all the lines will be better but probably unnecessary.)
|
|
|
|