contour

Sorting contours left to right in Python (OpenCV)

梦想与她 提交于 2019-12-03 03:58:56
I'm using Python and OpenCV to detect contours in my image. But when I run the following code to draw only a specific contour using the contour index, since the indices allocated are random, I get the wrong output. So I found out the Centroids (in my case all the centroids lie in the same horizontal line). Is there any way I can sort the contour indices from left to right (starting from 0 to n) based on the x value of the centroid? Could you please show the code for the same? Any help would be greatly appreciated! contours, hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX

Matplotlib streamplot arrows pointing the wrong way

青春壹個敷衍的年華 提交于 2019-12-03 03:41:32
I am generating a groundwater elevation contour and a streamplot in matplotlib The contour indicates that the elevation is decreasing in many areas but the groundwater flow (streamplot) is pointed uphill. I have circled the arrows that seem to be pointed the wrong direction. The arrows toward the bottom of the map appear to be pointed the correct direction. Does anyone know why this might be? And here is most of the code which generates this plot: #create empty arrays to fill up! x_values = [] y_values = [] z_values = [] #iterate over wells and fill the arrays with well data for well in well

3D Contour plot from data using Mayavi / Python

醉酒当歌 提交于 2019-12-03 03:21:16
问题 I would like to do a 3D contour plot using Mayavi in exactly the same way as the third figure on this page (a hydrogen electron cloud model) : http://www.sethanil.com/python-for-reseach/5 I have a set of data points which I created using my own model which I would like to use. The data points are stored in a multi-dimensional numpy array like so: XYZV = [[1, 2, 3, 4], [6, 7, 8, 9], ... [4, 5, 6, 7]] The data points are not uniformly spread in XYZ space and not stored in any particular order.

contour plot of a custom function in R

扶醉桌前 提交于 2019-12-03 02:53:22
I'm working with some custom functions and I need to draw contours for them based on multiple values for the parameters. Here is an example function: I need to draw such a contour plot: Any idea? Thanks. First you construct a function, fourvar that takes those four parameters as arguments. In this case you could have done it with 3 variables one of which was lambda_2 over lambda_1. Alpha1 is fixed at 2 so alpha_1/alpha_2 will vary over 0-10. fourvar <- function(a1,a2,l1,l2){ a1* integrate( function(x) {(1-x)^(a1-1)*(1-x^(l2/l1) )^a2} , 0 , 1)$value } The trick is to realize that the integrate

Drawing labels on flat section of contour lines in ggplot2

南楼画角 提交于 2019-12-03 02:17:26
In a previous question , I reproduced a contour plot generated with the fields package, in ggplot2 instead (full example below). The only trouble is, I would like to replicate the placement of the contour labels in contour() , which by default are at the "flattest" part of the line - the second picture might show why. I'm stumped by how to set up that calculation. I see here that it's possible to grab the data used to generate the contour lines, and then geom_text() could be used to plot the text. So what's left is figuring out how to calculate the "flattest" part. Ideas? library(fields)

Draw axis lines or the origin for Matplotlib contour plot

[亡魂溺海] 提交于 2019-12-03 01:23:40
I want to draw x=0 and y=0 axis in my contour plot, using a white color. If that is too cumbersome, I would like to have a white dot denoting where the origin is. My contour plot looks as follows and the code to create it is given below. xvec = linspace(-5.,5.,100) X,Y = meshgrid(xvec, xvec) fig = plt.figure(figsize=(6, 4)) contourf(X, Y, W,100) plt.colorbar() There are a number of options (E.g. centered spines ), but in your case, it's probably simplest to just use axhline and axvline . E.g. import numpy as np import matplotlib.pyplot as plt xvec = np.linspace(-5.,5.,100) x,y = np.meshgrid

matplotlib contour plot: proportional colorbar levels in logarithmic scale

不羁岁月 提交于 2019-12-03 00:48:50
Would it be possible to have levels of the colorbar in log scale like in the image below? Here is some sample code where it could be implemented: import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LogNorm delta = 0.025 x = y = np.arange(0, 3.01, delta) X, Y = np.meshgrid(x, y) Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) Z = 1e6 * (Z1* Z2) fig=plt.figure() ax1 = fig.add_subplot(111) lvls = np.logspace(0,4,20) CF = ax1.contourf(X,Y,Z, norm = LogNorm(), levels = lvls ) CS = ax1.contour(X,Y,Z, norm =

How to draw anti aliased lines in OpenGL ES 2.0?

我与影子孤独终老i 提交于 2019-12-03 00:32:46
I am trying to draw some contours that I have stored as vertex arrays: typedef struct { float* vertices; int nrPoints; }VertexCurve; list<VertexCurve> CurveList; I am using some samples from an opengl es 2.0 book : http://opengles-book.com/ The drawing method looks like this: void Draw ( ESContext *esContext ) { UserData *userData = (UserData*)esContext->userData; // Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ); // Clear the color buffer glClear ( GL_COLOR_BUFFER_BIT ); // Use the program object glUseProgram ( userData->programObject ); //glEnable(GL_SAMPLE_ALPHA

OpenCV - using cv2.approxPolyDP() correctly

故事扮演 提交于 2019-12-02 20:54:55
I am trying to extract an approximation of a contour in an image, using cv2.approxPolyDP() . Here's the image I am using: My code attempts to isolate the main island and define and plot the contour approximation and contour hull. I have plotted the contour found in green, the approximation in red: import numpy as np import cv2 # load image and shrink - it's massive img = cv2.imread('../data/UK.png') img = cv2.resize(img, None,fx=0.25, fy=0.25, interpolation = cv2.INTER_CUBIC) # get a blank canvas for drawing contour on and convert img to grayscale canvas = np.zeros(img.shape, np.uint8)

Plot 3D Contour from an Image using extent with Matplotlib

断了今生、忘了曾经 提交于 2019-12-02 18:04:56
问题 As I present here (in 2D), I'm wondering if how I could "scale" an image input to be plotted to a range in the plot. To be more clear, this is what I need: I have a 400 * 400 image that is generated based on a function which interval is -1..1. So, I do a translate to save this data, like this: x = Utils.translate(pos_x, 0, self.width, -1, 1) y = Utils.translate(pos_y, 0, self.height, -1, 1) data = Utils.map_position_to_function(x, y) I.e, first I map its position to my range and then I