I tried to create this very unique shape in swift a long time ago but failed. My goal is to draw a shape like in this image here (I mean the darker shape in that image).
How can you create such a unique shape in Swift?
As Alexander says, it looks like that shape would be pretty easy to create using Bezier curves.
I'd suggest opening that image in a program like Photoshop that offers a Bezier path drawing tool and trying to recreate it there. Once you have the control points that get you the shape you are after, you can write down their coordinates and recreate them using a UIBezierPath in iOS.
A cubic bezier path has 2 end points and 2 middle control points. The curve moves from the starting point to the ending point, and gets pulled towards the first middle control point first, and then pulled towards the second control point. You can create a wide variety of curves that have 2 "humps" in them with a single Bezier curve, and you can chain multiple Bezier curves together to create more complex shapes. If you arrange the control points for connecting Bezier curves correctly you can get curves that transition smoothly from one to the next. With a different arrangement of the control points between Bezier curves, you can create sharp corners between curves.
I suggest you google Bezier curves, and do some experimenting.
I'm not particularly good with the path tool in Photoshop, but I got pretty close with a few minutes tinkering. here is a screen-shot:
Related
I have image of robot with yellow markers as shown
The yellow points shown are the markers. There are two cameras used to view placed at an offset of 90 degrees. The robot bends in between the cameras. The crude schematic of the setup can be referred.
https://i.stack.imgur.com/aVyDq.png
Using the two cameras I am able to get its 3d co-ordinates of the yellow markers. But, I need to find the 3d-co-oridnates of the central point of the robot as shown.
I need to find the 3d position of the red marker points which is inside the cylindrical robot. Firstly, is it even feasible? If yes, what is the method I can use to achieve this?
As a bonus, is there any literature where they find the 3d location of such internal points which I can refer to (I searched, but could not find anything similar to my ask).
I am welcome to a theoretical solution as well(as long as it assures to find the central point within a reasonable error), which I can later translate to code.
If you know the actual dimensions, or at least, shape (e.g. perfect circle) of the white bands, then yes, it is feasible and possible.
You need to do the following steps, which are quite non trivial to do, and I won't do them here:
Optional but extremely suggested: calibrate your camera, and
undistort it.
find the equation of the projection of a 3D circle into a 2D camera, for any given rotation. You can simplify this by assuming the white line will be completely horizontal. You want some function that takes the parameters that make a circle and a rotation.
Find all white bands in the image, segment them, and make them horizontal (rotate them)
Fit points in the corrected white circle to the equation in (1). That should give you the parameters of the circle in 3d (radious, angle), if you wrote the equation right.
Now that you have an analytic equation of the actual circle (equation from 1 with parameters from 3), you can map any point from this circle (e.g. its center) to the image location. Remember to uncorrect for the rotations in step 2.
This requires understanding of curve fitting, some geometric analytical maths, and decent code skills. Not trivial, but this will provide a solution that is highly accurate.
For an inaccurate solution:
Find end points of white circles
Make line connecting endpoints
Chose center as mid point of this line.
This will be inaccurate because: choosing end points will have more error than fitting an equation with all points, ignores cone shape of view of the camera, ignores geometry.
But it may be good enough for what you want.
I have been able to extract the midpoint by fitting an ellipse to the arc visible to the camera. The centroid of the ellipse is the required midpoint.
There will be wrong ellipses as well, which can be ignored. The steps to extract the ellipse were:
Extract the markers
Binarise and skeletonise
Fit ellipse to the arc (found a matlab function for this)
Get the centroid of the ellipse
hsv_img=rgb2hsv(im);
bin=new_hsv_img(:,:,3)>marker_th; %was chosen 0.35
%skeletonise
skel=bwskel(bin);
%use regionprops to get the pixelID list
stats=regionprops(skel,'all');
for i=1:numel(stats)
el = fit_ellipse(stats(i).PixelList(:,1),stats(i).PixelList(:,2));
ellipse_draw(el.a, el.b, -el.phi, el.X0_in, el.Y0_in, 'g');
The link for fit_ellipse function
Link for ellipse_draw function
I have the equations of two spheres in MATLAB, like
(x-x0)^2+(y-y0)^2+(z-z0)^2=R0^2
(x-x1)^2+(y-y1)^2+(z-z1)^2=R1^2
They have an intersecting part (I find a similar picture which could explain my meaning on the web like below)
Now I would like to only draw the spatial intersecting volume of these two spheres (like the 3D part between the curved faces with red lines in the sample image above)
Maybe I could use the command 'surface' in MATLAB to draw out those two curved faces which make up the intersecting volume? I do not know how to do it....
Moreover, I also would like to draw these two spheres after erasing out those intersecting parts
That is, my goal: drawing out the intersecting and non-intersecting part of these two spheres individually.
Could anyone help me?
Thank you!
The answer is given in great detail at Wolfram. In brief, rather than copypaste all the equations:
1) calculate the circle of intersection of the two sphere's surfaces.
2) determine the location of that circle on each sphere.
3) Calculate the volume of each sphere's spherical cap for that circle and add the two volumes to get the "lens."
I am recommending this be moved to Math.SE because it is a math problem, and coding it in Matlab is trivial.
I am analyzing back bone formation in zebrafish embryos and in this picture:
I would like to extract the shape and position of the horizontal lines/curves. Here is a little information about the image. The image at the top is already a segmented image through morphological processing and by using the MATLAB active contour function. The region between the two vertical lines is where the spinal cord develops and the horizontal lines on either side of the spinal cord later develop into ribs. The image at the bottom is where I have applied a canny edge detector. I have a time series of the development of ribs and I would now like to extract the shape and position of the horizontal curves. This is a follow up of my previous question:
Identify curves in binary image
I am guessing this will involve some kind of curve fitting module to obtain the shapes. Any ideas to go about this is very welcome.
Thanks
As an input I have a segmented image of the upper body, I'm trying to detect shoulders from this image.
I minimized the region by a threshold calculated by simple known ratios between head size and shoulder width.
Now I have the shoulders region, performed edge detection on it.
Now I need to find the points of shoulders.
is there a fast way to detect the shoulder curves ?
I'm using Matlab.
This is my input image :
Bezier Curve is just a mathematical description of a curve, (linear interpolation, using control points).
It is not a curvetracer.
If you need bezier curve descriptions, you would need to do a best fit between a bezier curve model, and the data. Before you get started, you should probably play around with bezier curves, to get a feeling of how they operate.
See here: http://www.mathworks.com/matlabcentral/fileexchange/33828-generalised-bezier-curve-matlab-code
for a Bezier Curve render, in matlab.
It displays the bezier curve, when you provide some control points.
There is a few methods to actually fit a bezier curve to a set of data, here is one for matlab (using the least squares method).
http://www.mathworks.com/matlabcentral/fileexchange/15542-cubic-bezier-least-square-fitting
It will some times work nicely, and sometimes fail miserably, this is due to the least squares method, and the uniform parameterization used. It should work OK for your shoulder problem.
you need to extract the edge data, as data points, but that should be trivial
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).