1/5/2024 0 Comments Easy contour pythonPts_df, text_df = adc_data.generate_pts_text_df() Text_df = self.data_dfĪdc_data = ADC_DataPts(data_excel, header_psn =1) Self.data_df = pd.read_excel(self.xls_fname, header = self.header_psn) Note the points shown in the Excel and plots are randomly generated.ĭef _init_(self, xls_fname, header_psn = 0): These, together with the contour data frame from above, are then feed into the seaborn lmplot. Two data frames are produced, pts_df and text_df which is the dataframe from the points and the associated text. The various points are updated in the excel sheet (or csv), shown in fig 2, and read using pandas. The regression plots are based on seaborn lmplot and the points with labels are annotated on the chart based on the individual x, and y values.īesides the seaborn, pandas, matplotlib and numpy, additional module adjustText is used to prevent overlapping of the text labels in the plotĭata_list = for BPI in BPI_tgt for ADC in ADC_tgt]ĪDC_df = pd.DataFrame(data_list, columns=) #ĪDC_df = ADC_df.astype('category')īAR_tgt =ĭata_list = for BPI in BPI_tgt for BAR in BAR_tgt]īAR_df = pd.DataFrame(data_list, columns=) #īAR_df = BAR_df.astype('category')Īdding the demo points with text from Excel The idea will be to use the regression plots for both the ADC and the BAR contours while the points and labels can be automatically added to the plots after reading from an Excel table (or csv file). Further requirements include having additional points (with labels) to be added in fairly easily and charts with different sets of data can be recreated rapidly. The two different contours shown in the plot are made up of ADC (BPI * TPI) and bit aspect ratio BAR (BPI/TPI).Ī way to create the plot might be to generate the contours based on Excel and manually added in the different points. The chart shows the areal density capacity (ADC) demo of certain samples on a bit density (BPI) by track density (TPI) chart. I was asked to create a customized contour plot based on a chart (Fig 1 ) found in IEEE Transactions on Magnetics journal with some variant in requirements. First image shows points I got with cv.CHAIN_APPROX_NONE (734 points) and second image shows the one with cv.CHAIN_APPROX_SIMPLE (only 4 points).Creating Customized Contour Plots with Labelled Points Just draw a circle on all the coordinates in the contour array (drawn in blue color). It removes all redundant points and compresses the contour, thereby saving memory.īelow image of a rectangle demonstrate this technique. This is what cv.CHAIN_APPROX_SIMPLE does. Do you need all the points on the line to represent that line? No, we need just two end points of that line. But actually do we need all the points? For eg, you found the contour of a straight line. If you pass cv.CHAIN_APPROX_NONE, all the boundary points are stored. But does it store all the coordinates ? That is specified by this contour approximation method. It stores the (x,y) coordinates of the boundary of a shape. What does it denote actually?Ībove, we told that contours are the boundaries of a shape with same intensity. This is the third argument in cv.findContours function. Note Last two methods are same, but when you go forward, you will see last one is more useful. To draw all contours, pass -1) and remaining arguments are color, thickness etc.Ĭv.drawContours(img,, 0, (0,255,0), 3) Its first argument is source image, second argument is the contours which should be passed as a Python list, third argument is index of contours (useful when drawing individual contour. It can also be used to draw any shape provided you have its boundary points. To draw the contours, cv.drawContours function is used. Until then, the values given to them in code sample will work fine for all images. Note We will discuss second and third arguments and about hierarchy in details later. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object. contours is a Python list of all the contours in the image. And it outputs a modified image, the contours and hierarchy. See, there are three arguments in cv.findContours() function, first one is source image, second is contour retrieval mode, third is contour approximation method. Im2, contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |