【问题标题】:How to plot 3d graphics with the values of each pixel of the image?如何使用图像的每个像素的值绘制 3d 图形?
【发布时间】:2023-04-01 22:54:01
【问题描述】:

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

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

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

【问题讨论】:

  • 不久前有人问了一个非常相似的问题(但 OP 比你更远一点)---见 here。这会将所有标记绘制在正确的位置,然后您可以按照我对该问题的评论来查看如何将标记颜色映射到那里的图像颜色。
  • 好的,但发给我的问题只是图表,您无法获取颜色
  • 我回答了 Alexander 指出的问题。答案能解决你的问题吗?

标签: python python-3.x opencv image-processing histogram


【解决方案1】:

以下是一些如何将图像和图形图像数据显示为 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()

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

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

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

图(2) - 第一个 LAB 通道的等高线图

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

【讨论】:

    猜你喜欢
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    相关资源
    最近更新 更多