Search code examples
pythonr3dimagejfiji

Draw a 3d drape over the non zero non null pixels in my 3d tif image


So I have a 3d tif pixel image and want to draw a 3d drape over the non_zero non_null pixels

At first I worked in a 2d manner and passed on every slice and tried to draw a shape around and then plot them to form a 3d shape but it doesnt seem to work out

I tried the 3d suite in fiji using 3D drawing ROIs but it only drew a fixed 2d circle on every slice


Solution

  • I built a convexHull with the help of this answer which fit what I was looking for

    hull = ConvexHull(data)
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection="3d")
    
    # Plot defining corner points
    ax.plot(data.T[0], data.T[1], data.T[2], "ko")
    
    # 12 = 2 * 6 faces are the simplices (2 simplices per square face)
    for s in hull.simplices:
        s = np.append(s, s[0])  # Here we cycle back to the first coordinate
        ax.plot(data[s, 0], data[s, 1], data[s, 2], "r-")
    
    # Make axis label
    for i in ["x", "y", "z"]:
        eval("ax.set_{:s}label('{:s}')".format(i, i))
    
    plt.show()