相关疑难解决方法(0)

具有直接像素访问的Opencv颜色映射

我有一个灰度图像,我希望通过使用调色板(如Matlab中的colormap)映射灰度值来显示颜色.

我设法通过使用OpenCV cvSet2D函数来实现,但出于性能原因我想直接访问像素.

但是,当我这样做时,图像有奇怪的颜色.我尝试以不同的顺序(RGB,BGR,......)设置颜色,但似乎无法解决它.

有我的代码:

    IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), IPL_DEPTH_8U, 3 );
for (int y=0; y<temp->height; y++)
{
    uchar* ptr1 = (uchar*) ( temp->imageData + y * temp->widthStep );
    uchar* ptr2 = (uchar*) ( img->imageData + y * img->widthStep );

    for (int x=0; x<temp->width; x++)
    {
        CvScalar v1;

        int intensity = (int)ptr2[x];
        int b=0, g=0, r=0;
        r = colormap[intensity][0];
        g = colormap[intensity][1];
        b = colormap[intensity][2];

        if (true)
        {
            ptr1[3*x]   = b;
            ptr1[3*x+1] = g;
            ptr1[3*x+2] = r;
        } …
Run Code Online (Sandbox Code Playgroud)

c++ opencv

7
推荐指数
2
解决办法
6886
查看次数

Python - 将颜色图应用于灰度 numpy 数组并将其转换为图像

我想要实现 Photoshop 中提供的渐变映射效果。已经有一篇文章解释了期望的结果。另外,这个答案完全涵盖了我想做的事情,但是

im = Image.fromarray(np.uint8(cm.gist_earth(myarray)*255))
Run Code Online (Sandbox Code Playgroud)

不适合我,因为我不知道如何将数组标准化为 1.0 的值。

下面是我的代码,因为我想让它工作。

im = Image.open(filename).convert('L') # Opening an Image as Grayscale
im_arr = numpy.asarray(im)             # Converting the image to an Array 

# TODO - Grayscale Color Mapping Operation on im_arr

im = Image.fromarray(im_arr)
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出将颜色图应用于该数组的可能选项和理想方法吗?我不想绘制它,因为似乎没有一种简单的方法将 pyplot 图转换为图像。

另外,您能否指出如何规范化数组,因为我无法这样做并且无法在任何地方找到帮助。

python numpy image-processing python-imaging-library

5
推荐指数
1
解决办法
8242
查看次数