Detect shapes based on their equations in an image in MATLAB - matlab

EDIT: Detection of triangle, rectangle/square or any other with sharp edges can be detected, but I'm not getting how to detect the spiral.
Is it possible to detect different shapes based on the general equation of the shape. Like for example if I give a general equation of a circle/ rectangle/ triangle/ spiral or any other shape, is it possible to detect that shape in an image?
For example if I give a general equation of the shapes, it should detect the shape in the image.
More precisely defining the problem: If I give a general equation of a triangle, it should detect the triangle and mark it.
Here's a sample input image.
I know that using some morphological analysis and edge detection is very easy for this but I have to use curve fitting, but I'm not able to know how to start, can anyone please provide an algorithm or a snippet please.

You get line detection using the hough() function and circle detection using imfindcircles() in the Image Processing Toolbox.
Alternatively, you can turn this problem around: first detect objects of interest by some means, e. g. by color, and then try to identify their shape. The regionprops() function can compute many different shape characteristics for you.
And if all else fails, you can write your own Generalized Hough Transform

Related

Matlab detect layer edge with form of parabola

I have this image:
and would like to get the points on the two black layers to calculate the area siz between the 2 layers.
What is the best way to proceed here? I was thinking to apply dijsktra algorithm or hough transform but it did not really work out.
I have some similar pictures to detect parabola.However, I only need to calculate the number. When it comes to your problem, I think you can use functions such as 'bwconncomp',and calculate the area according to the two edges.

Extract co-ordinates from detected contour

I want to detect the contour of a ring/disc which may be rotated in 3D. I used Detect circles with various radii in grayscale image via Hough Transform by Tao Peng. The results were very close to my requirement. Except for two points:
Using Tao Peng's code I could get a neat blue line indicating the detected contour. I want to access these co-ordinates (sub-pixels) for further processing. I could not figure out where these co-ordinates of detected contour are stored. If you have any idea, please let me know.
Is there any such code to detect ellipse and not only circles? This is because a ring when rotated in 3D wouldn't necessarily be a circle (in which case Tao Peng's code fails. But this is the best I have come across till date. I do not want to binarize my image, as I'll be losing out on a lot of information). Do let me know if there's anything.
Apart from this code, if there's any other one which does a similar job (even if it is like Tao Peng's code, for circles, plus gives me the co-ordinate values), please tell me.
I would prefer MATLAB, but C would also do.
This is an example image who's contour I want to detect, with high accuracy. (The outline of silver disc)
Regards.
Edit:
Here is an example of my output using Tao Peng's code.

Headlights detection using Difference of Gaussian (DoG)

I am developing a project of detecting vehicles' headlights in night scene. First I am working on a demo on MATLAB. My detection method is edge detection using Difference of Gaussian (DoG): I take the convolution of the image with Gaussian blur with 2 difference sigma then minus 2 filtered images to find edge. My result is shown below:
Now my problem is to find a method in MATLAB to circle the round edge such as car's headlights and even street lights and ignore other edge. If you guys got any suggestion, please tell me.
I think you may be able to get a better segmentation using a slightly different approach.
There is already strong contrast between the lights and the background, so you can take advantage of this to segment out the bright spots using a simple threshold, then you can apply some blob detection to filter out any small blobs (e.g. streetlights). Then you can proceed from there with contour detection, Hough circles, etc. until you find the objects of interest.
As an example, I took your source image and did the following:
Convert to 8-bit greyscale
Apply Gaussian blur
Threshold
This is a section of the source image:
And this is the thresholded overlay:
Perhaps this type of approach is worth exploring further. Please comment to let me know what you think.

How to calculate perspective transformation using ellipse

