Image to Textured Anulus (Ring) Python Tool

Image to Textured Anulus (Ring) Python Tool

thingiverse

originally this was a script to convert images to height maps as polyhedrons suitable for use in openscad...now it has become a tool for making height map textured ring shapes ToDo add control for fading edges of image v0-13 modifications based on prototype from i.materialise Ring .stl internal diameter seemed to be 6 or 16.5mm, but size is entered correctly as 6.5 or 16.9mm which is correct GENERATING A NON-TEXTURED RING GIVES CORRECT DIMENSIONS however adding an embossed texture to the inside adds material Fixed!!! in... if texture: if texture_inside_not_outside: print "texture inside not outside" if texture_engraved_not_raised: #changes made here to fix texture size issue NOW vertex_list.append([row*height_scaling,column,texture_depth - (pix[row,column]*depth_scaling) ]) WAS vertex_list.append([row*height_scaling,column, - (pix[row,column] *depth_scaling) ]) sizes/etc changed for 2nd prototype/production version texture_depth=0.2 #to match prototype which turned out well, default was 0.5 ring_width=4.4 #to match engagement ring, default was 4 inputImage = 'slightlycleanedbetter_text.png' to include engraving text texture_height_ring_circum_ratio=1#changed from 0.6 to take account of longer texture image featuring text doming looks good now with adjusted shape v0-12 add control for how much of ring is covered in pattern added texture_scale ability possibly this introduces shadows at the edges... perhaps have option to trim 1 pixel from each edge before using for texture to prevent this? identified possible bug with texture direction when only using partial coverage identified possible bug where back vertical edges have gaps...possibly due to ctrl+h replacing of width and height previously...blergh! reduced the number of holes and bad edges but still not perfect... this requires further attention as at the moment it generates bad .STLs!!! fixed!!! v0-11 Now can directly make the entire ring! ability to invert/flip/rotate image add control over emboss/engrave fix jumbled up width and height removed openscad output options to functions removed make_square section to function add control for placing image on inner/outer surface control the shapes of inner/outer surface so can directly create final ring curvature direction and amount on inner and outer surface add 2 separate ellispe radii for each surface implementing simple control over curving in second direction fixed some bugs where curved surfaces shape and change in height was miscalculated Only tested on combinations of flat and convex...possibly bugs in concave surfaces??? v0-10 implement curving in second direction cleanup code v0-9 Moved items to main fixed calculation of ring width added ability to connect ends together so you can get a complete ring add option for direct output in ascii .stl format (from https://en.wikipedia.org/wiki/STL_ %28file_format%29 ) An STL file describes a raw unstructured triangulated surface by the unit normal and vertices (ordered by the right-hand rule) of the triangles using a three-dimensional Cartesian coordinate system. STL coordinates must be positive numbers, there is no scale information, and the units are arbitrary. An ASCII STL file begins with the line: Line 1 solid name where name is an optional string (though if name is omitted there must still be a space after solid). The file continues with any number of triangles, each represented as follows: Line 2 to n-1 facet normal ni nj nk In both ASCII and binary versions of STL, the facet normal should be a unit vector pointing outwards from the solid object. In most software this may be set to (0,0,0) and the software will automatically calculate a normal based on the order of the triangle vertices using the 'right-hand rule' outer loop vertex v1x v1y v1z vertex v2x v2y v2z vertex v3x v3y v3z endloop endfacet where each n or v is a floating point number in sign-mantissa 'e'-sign-exponent format, e.g., "-2.648000e-002". The file concludes with: Line n endsolid name v0-8 3d graph of vertex points with ID numbers v0-7 simple hack around failure with non-square images by adding blank pixels to edges to make it square! This works but leaves flat parts at the edges uses the maxima from im.extrema() to scale the texture heights uses user input to select width of output polygon via x position of vertex points began attempt to join ends together v0-6 vertex array is now curved in 1 dimension v0-5 all data is saved to arrays rather than written immediately to file this will allow for easier editing v0-4 moved all polygon and triangle surface generation (textured top, flat bottom & sides) into single block swapped order of side 4 in attempt to fix winding order This can now generate a valid 3d polyhedron... but openscad has trouble with non-square input textures (not sure why) v0-3 2013-01-09 Now able to generate all surfaces...still need to integrate this all into one method (removing special values) so they can form one object! Cleaned up section that generates upper surface so it is more like that used to generate subsequent surfaces (easier to read and integrate) v0-2 2013-01-09 converted to use load() (for better speed) based on http://stackoverflow.com/questions/11064786/get-pixels-rgb-using-pil Add option to output simple cube (set op_format=1) or ployhedron (triangles) based maps (set op_format=0) added base_thickness added ability to direct output to file (greatly speeds up operation) Fixed output of base polygon so it appears at the end! Having difficulties generatign the edges and sides v0-1 2013-01-08 simple script to open a simple diagonal greysale_10x10_diagonal image in multiple formats and extract pixel data for manipulation code initially taken from here http://stackoverflow.com/questions/14111705/python-displaying-a-grayscale-image It will calculate the "elevation" for each pixel using the average RGB value as a height, kinda like a height/bump-map an attempt to create an openscad compatible ployhedron object containing a list of vertices and triangles Note: Current output can be viewed in Openscad but cannot be rendered and output unless input is square!!! Instructions You will need the following: Python 2.X (tested with 2.7) Python modules: Python Image Library (PIL) PyLab NumPy simple_graphs (custom library available on this page) A greyscale height mapped image you want to be applied to the ring Time... as the output files may take a long time to generate and open. For example an input image file of 76x953 pixels took ~5 minutes to generate on a basic PC and generated a file of several 200+MB which took about 1 minute just to open in a .stl viewer. This file ended up being too large for i.materialise to accept and so it had to be down-sampled significantly. Once you have these simply set the following

Download Model from thingiverse

With this file you will be able to print Image to Textured Anulus (Ring) Python Tool with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Image to Textured Anulus (Ring) Python Tool.