RGB to CMYK

O

Oracle3001

Hi All,

I want to take an image maybe in a jpeg or gif format or rgb and convert it
to a series of CMYK images (one for each colour). If there an easy way using
the API of java 2, or JAI. If not does anybody no an algorithm I can use to
implement this conversion.

Cheers,

Adam
 
H

Harald Hein

:

I am sure that there is some conversion implemented somewhere in the
image API, but
If not does anybody no an algorithm I can use to
implement this conversion.

Step 0: Normalize R,G, and B values to fit into range [0.0 ... 1.0], or
adapt the following matrix.

Step 1: RGB to CMY

| C | | 1 | | R |
| M | = | 1 | - | G |
| Y | | 1 | | B |

Step 2: CMY to CMYK

| C' | | C | | min(C,M,Y) |
| M' | | M | | min(C,M,Y) |
| Y' | = | Y | - | min(C,M,Y) |
| K' | | min(C,M,Y) | | 0 |

Easier to calculate if K' is calculated first, because K' = min(C,M,Y):

| C' | | C | | K' |
| M' | | M | | K' |
| Y' | = | Y | - | K' |
| K' | | K'| | 0 |
 
T

Tor Iver Wilhelmsen

Harald Hein said:
I am sure that there is some conversion implemented somewhere in the
image API, but


java.awt.color.ColorSpace

ColorSpace cmyk = new ColorSpace(ColorSpace.TYPE_CMYK, 4);
float[] values = cmyk.fromRGB(rgbFloatArray);
 
O

Oracle3001

Tor Iver Wilhelmsen said:
Harald Hein said:
I am sure that there is some conversion implemented somewhere in the
image API, but


java.awt.color.ColorSpace

ColorSpace cmyk = new ColorSpace(ColorSpace.TYPE_CMYK, 4);
float[] values = cmyk.fromRGB(rgbFloatArray);

You haven't said how I actually go about converting the image itself? Sorry
if I'm been really dumb but I'm a bit of a newbie.

The few lines you posted sets the color space to the type I want, but how is
this used with say an image test1.jpg?

Adam
 
T

Tor Iver Wilhelmsen

Oracle3001 said:
The few lines you posted sets the color space to the type I want,
but how is this used with say an image test1.jpg?

You need to read the docs for the entire java.awt.image package; Start
with ColorSpace and its "Use" link at the top, there you see where
it's applied. The most relevant classes seem to be BufferedImage,
BufferedImageFilter and tRGBImageFilter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top