I'm very new to 3D image processing.i'm working in my project to find the perspective angle of an circle.
A plate having set of white circles,using those circles i want to find the rotation angles (3D) of that plate.
For that i had finished camera calibration part and got camera error parameters.The next step i have captured an image and apply the sobel edge detection.
After that i have a little bit confusion about the ellipse fitting algorithm.i saw a lot of algorithms in ellipse fit.which one is the best method and fast method?
after finished ellipse fit i don't know how can i proceed further?how to calculate rotation and translation matrix using that ellipse?
can you tell me which algorithm is more suitable and easy. i need some matlab code to understand concept.
Thanks in advance
sorry for my English.
First, find the ellipse/circle centres (e.g. as Eddy_Em in other comments described).
You can then refer to Zhang's classic paper
https://research.microsoft.com/en-us/um/people/zhang/calib/
which allows you to estimate camera pose from a single image if some camera parameters are known, e.g. centre of projection. Note that the method fails for frontal recordings, i.e. the more of a perspective effect, the more accurate your estimate will be. The algorithm is fairly simple, you'll need a SVD and some cross products.

How to detect curves in a binary image?

I have a binary image, i want to detect/trace curves in that image. I don't know any thing (coordinates, angle etc). Can any one guide me how should i start? suppose i have this image
I want to separate out curves and other lines. I am only interested in curved lines and their parameters. I want to store information of curves (in array) to use afterward.
It really depends on what you mean by "curve".
If you want to simply identify each discrete collection of pixels as a "curve", you could use a connected-components algorithm. Each component would correspond to a collection of pixels. You could then apply some test to determine linearity or some other feature of the component.
If you're looking for straight lines, circular curves, or any other parametric curve you could use the Hough transform to detect the elements from the image.
The best approach is really going to depend on which curves you're looking for, and what information you need about the curves.
reference links:
Circular Hough Transform Demo
A Brief Description of the Application of the Hough
Transform for Detecting Circles in Computer Images
A method for detection of circular arcs based on the Hough transform
Google goodness
Since you already seem to have a good binary image, it might be easiest to just separate the different connected components of the image and then calculate their parameters.
First, you can do the separation by scanning through the image, and when you encounter a black pixel you can apply a standard flood-fill algorithm to find out all the pixels in your shape. If you have matlab image toolbox, you can find use bwconncomp and bwselect procedures for this. If your shapes are not fully connected, you might apply a morphological closing operation to your image to connect the shapes.
After you have segmented out the different shapes, you can filter out the curves by testing how much they deviate from a line. You can do this simply by picking up the endpoints of the curve, and calculating how far the other points are from the line defined by the endpoints. If this value exceeds some maximum, you have a curve instead of a line.
Another approach would be to measure the ratio of the distance of the endpoints and length of the object. This ratio would be near 1 for lines and larger for curves and wiggly shapes.
If your images have angles, which you wish to separate from curves, you might inspect the directional gradient of your curves. Segment the shape, pick set of equidistant points from it and for each point, calculate the angle to the previous point and to the next point. If the difference of the angle is too high, you do not have a smooth curve, but some angled shape.
Possible difficulties in implementation include thick lines, which you can solve by skeleton transformation. For matlab implementation of skeleton and finding curve endpoints, see matlab image processing toolkit documentation
1) Read a book on Image Analysis
2) Scan for a black pixel, when found look for neighbouring pixels that are also black, store their location then make them white. This gets the points in one object and removes it from the image. Just keep repeating this till there are no remaining black pixels.
If you want to separate the curves from the straight lines try line fitting and then getting the coefficient of correlation. Similar algorithms are available for curves and the correlation tells you the closeness of the point to the idealised shape.
There is also another solution possible with the use of chain codes.
Understanding Freeman chain codes for OCR
The chain code basically assigns a value between 1-8(or 0 to 7) for each pixel saying at which pixel location in a 8-connected neighbourhood does your connected predecessor lie. Thus like mention in Hackworths suggestions one performs connected component labeling and then calculates the chain codes for each component curve. Look at the distribution and the gradient of the chain codes, one can distinguish easily between lines and curves. The problem with the method though is when we have osciallating curves, in which case the gradient is less useful and one depends on the clustering of the chain codes!
Im no computer vision expert, but i think that you could detect lines/curves in binary images relatively easy using some basic edge-detection algorithms (e.g. sobel filter).