Ask Your Question
0

Create a colored image from CMYK grayscale images

asked 2013-07-30 11:00:50 -0600

itayer gravatar image

updated 2013-07-30 11:32:01 -0600

berak gravatar image

Hi - I have 4 images (separation) which each one represent a color (cyan , magenta , black and yellow), i need to blend them together into a single colored (RGB) image.

what is the best way to accomplish that. Thanks a lot. Itay.

edit retag flag offensive close merge delete

Comments

1

I don't know the best way, but maybe this source will be helpful for you https://code.ros.org/trac/opencv/changeset/564/trunk/opencv/src/highgui/utils.cpp if you will not find the better decision

tenta4 gravatar imagetenta4 ( 2013-07-30 15:41:38 -0600 )edit

@tenta4, good hint! will still need some work to adapt to cv::Mat

you're the hero of the day, if you can do it ! ;)

berak gravatar imageberak ( 2013-07-30 16:28:39 -0600 )edit

You can call mat.data attribute to get uchar* from cv::Mat

tenta4 gravatar imagetenta4 ( 2013-07-31 01:39:23 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2013-07-31 05:17:13 -0600

berak gravatar image

here you go:

void cmyk2rgb(const Mat & c,const Mat & m,const Mat & y,const Mat & k, Mat & rgb ) {
    rgb = Mat(c.size(), CV_8UC3);
    for ( size_t j=0;j<c.rows; j++ ) {
        for ( size_t i=0;i<c.rows; i++ ) {
            Vec3b & v = rgb.at<Vec3b>(i,j);
            uchar K = k.at<uchar>(i,j);
            v[2] = saturate_cast<uchar>(K - ((255 - c.at<uchar>(i,j))*K>>8));
            v[1] = saturate_cast<uchar>(K - ((255 - m.at<uchar>(i,j))*K>>8));
            v[0] = saturate_cast<uchar>(K - ((255 - y.at<uchar>(i,j))*K>>8));
        }
    }
}
edit flag offensive delete link more

Comments

Lets put it into the color conversion module? :) Guess this is usefull for others also.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-31 05:39:41 -0600 )edit

But to make it more cleare I suggest to merge the cmyk channels into a single mat and output it as 1 element.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-31 05:41:03 -0600 )edit

it's just a port from highgui/utils.cpp

also it does not fit the usual cvtColor signature

berak gravatar imageberak ( 2013-07-31 05:43:10 -0600 )edit

Hmm okay :) Maybe an idea to do later. Added to the small TODO list sticking at the wall.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-31 05:47:29 -0600 )edit
1

merging them is very expensive, and the original poster already had single images.

but, yea, let's see..

berak gravatar imageberak ( 2013-07-31 05:48:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-07-30 11:00:50 -0600

Seen: 2,646 times

Last updated: Jul 31 '13