3

My computer setup is Mac Mojave 10.14.4. I am new to Python so I am using Jupyter Lab so that I can understand what each part is producing so please can you respond similarly.

I want to produce a 3d surface plot of a digitally printed fabric sample with z-axis plotting the color space.

Here is the hardcopy file.

[Test Sample Dots Print]

Here is the 3dContour plot of the same test fabric

Ultra Cotton Plot

img = cv2.imread(testROYGBIVB.jpg) img - cv2.cvtColor(img,  
cv2.COLOR_BGR2HSV)

plt.imshow(img)
img0 = img
img0.shape
(70, 90,3)

x, y, z = img0.T
x = np.linspace(0, 7, 70) #start, step, total
y = np.linspace(0, 9, 90)
X, Y = np.meshgrid(x, y) 
Z = np.invert(z) #makes it easier to view

font = {'family': 'sans-serif',
    'color':  'black',
    'weight': 'normal',
    'size': 16,
    }

 fig = plt.figure()

 ax = plt.axes(projection='3d')
 ax.contour3D(X, Y, Z, 256, cmap='cubehelix_r')
 ax.set_xlabel('x',fontdict=font)
 ax.set_ylabel('y',fontdict=font)
 ax.set_zlabel('z',fontdict=font); #RGB values
 ax.set_title('Ultra Cotton',fontdict=font);

 plt.tight_layout()
 plt.savefig('UltaCotton.png')
 ax.view_init(60, 35)
 fig

[Awesomeness from Abov]

My question is this - the color space values of my plot are HSV. I can split these values as seen below to create a scatter.

But I would like to maintain the rod structure from the contour but with the color of the rods matching the defined color space HSV as seen in the scatter.

I would like my contour plot and my scatter plot to have a hybrid baby.

FYI - the z values were inverted so that the top surface would be easily visible.

Can this be done? Thanks

flags = [i for i in dir(cv2) if i.startswith('COLOR_')]
len(flags)
258
flags[40]
'COLOR_BGR2RGB'

hsv_img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
pixel_colors = img.reshape((np.shape(img)[0]*np.shape(img)[1], 3))
norm = colors.Normalize(vmin=-1.,vmax=1.)
norm.autoscale(pixel_colors)
pixel_colors = norm(pixel_colors).tolist()

h, s, v = cv2.split(hsv_img)
fig = plt.figure()
axis = fig.add_subplot(1, 1, 1, projection="3d")
axis.scatter(h.flatten(), s.flatten(), v.flatten(), facecolors=pixel_colors,    marker=".")
axis.set_xlabel("Hue")
axis.set_ylabel("Saturation")
axis.set_zlabel("Value")
plt.show()

![X,Y,Z split for Hue Sat and Val]4

plt.tight_layout()
plt.savefig('filename.png')
axis.view_init(45, 35)
#ax.set_title('Ultra Cotton');
plt.tight_layout()
plt.savefig('filenameView.png')
fig

[same as before better viewing angle]

Krackle
  • 363
  • 1
  • 3
  • 9
  • I do have some problems understanding the actual question here, particularly because some parts seem to doubled. In any case, it seems part of your problem simply stems from the fact that there is no `linespace` in numpy - which is because it's called `linspace` (without *e*). – ImportanceOfBeingErnest Apr 24 '19 at 01:25
  • I need an alternative way to create this plot while I try to figure out numpy. I'm new. But there has to be someone out there with the knowledge about a different library or some kind of work around. My long question above was spent justifying the request for help without someone suggesting something I have already explored. – Krackle Apr 24 '19 at 02:09
  • Lin to Line was auto correct sorry. – Krackle Apr 24 '19 at 02:16
  • I just do not think this type of plot is possible. Each pixel equals a 'rod' of a single color value. My real samples are (4032,3024,3). Arrh! – Krackle Apr 24 '19 at 03:46
  • Please edit your original question to remove the duplicate part and correct linEspace to linspace. Please supply some sample data so we can see what you're working with. I can't really make out what data you have based on the fabric color sample – flurble Apr 24 '19 at 09:49

1 Answers1

3

Like the others, I'm confused by what you are trying to achieve.

Is this anything like what you had in mind?

img = plt.imread('Jb2Y5.jpg')
nx,ny,_ = img.shape
X, Y = np.meshgrid(np.linspace(0,ny,ny),np.linspace(0,nx,nx)) 
fig, (ax1, ax2, ax3) = plt.subplots(1,3,subplot_kw=dict(projection='3d'), figsize=(10,3))
ax1.plot_surface(X,Y, img[:,:,0], cmap="Reds", alpha=0.5)
ax1.set_title('RED')
ax2.plot_surface(X,Y, img[:,:,1], cmap='Greens', alpha=0.5)
ax2.set_title('GREEN')
ax3.plot_surface(X,Y, img[:,:,2], cmap='Blues', alpha=0.5)
ax3.set_title('BLUE')

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
  • Yes and no. I'm not looking for the color separations so much as I would like the face value of the peak colors to be represented. – Krackle Apr 27 '19 at 01:25