Calculate optical flow in a matrix - opticalflow

I'm not even sure if this is the appropriate forum for this question, (maybe I should go at MathExchange).
So, I have a Computer Vision exam in about 10 days, and I have no idea how to calculate the optical flow. The professor hasn't provided materials for this, and I've seen questions like these appear in exams:
https://i.stack.imgur.com/GuMD5.png
The requirements are the following:
Find the optical flow for pixel (2, 1) in image I1 (that's the pixel with 139 value). We're looking for a vector.
Thank you in advance.

Related

do i always need labeled data for ann?

i put a small request on upwork where i am requesting help for a topic which is right now out of my skill zone.
The problem is a fitting problem of small rectangles in a big rectangle via a ANN.
Problem is the first freelancer baffled me a little bit with a comment.
So my thinking was, because the solution is easy verified and rewardable, that you can simply throw a ANN on this problem and with enough time it will perform better and better.
The freelancer requested labeled data first before he can tackle the problem(thats the comment which confuses me).
I was thinking that unlabeled random Input data is enough for the start.
Do I think wrong?
here the link to the job post.
https://www.upwork.com/jobs/~01e040711c31ac0979
edit: directly the original job description
I want python code for training a ANN and using it in a productive enviroment.
The problem it needs to solve is a rectangle fitting problem.
Input are
1000 small Rectangles(groupid,width,heigth,Oriantion(free,restricted,hor or ver), value) --sRect
1 big Rectangles(width, heigth)--bRect
Layout(bool,bool,bool,xpos,ypos,Oriantaion(hor or ver))--Layout
Output
Layout
The bRect will be duplicated to 3 Rectangles where the sRects need to be fitted into.
The Worth of the solution is determined by the sum of the value of sRect inside the bRect.
Further is the value decreased if the sRect is placed in the second bRect or third bRect.
sum(sRect(value))*0.98^nth bRect
Not all sRect needs to be placed.
Layout is structered that the three bool at the start represent at which bRect the sRect is placed. If a sRect is placed at one of the bRect, then the Solution Layout muss stay for this sRect the same.
Restricted Ori means all of the sRect with the same group need to be Oriantated the same way. Hor means the sRect is not turned, ver the sRect is turned by 90degrees.
Other then that normal rules apply, like all sRect needs to be inside the bRect and not Overlapp between sRect.
Looking forward to replys and i am avaible for further explanations.
edit: example picture
important i dont want to optimise for maximum plate usage, because it can happen that a smaller sRect can have a higher value then a bigger sRect.
example fitting problem
Without expected output for each input you cannot use the most standard training methodology - supervised learning. If you only have a way to verify the solution (e.g. in a game of chess you can tell me if I won but you cant tell me how to win) then the most standard approach is reinforcement learning. That being said, it is much more complex problem, not something that say a newcomer to the field of ML will be capable of doing (while supervised learning is something that one can do essentially by following basic tutorials online)

Dealing with false positives in binary image segmentation

I'm working on a model to identify bodies of water in satellite imagery. I've modified this example a bit to use a set of ~600 images I've labeled, and it's working quite well for true positives - it produces an accurate mask for imagery tiles with water in it. However, it produces some false-positives as well, generating masks for tiles that have no water in them whatsoever - tiles containing fields, buildings or parking lots, for instance. I'm not sure how to provide this sort of negative feedback to the model - adding false-positive images to the training set with an empty mask is having no effect, and I tried a training set made up of only false-positives, which just produces random noise, making me think that empty masks have no effect on this particular network.
I also tried training a binary classification network from a couple of examples I found to classify tiles as water/notwater. It doesn't seem to be working with a good enough accuracy to use a first-pass filter, with about 5k images per class. I used OSM label-maker for this, and the image sets aren't perfect - there are some water tiles in the non-water set and vice-versa, but even the training set isn't getting good accuracy (~.85 at best).
Is there a way to provide negative feedback to the binary image segmentation model? Should I use a larger training set? I'm kinda stuck here without an ability to provide negative feedback, and would appreciate any pointers on how to handle this.
Thanks!

How to bring M.C. Escher to actionscript 3

I need a bit of counseling. I´m trying to reproduce one of M.C. Escher´s models in Actionscript, but I´m not entirely sure about where to begin. Ideally, I´d want to make something from his Circle Limit series look somewhat like this: http://vimeo.com/4154382
Could anyone provide any pointers as in what approach should I take? I am not an expert coder, so anything would help.
Thanks in advance,
Garfeel M.D.
The different copies of a hyperbolic transformation are related to one another via Möbius transformations which leave the circle fixed. You can represent them as transformations
(a+bi)z + (c+di)
z |-> ----------------
(c-di)z + (a-bi)
You might want to represent the switch from circle to half plane as a Möbius transformation as well, to avoid numeric issues with simple zooming.
I have tools available to make hyperbolic ornaments from Escher ornaments, and zoom into them in real time. But Escher isn't public domain yet, and in my experience the Escher foundation is less than enthusiastic in granting permission for derived works. So if you get ther OK, or decide on some other artist (possibly starting from a Euclidean ornament), feel free to contact me by e-mail to discuss this further.
I recently was a jury member foir an ornament competition where some submissions were hyperbolized from Euclidean drawings. Gaining permissions for those would likely be easier than from the Escher foundation.

Electrically charging edges in a force-based graph drawing algorithm?

I'm attempting to write a short mini-program in Python that plays around with force-based algorithms for graph drawing.
I'm trying to minimize the number of times lines intersect. Wikipedia suggests giving the lines an electrical charge so that they repel each other. I asked my physics teacher how I might simulate this, and she mentioned using calculus with Coulomb's Law, but I'm uncertain how to start.
Could somebody give me a hint on how I could do this? (Or alternatively, another way to tweak a force-based graph drawing algorithm to minimize the number of times the lines cross?) I'm just looking for a hint; no source code please.
In case anybody's interested, my source code and a youtube vid I made about it.
You need to explicitly include a term in your cost function that minimizes the number of edge crossings. For example, for every pair of edges that cross, you incur a fixed penalty or, if the edges are weighted, you incur a penalty that is the product of the two weights.

Angular Momentum Transfer equations

Does anyone have any good references for equations which can be implemented relatively easily for how to compute the transfer of angular momentum between two rigid bodies?
I've been searching for this sort of thing for a while, and I haven't found any particularly comprehensible explanations of the problem.
To be precise, the question comes about as this; two rigid bodies are moving on a frictionless (well, nearly) surface; think of it as air hockey. The two rigid bodies come into contact, and then move away. Now, without considering angular momentum, the equations are relatively simple; the problem becomes, what happens with the transfer of angular momentum between the bodies?
As an example, assume the two bodies have no angular momentum whatsoever; they're not rotating. When they interact at an oblique angle (vector of travel does not align with the line of their centers of mass), obviously a certain amount of their momentum gets transferred into angular momentum (i.e. they each get a certain amount of spin), but how much and what are the equations for such?
This can probably be solved by using a many-body rigid system to calculate, but I want to get a much more optimized calculation going, so I can calculate this stuff in real-time. Does anyone have any ideas on the equations, or pointers to open-source implementations of these calculations for inclusion in a project? To be precise, I need this to be a rather well-optimized calculation, because of the number of interactions that need to be simulated within a single "tick" of the simulation.
Edit: Okay, it looks like there's not a lot of precise information about this topic out there. And I find the "Physics for Programmers" type of books to be a bit too... dumbed down to really get; I don't want code implementation of an algorithm; I want to figure out (or at least have sketched out for me) the algorithm. Only in that way can I properly optimize it for my needs. Does anyone have any mathematic references on this sort of topic?
If you're interested in rotating non-spherical bodies then http://www.myphysicslab.com/collision.html shows how to do it. The asymmetry of the bodies means that the normal contact force during the collision can create a torque about their respective CGs, and thus cause the bodies to start spinning.
In the case of a billiard ball or air hockey puck, things are a bit more subtle. Since the body is spherical/circular, the normal force is always right through the CG, so there's no torque. However, the normal force is not the only force. There's also a friction force that is tangential to the contact normal which will create a torque about the CG. The magnitude of the friction force is proportional to the normal force and the coefficient of friction, and opposite the direction of relative motion. Its direction is opposing the relative motion of the objects at their contact point.
Well, my favorite physics book is Halliday and Resnick. I never ever feel like that book is dumbing down anything for me (the dumb is inside the skull, not on the page...).
If you set up a thought problem, you can start to get a feeling for how this would play out.
Imagine that your two rigid air hockey pucks are frictionless on the bottom but have a maximal coefficient of friction around the edges. Clearly, if the two pucks head towards each other with identical kinetic energy, they will collide perfectly elastically and head back in opposite directions.
However, if their centers are offset by 2*radius - epsilon, they'll just barely touch at one point on the perimeter. If they had an incredibly high coefficient of friction around the edge, you can imagine that all of their energy would be transferred into rotation. There would have to be a separation after the impact, of course, or they'd immediately stop their own rotations as they stuck together.
So, if you're just looking for something plausible and interesting looking (ala game physics), I'd say that you could normalize the coefficient of friction to account for the tiny contact area between the two bodies (pick something that looks interesting) and use the sin of the angle between the path of the bodies and the impact point. Straight on, you'd get a bounce, 45 degrees would give you bounce and spin, 90 degrees offset would give you maximal spin and least bounce.
Obviously, none of the above is an accurate simulation. It should be a simple enough framework to cause interesting behaviors to happen, though.
EDIT: Okay, I came up with another interesting example that is perhaps more telling.
Imagine a single disk (as above) moving towards a motionless, rigid, near one-dimensional pin tip that provides the previous high friction but low stickiness. If the disk passes at a distance that it just kisses the edge, you can imagine that a fraction of its linear energy will be converted to rotational energy.
However, one thing you know for certain is that there is a maximum rotational energy after this touch: the disk cannot end up spinning at such a speed that it's outer edge is moving at a speed higher than the original linear speed. So, if the disk was moving at one meter per second, it can't end up in a situation where its outer edge is moving at more than one meter per second.
So, now that we have a long essay, there are a few straightforward concepts that should aid intuition:
The sine of the angle of the impact will affect the resulting rotation.
The linear energy will determine the maximum possible rotational energy.
A single parameter can simulate the relevant coefficients of friction to the point of being interesting to look at in simulation.
You should have a look at Physics for Game Developers - it's hard to go wrong with an O'Reilly book.
Unless you have an excellent reason for reinventing the wheel,
I'd suggest taking a good look at the source code of some open source physics engines, like Open Dynamics Engine or Bullet. Efficient algorithms in this area are an artform, and the best implementations no doubt are found in the wild, in throroughly peer-reviewed projects like these.
Please have a look at this references!
If you want to go really into Mecanics, this is the way to go, and its the correct and mathematically proper way!
Glocker Ch., Set-Valued Force Laws: Dynamics of Non-Smooth Systems. Lecture Notes in Applied Mechanics 1, Springer Verlag, Berlin, Heidelberg 2001, 222 pages. PDF (Contents, 149 kB)
Pfeiffer F., Glocker Ch., Multibody Dynamics with Unilateral Contacts. JohnWiley & Sons, New York 1996, 317 pages. PDF (Contents, 398 kB)
Glocker Ch., Dynamik von Starrkörpersystemen mit Reibung und Stößen. VDI-Fortschrittberichte Mechanik/Bruchmechanik, Reihe 18, Nr. 182, VDI-Verlag, Düsseldorf, 1995, 220 pages. PDF (4094 kB)