Im trying to calculate numerically an area of different shapes where the only thing I know about them is the (x,y) of each corner.
For example the shapes are:
P.s. The points inside the shape are for other calculation, I only need the area of the most outer shape.
Thank you.
Create polygon, and use polyarea function.
Given x,y location of corners than:
Area=polyarea(x,y)
Related
I have a set of polygons and I want to draw the smallest possible polygon around them (it has to be a rectangular shape, all inner angles 90 degrees).
To achieve this I used the bboxPolygon function from turf.js and it works okay, but it does not take in account rotation of the polygons.
For example take a look at the image bellow, the purple line is the bboxPolygon result but there is too much space at the sides, what I ultimately try to achieve is the corners should be near the topmost points of polygon 101 and bottom most of 202. Is there some other method to use to achieve this? I tried envelope but I still get the same results...
By definition, a bbox is always aligned north/south/east/west.
In this particular case, a convex hull is probably what you want. Turf supports that with the convex method.
I'm using canny edge detection to detect the edges of a rope and eliminate the background, then using morphological filters I'm filling these edges then thinning them to be in pixel size. The plot indicates the xy coordinates of the rope. What I need to do is to get the intersection of the scattered data (blue *) with the red circle (get the coordinates of Points (1,2,3,4).
Then I need to get the whole points coordinates from the point of intersection (point1,2,3,4) to the center,grouped as A,B,C,D.
The center of the circle, the origin of the axes, and the radius are all known.
I've tried some Matlab functions to get the four intersections points like
InterX,intersections
and also I tried to manually find the intersections
idx=find(y1-y2<eps);
but no method gives me the 4 intersection points.
Thank you in Advance
You'll need a thick circle. I presume (from your previous question) that the rope points are at contiguous integer coordinates. Using a thick circle (donut) with a width of 1 ensures you'll find at least one point in each rope end. Connected component analysis will then tell you which of these points belong to the same rope end.
I am trying to find coordinates of edges of the image (a rectangle, basicly) formed by this code:
%Pre-setting Variables
N=300; M=300; H=80; L=100; Alfa=10;
Tx=20; Ty=20; Tz=10;
Sx=0.6; Sy=0.7; Sz=1.2;
Tetax=20; Tetay=30; Tetaz=20;
% Forming source image
source=zeros(M,N);
source(round(M/2-L/2):round(M/2+L/2),round(N/2-H/2):round(N/2+H/2))=1;
source=imrotate(source,Alfa,'crop');
imshow(source);
disp(source);
I really have no clue how to do it, and I can't change the method of forming the image. Thank you in advance.
I recomend using corner to find the coordinates of the corner points.
And if you really just have a image of zeros and ones with a rectangle that is aligned with the pixel grid, you can also use
%y-coordinates
find(sum(img,1),1,'first')
find(sum(img,1),1,'last')
%x-coordinates
find(sum(img,2),1,'first')
find(sum(img,2),1,'last')
(or even replace sum by any)
I have a shape which you can imagine as a lake in a field observed from the top (2D). I determined the border pixels of the shape after an image processing, so that I have the coordinates of each border point.
Now I want to calculate the perimeter of this shape. My problem is that I have the points not in following order that would give a closed loop, but unordered.
How can a problem like this be solved in Matlab? (including Curve-Fitting-Toolbox etc.)
Thank you for any suggestions!
You can use the function regionprops for this.
Turn your image into a binary image with 1 inside your 'lake' and 0 outside (which you should be easily able to do, as you mention you extracted the boundaries).
Then use:
props=regionprops(YourBinaryImage, 'Perimeter');
You can then access the perimeter as follows: props.Perimeter
If you have set of 3D points with (x,y,z) coordinates, you may set z to zero and use the 2D (x,y) points to find the convex hull using convhull regardless of their order .
I created some MATLAB code, that find somes shapes in an image
using regionpros and bwbounaries functions.
I have:
STATS = regionprops(L, 'all');
and from STATS I could easily find all my shapes Area and Perimeter.
My problem is the following: I want to find the "square" shapes and I do
in all shapes the following calculation 16 * area / (perimeter * perimeter),
if this value is near one then I "may" have a square. But other shapes too like
circles or rectangles are near one too. (Also some squares could be rotated
in the image).
Is there a better way to distinguish the shapes (like circles, triangles ...)?
Matlab has a function
procrustes(X,Y)
which will compute distance between two shapes based on the types of transformations it would take to move the points defined by X onto the points defined by Y. For many shape classification tasks, minimizing this distance is a useful way of categorizing noisy instances of shapes. If your problem has 'perfect' shapes, this should work extremely well. Just have Y fixed as a perfect square, and any time that the linear transformation from X to Y is a pure scaling, then you know X is also a square. You could do some simple logical checking to select only shapes satisfying this sort of property.