简体   繁体   English

如何在python中为3D灰度图像着色

[英]How to color a 3d grayscale image in python

I want to color a pixel in 3d 我想在3d中为一个像素着色

import numpy as np
import matplotlib.pyplot as plt
im = np.random.randint(0, 255, (16, 16))
I = np.dstack([im, im, im])
x = 5
y = 5
I[x, y, :] = [1, 0, 0]
plt.imshow(I, interpolation='nearest' )
plt.imshow(im, interpolation='nearest', cmap='Greys')

This code is for 2d but instead of the coordiantes i want to give the value of the grayscale pixel in 3d that i want to change. 这段代码适用于2d,但我不想使用coordiantes来给出我想要改变的3d中灰度像素的值。

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(4)
im = np.random.randint(0, 255, (16, 16))
I = np.dstack([im, im, im])
I[np.logical_and(np.logical_and(I[:, :, 0]==15, I[:, :, 1]==15), I[:, :, 2]==15)] = [0, 1, 0]
plt.figure()
plt.imshow(I, interpolation='nearest' )
plt.figure()
plt.imshow(im, interpolation='nearest', cmap='Greys')
plt.show()
from PIL import Image
import numpy as np 
def image_preprocessing(image_file, height, width):  
    image = Image.open(image_file)
    image = image.resize((width, height), Image.ANTIALIAS)        
    np_image = np.array(image)
    np_image = np_image.astype(float)
    np_image = np_image - 128.0
    np_image = np_image / 128.0

    if len(np_image.shape) == 2: # 1D image
        new_image = np.zeros((np_image.shape[0], np_image.shape[1], 3))
        new_image[:,:,0] = np_image
        new_image[:,:,1] = np_image
        new_image[:,:,2] = np_image
    else:
        new_image = np_image

    # flushing
    np_image = []

    return new_image

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

相关问题 如何建立具有灰度值的 3D 数组的 3D 模型? [Python] - How to establish a 3D model with a 3D array with grayscale values? [python] 如何将1d数组转换为3d数组(将灰度图像转换为rgb格式)? - How to convert 1d array to 3d array (convert grayscale image so rgb format )? OpenCV Python 如何在将图像转换为灰度时保持一种颜色 - OpenCV Python how to keep one color as is converting an image to Grayscale 如何在非彩色图像的彩色通道中显示图像? - How to show image in color channel of a image not in grayscale? 如何在Python中保存灰度图像? - How to save grayscale image in Python? 在给定大小为 (64,64,64) 的 numpy 数组的情况下显示 3D 图像,其中每个元素代表 Python 中 3d 空间中的强度 (0-1)(灰度) - Display 3D image given a numpy array of size (64,64,64) where each element represents the intensity(0-1)(grayscale) in 3d space in Python Python - 如何将 2D 灰度图像转换为 1D 矢量 - Python - How can I convert a 2D grayscale image to a 1D vector 如何在 python 中将 2D 图像重塑为 3D - How to reshape 2D image into 3D in python 如何在 python 中用颜色显示、更新和旋转 3d 点? - How to display, update and rotate 3d points with color in python? 如何在Python中为3D球体的各个部分着色 - How do I color individual sections of a 3d sphere in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM