contour

How to overlay a pcolor plot with a contour plot that uses a different colormap?

瘦欲@ 提交于 2019-12-01 01:20:06
问题 Minimum example that does not achieve it: [X,Y,Z] = peaks; figure; pcolor(X,Y,Z); shading flat; hold all; axes; contour(X,Y,Z); colormap gray; % this should only apply to the contour plot axes... axis off; % ... but it doesn't This shows both the contour plot and the pseudo colour plot in the grayscale colourmap. However, what I want to achieve is only turning the contours gray. This is just a minimalistic example, in reality the contour plot is of different data that has a different range,

Problems during Skeletonization image for extracting contours

南笙酒味 提交于 2019-11-30 23:06:54
I found this code to get a skeletonized image. I have a circle image ( https://docs.google.com/file/d/0ByS6Z5WRz-h2RXdzVGtXUTlPSGc/edit?usp=sharing ). img = cv2.imread(nomeimg,0) size = np.size(img) skel = np.zeros(img.shape,np.uint8) ret,img = cv2.threshold(img,127,255,0) element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3)) done = False while( not done): eroded = cv2.erode(img,element) temp = cv2.dilate(eroded,element) temp = cv2.subtract(img,temp) skel = cv2.bitwise_or(skel,temp) img = eroded.copy() zeros = size - cv2.countNonZero(img) if zeros==size: done = True print("skel") print

Navigate through hierarchy of contours found by FindContours method?

雨燕双飞 提交于 2019-11-30 21:44:17
This must be simple for C++ developers using OpenCV directly. However what I'm using is Emgu (an OpenCV wrapper for .NET) and in the latest version we have the method CvInvoke.FindContours returning void, the output result is passed by parameter reference and is of type VectorOfVectorOfPoint . Here is a simple call: //outputResult is a VectorOfVectorOfPoint CvInvoke.FindContours(inputImage, outputResult, null, RetrType.Tree, ChainApproxMethod.ChainApproxSimple); For RetrType.List mode, we can just convert the result to some array of arrays and loop through all the contours easily. However here

How can I calculate the area within a contour in Python using the Matplotlib?

Deadly 提交于 2019-11-30 16:08:57
I am trying to figure out a way to get the area inside a specific contour line? I use matplotlib.pyplot to create my contours. Does anyone have experience for this? Thanks a lot. From the collections attribute of the contour collection, which is returned by the contour function, you can get the paths describing each contour. The paths' vertices attributes then contain the ordered vertices of the contour. Using the vertices you can approximate the contour integral 0.5*(x*dy-y*dx), which by application of Green's theorem gives you the area of the enclosed region. However, the contours must be

Choosing isolines from Matlab contour function

纵然是瞬间 提交于 2019-11-30 16:06:41
问题 The Matlab contour function (and imcontour) plots isolines of different levels of a matrix. I would like to know: How can I manipulate the output of this function in order to receive all the (x,y) coordinates of each contour, along with the level? How can I use the output [C,h] = contour(...) to achieve the aforementioned task? Also, I am not interested in manipulating the underlying grid, which is a continuous function, only extracting the relevant pixels which I see on the plot . 回答1: You

Drawing an iso line of a 2D implicit scalar field

假装没事ソ 提交于 2019-11-30 15:13:21
I have an implicit scalar field defined in 2D, for every point in 2D I can make it compute an exact scalar value but its a somewhat complex computation. I would like to draw an iso-line of that surface, say the line of the '0' value. The function itself is continuous but the '0' iso-line can have multiple continuous instances and it is not guaranteed that all of them are connected. Calculating the value for each pixel is not an option because that would take too much time - in the order of a few seconds and this needs to be as real time as possible. What I'm currently using is a recursive

OpenCV C++/Obj-C: Connect nearby contours

大兔子大兔子 提交于 2019-11-30 14:46:56
Is there a function to connect two (or more) nearby contours? Take a look at my in-/output and you'll see what I mean … My code: [... some processing ...] // getting contours std::vector<std::vector<cv::Point> > contours; findContours(input, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); // approximate contours std::vector<std::vector<cv::Point> > contours_poly( contours.size() ); for( int i = 0; i < contours.size(); i++ ) { approxPolyDP(cv::Mat(contours[i]), contours_poly[i], 5, true ); } // debugging cv::Scalar colors[3]; colors[0] = cv::Scalar(255, 0, 0); colors[1] = cv::Scalar(0, 255

Closing a contour curve in OpenCV

*爱你&永不变心* 提交于 2019-11-30 12:22:40
I'm using OpenCV (Canny + findCountours) to find external contours of objects. The curve drawn is typically almost, but not entirely, closed. I'd like to close it - to find the region it bounds. How do I do this? Things considered: Dilation - the examples I've seen show this after Canny, although it would seem to me it makes more sense to do this after findContours Convex hull - might work, though I'm really trying to complete a curve Shape simplification - related, but not exactly what I want Using PolyLine method to draw contours cv2.PolyLine(img, points, is_closed=True, 255, thickness=1,

How do you create a legend for a contour plot in matplotlib?

半世苍凉 提交于 2019-11-30 11:52:33
问题 I can't seem to find the answer anywhere! I found a discussion here, but trying this I get a TypeError: 'NoneType' object is not iterable : >>> import numpy as np >>> import matplotlib.pyplot as plt >>> x, y = np.meshgrid(np.arange(10),np.arange(10)) >>> z = x + y >>> cs = plt.contourf(x,y,z,levels=[2,3]) >>> cs.collections[0].set_label('test') >>> plt.legend() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions

opencv find concave hull

两盒软妹~` 提交于 2019-11-30 07:31:59
问题 I have a set of discrete points shown in an image, like the following I want to reconstruct or up sampling (I'm not sure what's the correct way to describe it) the image, so that the result image would be like the following . It doesn't need to be exactly the same as the example image, but the main idea is to fill up the original one. I have an initial idea about how to do it. But I don't know how to do it after the first step. My idea is to first separate image using kmeans and find out the