I have spurious lines appearing on a highcharts stock chart, best illustrated by the included screenshot. They are sloping lines, which begin at 0,0 and zoom up to join the 'actual' data lines, as can be seen.
Does anybody have any idea why this is happening?
I can find no mention of it anyhwere.
Spurious splines
Related
I have a contour in Opencv with a convexity defect (the one in red) and I want to cut that contour in two parts, horizontally traversing that point, is there anyway to do it, so I just get the contour marked in yellow?
Image describing the problem
That's an interesting question. There are some solutions based on how the concavity points are distributed in your image.
1) If such points does not occur at the bottom of the contour (like your simple example). Then here is a pseudo-code.
Find convex hull C of the image I.
Subtract I from C, that will give you the concavity areas (like the black triangle between two white triangles in your example).
The point with the minimum y value in that area gives you the horizontal line to cut.
2) If such points can occur anywhere, you need a more intelligent algorithm which has cut lines that are not constrained by only being horizontal (because the min-y point of that difference will be the min-y of the image). You can find the "inner-most" corner points, and connect them to each other. You can recursively cut the remainder in y-,x+,y+,x- directions. It really depends on the specs of your input.
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.
I already had two questions on here (Undistorting/rectify images with OpenCV and Improve cvFindChessboardCorners) which led me to the cause of my problem.
So, as you can see in this picture (http://abload.de/img/cvfindchessboardcornet9pn4.jpg) all inner corners of this chessboard are found except the ones in the upper left area.
For the second image, I tried interpolating the coordinates of found corners both in vertical and horizontal direction in order to calculate their intersection, but I couldn't locate the corner that way (the x-coordinate was correct, but the y-coordinate wasn't due to the curvature of the interpolating polnomials).
Problem: The trouble is, that interpolation won't work in the first picture, because there is no such polynomial, at least for the interpolation in vertical direction (because that would be in conflict with the fundamental definition of a mathematical function.
So, I'm really clueless, how to extract the remaining coordinates of the corners which cannot be found by cvFindChessboardCorners
How many way to tell if a photo (in a few lines) in opencv
In the example below that line there are 3
http://www.uploadimage.co.uk/images/1511642.jpg
Thanks
Try dilating the white portion of the image first. This will make the black strip thinner. Once it is thin comparatively, you could use hough lines transform which returns an array of lines it finds. The task would then be as simple as counting the number of elements in the arrray. Of course, you will have to do a lot of trial and error in passing appropriate parameters to the Hough transform, lest it returns you closely spaced lines which represent the same region in your image. You might probably need to group the lines based on the slope and the intercept also.
Are there any implementations or papers that modify the Hough transform to detect the width of line segments? Hough space maxima can be used to determine potential lines, and line segments are groups of pixels that are on the line for sufficient intervals. After doing that, I'm trying to determine the width of each line segment.
All I've been able to find thus far is this poster:
http://www.cse.cuhk.edu.hk/~lyu/staff/SongJQ/poster_47_song_j.pdf
Depending if you are willing to spend some money, there is a package called Halcon that has the kind of things you are after.
For example http://www.mvtec.com/download/reference/lines_gauss.html (that's not a Hough transform, but the main package does have those as well).
I used Google to find a paper called "Extraction of Curved Lines from Images" which mentions line width (I can't get the link to work either).
If you have a binary mask for each line segment could you possibly take the maximum of the distance transform on that line segment? It should tell you how far away the center of the line is from the edge, the width should be 2*max(distanceTranform(segment)) - 1 for odd widths and 2*max(distanceTranform(segment)) for even widths.
OpenCV has an implementation of this method here. They also have HoughLinesP to detect line segments, but sounds like you already have that worked out.