0ello I'm trying creating a triangular mesh from png.
How can I extract the basic information from a image contour to create a mesh?
I used opencv module in order to extract the contours .
On xyContour variable I have essentially a path, but with a path I think that I cannot construct a mesh. How can I extract the basic infromation to create a mesh ?? I'm not sure, but I think that I need: points, facets, and/or vertices/segments/holes.
import os
import numpy as np
import cv2
from skimage import img_as_ubyte
import matplotlib.pyplot as plt
currentPath = os.path.dirname(os.path.abspath(__file__))
def Average(pixel):
return np.average(pixel)
def convertToGrayScale(image):
grey = np.zeros((image.shape[0], image.shape[1])) # init 2D numpy array
for rownum in range(len(image)):
for colnum in range(len(image[rownum])):
grey[rownum][colnum] = Average(image[rownum][colnum])
return grey
def readImage(filen):
from skimage import io
filename = os.path.join(currentPath, filen)
img = io.imread(filename)
return img
def convertToBinary(img):
from skimage import filters
thresh = filters.threshold_yen(img)
binary = img > thresh
return binary
baselayerFileName = 'MIL_NP.png'
baselayer = readImage(baselayerFileName)
baselayerGray = convertToGrayScale(baselayer)
baseLayerBin = convertToBinary(baselayerGray)
cv_image = img_as_ubyte(imgBIn)
(contours, hierarchy) = cv2.findContours(cv_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
out = np.zeros_like(cv_image.copy()).astype('uint8')
xyContour = np.transpose(np.nonzero(out))
cv2.drawContours(out, contours, -1, (255,255,255), 3)
Having the "basic" information what python module should I use? Scipy Delaunay? Meshpy? Triangle? There a lot of possibilities, but I found difficult understand what is the best, and what information each module needs in order to create the mesh.
xyContour content is here : http://pasted.co/bc45457b
the original image in attachment
Thank you very much