centroid

How to Calculate Centroid

雨燕双飞 提交于 2020-01-01 10:10:12
问题 I am working with geospatial shapes and looking at the centroid algorithm here, http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon I have implemented the code in C# like this (which is just this adapted), Finding the centroid of a polygon? class Program { static void Main(string[] args) { List<Point> vertices = new List<Point>(); vertices.Add(new Point() { X = 1, Y = 1 }); vertices.Add(new Point() { X = 1, Y = 10 }); vertices.Add(new Point() { X = 2, Y = 10 }); vertices.Add(new Point()

Explanation of Matlab's bwlabel,regionprops & centroid functions

戏子无情 提交于 2019-12-29 05:34:12
问题 I have spent all day reading up on the above MATLAB functions. I can't seem to find any good explanations online, even on the MathWorks website! I would be very grateful if anyone could explain bwlabel , regionprops and centroid . How do they work if applied to a grayscale image? Specifically, they are being used in this code below. How do the above functions apply to the code below? fun=@minutie; L = nlfilter(K,[3 3],fun); %% Termination LTerm=(L==1); figure; imshow(LTerm) LTermLab=bwlabel

Create square polygons from single centre coordinates and area in R

若如初见. 提交于 2019-12-23 12:34:30
问题 I am having issues plotting true to geographic extent pixels in R. the files come with a list of daily single coordinates and pixel size (area). There is also a Z element separate from this. The data structure looks this way: X <- c(1,3,6,7) Y <- c(3,2,7,8) Z <- c(38,23,12,12) Area <- c(32,23,45,67) The X and Y are in degrees longitude and latitude while the area is in square kilometres. I create the point features easily using: library(sp) A <- cbind(X,Y,Z,Area) B <- SpatialPoints(A) I plot

how to set initial centers of K-means openCV c++

你。 提交于 2019-12-22 13:47:29
问题 I am trying to do a segmentation of an image using OpenCv and Kmeans, the code that I have just implemented is the following: #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; using namespace cv; int main(int, char** argv) { Mat src, Imagen2, Imagris, labels, centers,imgfondo; src = imread("C:/Users/Sebastian/Documents/Visual Studio 2015/Projects/ClusteringImage

Weighted Centroid of an Array

拥有回忆 提交于 2019-12-21 16:47:10
问题 So I have a 2-dimensional array representing a coordinate plane, an image. On that image, I am looking for "red" pixels and finding (hopefully) the location of a red LED target based on all of the red pixels found by my camera. Currently, I'm simply slapping my crosshairs onto the centroid of all of the red pixels: // pseudo-code for(cycle_through_pixels) { if( is_red(pixel[x][y]) ) { vals++; // total number of red pixels cx+=x; // sum the x's cy+=y; // sum the y's } } cx/=vals; // divide by

Better “centerpoint” than centroid

最后都变了- 提交于 2019-12-21 09:10:12
问题 I'm using the centroid of polygons to attach a marker in a map application. This works definitely fine for convex polygons and quite good for many concave polygons. However, some polygons (banana, donut) obviously don't produce the desired result: The centroid is in these cases outside the polygons area. Does anybody know a better approach to find a suitable point within any polygons area (which may contain holes!) to attach a marker? 回答1: One approach would be to generate and refine a

Calculate Centroid WITHIN / INSIDE a SpatialPolygon

依然范特西╮ 提交于 2019-12-19 06:44:33
问题 In Software like ArcMap one can create centroids for polygons within a polygon. In cases like the one shown below this is necessary. In R it is possible to calculate centroids of spatial polygons with rgeos::gCentroid() . However there is no way to force the calculation of centroids within the polygon. library(rgdal) library(rgeos) x <- readWKT("POLYGON ((1441727.5096940901130438 6550163.0046194596216083, 1150685.2609429201111197 6669225.7427449300885201, 975398.4520359700545669 6603079

Calculate Centroid WITHIN / INSIDE a SpatialPolygon

我是研究僧i 提交于 2019-12-19 06:44:32
问题 In Software like ArcMap one can create centroids for polygons within a polygon. In cases like the one shown below this is necessary. In R it is possible to calculate centroids of spatial polygons with rgeos::gCentroid() . However there is no way to force the calculation of centroids within the polygon. library(rgdal) library(rgeos) x <- readWKT("POLYGON ((1441727.5096940901130438 6550163.0046194596216083, 1150685.2609429201111197 6669225.7427449300885201, 975398.4520359700545669 6603079

Extract centroid of shape file object in R?

自闭症网瘾萝莉.ら 提交于 2019-12-13 16:44:17
问题 I have a shape file, uploaded at the following path: https://drive.google.com/open?id=0B1ITb_7lHh1EUFVfVWc4ekRfSnc I imported the data using the "read.shapefiles" function in "shapefiles" package: landuse<- read.shapefile("landuse") I now need to extract the lat/long centroids of all the shapes within the landuse object and add it to the landuse$dbf dataframe I tried two things: lu_df<-coordinates(landuse) lu_df<-SpatialPoints(landuse) Both gave me the following error: Error in coordinates(as

Finding an Images Contours Centroid

此生再无相见时 提交于 2019-12-11 12:47:49
问题 I am trying to calculate an image centroid like so: // Calculate centroid double signedArea = 0.0; sskp_point centroid; for(int i=0;i<numPoints;i++) { double a = (points[i].x*points[(i+1)%numPoints].y)-(points[(i+1)%numPoints].x*points[i].y); signedArea += a; centroid.x += (points[i].x*points[(i+1)%numPoints].x)*a; centroid.y += (points[i].y*points[(i+1)%numPoints].y)*a; printf("points[%d] = { %f, %f }\n",i,points[i].x,points[i].y); } signedArea /= 2.0; centroid.x /= (6*signedArea); centroid