相关疑难解决方法(0)

如何从PNG图像中删除第4通道

我正在从OpenCV中的URL加载图像。一些图像是PNG,具有四个通道。我正在寻找一种删除第四频道(如果存在)的方法。

这就是我加载图像的方式:

def read_image_from_url(self, imgurl):
    req = urllib.urlopen(imgurl)
    arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
    return cv2.imdecode(arr,-1) # 'load it as it is'
Run Code Online (Sandbox Code Playgroud)

我不想更改,cv2.imdecode(arr,-1)但我想检查加载的图像是否有第四个通道,如果有,请删除它。

像这样,但我不知道如何删除第四个频道

def read_image_from_url(self, imgurl):
    req = urllib.urlopen(imgurl)
    arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
    image = cv2.imdecode(arr,-1) # 'load it as it is'
    s = image.shape
    #check if third tuple of s is 4
    #if it is 4 then remove the 4th channel and return the image. 
Run Code Online (Sandbox Code Playgroud)

python png opencv image-processing

3
推荐指数
1
解决办法
6130
查看次数

如何在Bokeh中显示TIFF图像?

我可以将TIFF图像作为NumPy数组加载到内存中,其中每个像素由3元素RGB矢量表示:

from PIL import Image
import numpy as np
arr=np.array(Image.open(imgfn))
Run Code Online (Sandbox Code Playgroud)

例如,上面的arr可能有形状(2469,2858,3).

按照Bokeh文档,在Bokeh中,像素是相对于颜色映射解释的1D数字.

如何将3D RGB TIFF阵列映射到1D Bokeh色彩映射索引数组,以及我应该使用什么色彩映射?

这篇文章建议我应该写一个名为RGBAColorMapper的东西.我怎么做?

还有一些叫做image_rgba的东西,它是一个4D像素,如何将3D像素转换为4D才能使用它?

基本上我正在寻找与MatPlotLib imshow相同的功能.

rgb image imshow bokeh

0
推荐指数
1
解决办法
845
查看次数

标签 统计

bokeh ×1

image ×1

image-processing ×1

imshow ×1

opencv ×1

png ×1

python ×1

rgb ×1