Emgu CV - Combining greyscale images into single Bgr image

时光毁灭记忆、已成空白 提交于 2019-12-20 04:11:19

问题


I'm trying to convert a greyscale image to a Hsv image, but with the S and V channels set to a preset value. The following code works but takes ~400ms to execute.

public void ToHueImage(this Image<Gray, double> image, Image<Hsv, double> output)
{
        for (int i = 0; i < image.Width; i++)
        {
            for (int j = 0; j < image.Height; j++)
            {
                output.Data[j, i, 0] = image.Data[j, i, 0];
                output.Data[j, i, 1] = 255;
                output.Data[j, i, 2] = 255;
            }
        }           
    }
}

I would like to be able to assign a single greyscale image channel to each of the H, S, and V planes in a single operation to avoid copying the pixels across individually, something along the lines of

public void ToHueImage(this Image<Gray, double> image, Image<Hsv, double>     output)
{
    output.Data.H = image; 
    output.Data.S = WHITE_IMAGE; // These are static
    output.Data.V = WHITE_IMAGE; // These are static            
}

without resorting to byte copying etc. I'm trying to get the execution time to ~30ms or so. Is there any straightforward way to accomplish this?


回答1:


Sorted thanks to Miki: just need to call opencv function merge using CVInvoke:

CvInvoke.Merge(new VectorOfMat(image.Mat, whiteImage.Mat, whiteImage.Mat), heatMap.Mat);


来源:https://stackoverflow.com/questions/47700067/emgu-cv-combining-greyscale-images-into-single-bgr-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!