I'm trying to calculate the distances between points of different colours, as shown in this image:
The goal is to use a macro to print the distances from the red dot to the yellow dot and then the yellow dot to the purple dot. I believe the best way to do this is to either:
1) Use a macro to print the coordinates of the red dots, and then a macro to print the coordinates of the closest yellow dots. Then a second macro to print the coordinates of the purple dots closest to a given yellow dot. I would also like to calculate the angle of the line relative to the center point, but I believe I can do this in Excel if I'm given the XY coordinates of each point as well.
2) Drawing lines between the red and yellow points and the yellow and purple points, printing the length and angle of those lines.
Ideally being able to do both would be good, but either would work for my purposes (calculating the distance and angle of the lines between the points from red to yellow and yellow to purple).
What is the best way to do this via macro? There are some examples (like this) but I don't believe it 1) selects for points based on colour or 2) picks the next closest point automatically.
Try using the Threshold Color function, I should think it would allow you to select your colors individually. You can then get the coordinates for your different points by selecting "centroid" from the Analyze menu. The calculations for the angles and distances can be done then in Excel if you use the closest coordinates for the relevant colors.
Related
I have images such as below (I am pasting only a sketch here) where I want to calculate the center of symmetry and the displacement between the 2 marked zones in the image(Marked in Red and blue). Could anyone suggest a simple algorithm for this? (Please note the signal is symmetric to 180-degree rotation).
The idea is to calculate the center of symmetry between the red and blue zones
Here is my algorithm approach:
Distinguish the red and blue pixels in the image by thresholding: Lets say set the blue pixels to wihte(255) and set the red pixels(0) and set the rest of image to the (125) in a gray channel image.
Check all of the pixels horizontally in the middle row of the image.
While you are checking, if you hit the red pixel, then try to search blue one. However, if you hit red pixel again, then start searching blue again.
During the search after red pixel if you hit a blue pixel then you can easiy calculate the middle of it. Then re-start the process.
Here is a demonstration of search line:
Note: Since they are dashed lines, luckily you may pass them with gaps. To fix, this you can try couple of random different rows.
I have a project that I need to follow the points like in the picture. I made a picture like this as a representation. I get the coordinates of the red dots as pixel coordinates once per second. Is there a way I can predict the green dots when I don’t take measurements afterwards? When I use the 2d-kalman filter (x,y,x’,y’ states) it keeps guessing in the direction of the blue arrow. I want to make correct predictions on the green dots, not this way. How can I do that.!
Thanks.
Image
I know, that the Meanshift-Algorithm calculates the mean of a pixel density and checks, if the center of the roi is equal with this point. If not, it moves the new ROI center to the mean center and checks again... . Like in this picture:
For density, it is clear how to find the mean point. But it can't simply calculate the mean of a histogram and get the new position by this point. How can this algorithm work using color histogram?
The feature space in your image is 2D.
Say you have an intensity image (so it's 1D) then you would just have a line (e.g. from 0 to 255) on which the points are located. The circles shown above would just be line segments on that [0,255] line. Depending on their means, these line segments would then shift, just like the circles do in 2D.
You talked about color histograms, so I assume you are talking about RGB.
In that case your feature space is 3D, so you have a sphere instead of a line segment or circle. Your axes are R,G,B and pixels from your image are points in that 3D feature space. You then still look where the mean of a sphere is, to then shift the center towards that mean.
I'm using EmguCV and trying to find polygons within an image. Here are some facts about the problem:
1) The polygons are irregularly shaped, but the sides are always at one of two angles.
2) Often the polygons have gaps in their sides that need to be filled.
3) If a polygon is contained within another polygon, I want to ignore it.
Consider this image:
And I want to find the polygons highlighted in red, omit the polygon highlighted in green and make connections across gaps as shown in blue here:
I've had some success using HoughLinesBinary and then connecting the closest line segment end points to each other to bridge gaps to build a complete polygon, but this doesn't work when multiple polygons are involved since it will try to draw lines between polygons if they happen to be close to each other.
Anybody have any ideas?
I think that the problem could be your image threshold.
I don't know how you did but you can get better results if the binary image is better.
I like of your idea to connect the polygons segment, try to secure that the line you will connect has a maximum and minimum length to avoid connect to nearest objects.
Verify if the new joint of lines forms 90 degrees angle, even if its a corner.
Added:
You can use moephological operators to grow the lines acord to angles. As you said that the lines has known angles do dilations using a mask like this
0 0 0
1 1 0
0 0 0
This mask will grow lines only to rigth until conect to other side.
A general solution will be hard, but for your particular problem a relatively simple heuristic should work.
The main idea is to use the white pixels on one side of a wall as an additional feature. The walls in your image always have one almost black side, and one side with many white noise pixels. The orientation of the white noise in relation to the wall does not switch on corners, so using this information you can eliminate a lot of possible connections between lines.
First some definitions:
All walls in the picture go either from the lower left to the upper right (a rising line) or from the upper left to the lower right (a falling line).
If there are more white pixels on the left side of a falling line, call it falling-left-wall, otherwise falling-right-wall. Same for rising lines.
Each line ends in two points. Call the leftmost one start, the rightmost one end.
Now for the algorithm:
classify each line and each start/endpoint in the image.
Check the immediate area on both sides of each line, and see which side contains more white pixels.
Afterwards, you have a list of points labeled falling-left-wall-start, rising-left-wall-end, etc.
for each start/end point:
look for nearby start/end points from another line
if it is a falling-left-wall-start, only look for:
a falling-left-wall-end
a rising-left-wall-start, if that point is on the left side of the current line
a rising-right-wall-end, if that point is on the right side of the current line
pick the closest point among the found points, connect it to the current point.
The blue dot and the blue area will need to be able to collide and to do so I need to calculate a path to create the physics body from.
I need help figuring out how I would create the path for the darker blue ring area (the darker portion of the ring within the light blue highlight).
I know it would have two arcs and two lines, but I need to be able to calculate the path based on the distance from the center and the angle (so in the image for example the angle would be 45 degrees, or PI/4, radius 1 would be 180px and radius 2 (the smaller one) would be 165px.
How would I create a dynamic path like this?