繁体   English   中英

如何用图像的每个像素的值绘制3d图形?

[英]How to plot 3d graphics with the values of each pixel of the image?

我将图片的颜色转换为LAB,如下所示:

import cv2
imbgr=cv2.imread('photo.jpg')
imlab=cv2.cvtColor(imbgr,cv2.COLOR_BGR2LAB)
cv2.imwrite('lab.jpg',imlab)

返回具有imlab [x,y]的像素,如何绘制具有这些值的图形?

这是一些如何将图像和图形图像数据显示为3-d数据的示例。

第一个和第二个图显示原始BGR图像,并将其单独的通道显示为BGR,然后显示为LAB。

第三和第四幅图显示了使用LAB图像的第一通道作为3-D数据的轮廓图和表面图。

另外:请注意imshow()需要RGB图像。 并且,如果需要,可以使用Aspect关键字,aspect ='equal'或set_aspect()将等高线图设为正方形。

import cv2
import numpy as np

import matplotlib.image as mpimg

import matplotlib.pyplot as plt

# for the surface map
from mpl_toolkits.mplot3d import Axes3D

imbgr = cv2.imread('Mona_Lisa.jpg')

imrgb = cv2.cvtColor(imbgr, cv2.COLOR_BGR2RGB)

imlab=cv2.cvtColor(imbgr,cv2.COLOR_BGR2LAB)

# Show the original image and individual color channels
plt.figure(0)
plt.subplot(2,2,1)

plt.imshow( imrgb )

plt.subplot(2,2,2)
plt.imshow(imbgr[:,:,0], cmap='Blues')

plt.subplot(2,2,3)
plt.imshow(imbgr[:,:,1], cmap='Greens')

plt.subplot(2,2,4)
plt.imshow(imbgr[:,:,2], cmap='Reds')

plt.show()

# show the LAB space iamge
plt.figure(1)
plt.subplot(2,2,1)

plt.imshow( imrgb )

plt.subplot(2,2,2)
plt.imshow(imlab[:,:,0], cmap='Greys')

plt.subplot(2,2,3)
plt.imshow(imbgr[:,:,1], cmap='cool')

plt.subplot(2,2,4)
plt.imshow(imbgr[:,:,2], cmap='cool')

plt.show()

# contour map
plt.figure(2)

y = range( imlab.shape[0] )
x = range( imlab.shape[1] ) 
X, Y = np.meshgrid(x, y)

plt.contour( X, Y, imlab[:,:,0], 50 )

plt.show()

# surface map
plt.figure(3)

ax = plt.axes(projection='3d')

y = range( imlab.shape[0] )
x = range( imlab.shape[1] ) 
X, Y = np.meshgrid(x, y)

ax.plot_surface( X, Y, imlab[:,:,0] )

plt.show()

这是由代码生成的图像,如下所示。

图(0)-原始图像和各个颜色通道

在此处输入图片说明

图(1)-LAB图像和单个通道

在此处输入图片说明

图(2)-第一个LAB通道的轮廓图

在此处输入图片说明

图(3)-第一个LAB通道的表面图

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM