def save_mesh_to_file(mesh): # Get the file name (excluding extension) from the input image path filename = os.path.splitext(os.path.basename(file.get_image_path()))[0] mesh.save(file.output_path + filename + '.stl')
level=threshold, spacing=(1., 1., 1.), gradient_direction='descent') # Export the mesh as stl mymesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype)) for i, f in enumerate(faces): for j in range(3): mymesh.vectors[i][j] = verts[f[j], :] file_utils.save_mesh_to_file(imageurl, mymesh) def ChangeContrast(self, gamma=1.0): """ change contrast of an image gamma value 1 for same image gamma value greater than 1 to increase brightness gamma value less than 1 to make image darker """ invGamma = 1.0 / gamma table = np.array([((i / 255.0)**invGamma) * 255 for i in np.arange(0, 256)]).astype("uint8") # apply gamma correction using the lookup table return cv2.LUT(self.im, table) if __name__ == "__main__": convertHatchedImageToSTL(file.get_image_path())
Contour value to search for isosurfaces in `volume`. If not given or None, the average of the min and max of vol is used. spacing : length-3 tuple of floats Voxel spacing in spatial dimensions corresponding to numpy array indexing dimensions (M, N, P) as in `volume`. gradient_direction : string Controls if the mesh was generated from an isosurface with gradient descent toward objects of interest (the default), or the opposite. The two options are: * descent : Object was greater than exterior * ascent : Exterior was greater than object ''' verts, faces, normals, values = measure.marching_cubes_lewiner( volume=voxel, level=threshold, spacing=(1., 1., 1.), gradient_direction='descent') # Export the mesh as stl mymesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype)) for i, f in enumerate(faces): for j in range(3): mymesh.vectors[i][j] = verts[f[j], :] file_utils.save_mesh_to_file(imageurl, mymesh) if __name__ == "__main__": convertGrayScaleToSTL(file.get_image_path())
Contour value to search for isosurfaces in `volume`. If not given or None, the average of the min and max of vol is used. spacing : length-3 tuple of floats Voxel spacing in spatial dimensions corresponding to numpy array indexing dimensions (M, N, P) as in `volume`. gradient_direction : string Controls if the mesh was generated from an isosurface with gradient descent toward objects of interest (the default), or the opposite. The two options are: * descent : Object was greater than exterior * ascent : Exterior was greater than object ''' verts, faces, normals, values = measure.marching_cubes_lewiner( volume=voxel, level=threshold, spacing=(1., 1., 1.), gradient_direction='descent') # Export the mesh as stl mymesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype)) for i, f in enumerate(faces): for j in range(3): mymesh.vectors[i][j] = verts[f[j], :] file_utils.save_mesh_to_file(imageurl, mymesh) if __name__ == "__main__": convertColoredImageToSTL(file.get_image_path())
gray_image[i][j] = get_gray_value_from_color( pixel_val, distinct_colors) return gray_image def get_gray_value_from_color(pixel, distinct_colors): gray_value = 0 matching_color = color_extractor.get_matching_color(pixel, distinct_colors) if matching_color is not None: gray_value = prop.get_height_map()[matching_color] * 0.1 return gray_value if __name__ == "__main__": ui.browse_image() image = cv2.imread(file.get_image_path()) distinct_colors = color_extractor.get_top_colors_hsv(image, 10) ui.assign_height_to_colors(distinct_colors) hsv_image = color_converter.get_hsv_from_bgr_image(image) gray_image = convert_from_colored_to_gray(hsv_image, distinct_colors) gray_image = cv2.medianBlur(gray_image, 3) # Perform 'closing' morphological operation on the image kernel = np.ones((1, 1), np.uint8) gray_image = cv2.morphologyEx(gray_image, cv2.MORPH_CLOSE, kernel) # Figure out the scaling parameter according to original size and then scale