Find thick and odd shapes on an image - algorithm

I am coding a specific edge detection algorithm. The image is black and red as given below. I am trying to extract red points that make a horizontal or vertical line and trying to get rid of anything that doesn't make a line shape. Some odd shapes are the ones that I later circled in yellow. The problem is that I cannot define the shapes exactly. The thing is they are 'thick'. They can be solid as in the upper left yellow circle or in pieces like the one below it. The only thing is they do not help me making a horizontal and vertical line on the image.
I am coding in Matlab, but any idea of algorithms are also welcome.

Related

Find the corner points of a set of pixels that make up a quadrilateral boundary

I have a situation where I have a set of pixels that make up the border of a quadrilateral (very close to square). I'm trying to determine the location of the corners as best as possible and have been struggling for a while now. My first thought was to determine the straight lines of the border and then calculate the corner points, but I don't have access to OpenCV or other image processing libraries, unfortunately.
Below are three cases where the black outline is the image boundary and the red outline is the quadrilateral boundary. I have a list of all of the pixels that make up the red boundary and the red boundary thickness may vary.
My initial thought was that I could just find the pixel that is closest to each of the four image boundaries, however this won't quite work for the first case where the inner quadrilateral isn't tilted.
Any thoughts on how to tackle this problem would be great. I'm coding in dart, but am looking for a psuedocode answer that I can implement myself.
(I have seen this post, which is similar to my problem, but I think there should be a simpler solution for my problem since I have access to all of the boundary points of the quadrilateral)
Having a list of all rectangle boundary pixels, you can use simple methods like this:
Calculate gravity center of rectangle (just sum X- and Y- coordinates of pixels and divide by their number) - it is diagonal intersection.
Find the farthest pixels - they are corners.
In case of bad quality of data set (empty places, excessive pixels) center calculation might be inexact. So you can apply Hough transform to extract sides (as lines) and calculate their intersections.

hough transform in a rectangular shape

Our aim, find vanishing point of rectangular shape. I want to apply hough transform this shape with y=mx+c. Than, after hough transform, I have to show two or more vote points on (m,c) axis second shape. I dont know how I apply. please help me.
The idea of Hough transform is that you basically draw all possible lines and then try to figure out which ones are really present in the image.
So, for your images, try to draw all possible horizontal/vertical lines and count the black points under each. Fot example - take horizontal line with y = 0(1,2,3..). Check the color of all points with x=[0...width] and y=0. If all or most of them are black - you have a line. Repeat with y=[1...height].
After you have the coordinates of all lines, you can find the gaps in each line in the same fashion - check all the points that should belong to the line and note the white ones. When you have enough white points in a row - there is a gap.
This method will help detecting few points of a figure on your first picture. Then you just have to connect them together to get your shape.

Remove incorrect pixels from polygons

I have generated set of points, that create polygonal areas border. On image below, there is an example of what I mean. The black "spots" should not be there and line should be "clear". I need to remove those points.
Now the problem is double. First, I dont know, how this situation is called. Its not aliasing or jagged edge, because those points are not obtained from line generating algorithm, but from contour generator.
And if not the name, than at least some push, how to solve this, would help me.
So far, I have tried convert this to chain code and simplify it, but that didnĀ“t worked very well and it was rather slow. Convert those dots to geometry and use Ramer algorithm to simplify geometry works better, but it destroy some "fine" detail, that should be there.
You can try the following:
First search for these spots. From your figure it seems that the spots look something like the following:
1 1
1 1
That is, a square matrix of colored pixels. Such spots can easily be found by traversing the pixel matrix once.
Now once you identify these spots, you will need to check for the neighbouring pixels and see what pattern is the curve/line following and accordingly delete the unnecessary pixels.
Separate the contour curves and clean each one by itself.
For each contour:
If the curve is not closed, close it with a temporary line.
Flood-fill the contour curve to get a solid monochrome figure.
Run contour detection on the result. The edge of a monochrome figure will be a clean line.
Flood-fill the area outside the new contour curve.
Run contour detection one last time to restore the original contour.
Re-assemble the contours into a single bitmap.

How can I animate a SVG Text element to skew relative to a polygon

Okay so I have a polygon, and I want to skew text, so it looks like the polygon contains the text. It is probably easier to just show what I mean. Below is an example, I have written a method to dynamicly manipulate the polygon vertices. This animation is to show a page folding over in a book.
http://jsfiddle.net/sdjqw/
Anyway, as seen in the example, I need to skew the text relative to blue polygon (at the moment it is only clipped based on the blue polygons position). So the blue page shows what is n it correctly. If this is not possible, are there any good alternatives?
On a sidenote, in this example i have applied shading to the blue element, but it appears on 3 sides, any simple way to make it only appear on a single side?
I have also been looking at to just rotate and move the text, I think this could possibly work, but is not my ideal solution.

detect triangle in bitmap

Working on an android app, I have a bitmap obtained by applying edge detection on some image.
Black background bitmap with white lines as edges.
I need to identify the first closed boundary moving outward from the
centre and check if it is a triangle.
How do I do that? Even a methodology if not code sample would
be of much help.
This is modified Hough transform, a little optimized for this problem.
Assuming that you applied edge detection and edge is white pixel.
Find boundary. Move from center to outside and find first white pixel. Repeat for as many direction as you want.
Find lines. Route line through pixels that are neighbours (take two pixels or find equation to route line through more than two pixels) and check how many white pixels are under the line. The more pixel under line, the better line it is. Take into account intersection with another lines and count white pixels till the intersection.
Identify triangle. If boundary is builded from 3 good lines then it is a triangle.
It's only idea, I'll hope that help.

Resources