I have an sketch that “simulates” a live RGB to CMYK conversion from a webcam image.
A webcam image or digital image is always captured in RGB. When the image is displayed on a screen, it is also always in RGB, because screens display all colors mixing the primary additive colors red R, green G and blue B. When you have an CMYK image file, the computer “simulates” how the CMYK would look like when printed on paper, and displays it on the RGB screen. If you have any further questions about that, ask me!
CMYK images are not supported to be loaded with loadImage(). You may need to convert your CMYK image to RGB with another software before loading it, if that is the case.
I think that is not exactly what you are looking for, but i think it may help:
(to run the code you may need to configure/test your webcam, or rewrite the code to use a loaded image instead. btw, sorry my code may be a bit messy!)
Preview:
Code:
import processing.video.*;
Capture cam;
PImage cyan;
PImage magenta;
PImage yellow;
PImage black;
int w = 640; // Webcam image width
int h = 480; // Webcam image height
void setup() {
size(1920, 960);
background(0);
// Webcam setup
String[] cameras = Capture.list();
printArray(cameras);
cam = new Capture(this, cameras[0]);
cam.start();
// Create Images
cyan = createImage(w, h, RGB);
magenta = createImage(w, h, RGB);
yellow = createImage(w, h, RGB);
black = createImage(w, h, RGB);
}
void draw() {
if (cam.available() == true) {
cam.read();
// LoadPixels of the images
cam.loadPixels();
cyan.loadPixels();
magenta.loadPixels();
yellow.loadPixels();
black.loadPixels();
// RGB to CMYK convertion simulation
for (int i = 0; i < cam.pixels.length; i++) {
float c_ = red(cam.pixels[i]);
float m_ = green(cam.pixels[i]);
float y_ = blue(cam.pixels[i]);
float k_ = brightness(cam.pixels[i]);
cyan.pixels[i] = color(c_, 255, 255);
magenta.pixels[i] = color(255, m_, 255);
yellow.pixels[i] = color(255, 255, y_);
black.pixels[i] = color(k_);
}
// UpdatePixels of the images
cyan.updatePixels();
magenta.updatePixels();
yellow.updatePixels();
black.updatePixels();
// Display the images
image(cam, 0, 0);
image(cyan, w + 0*w, 0);
image(magenta, w + 1*w, 0);
image(yellow, w + 0*w, h);
image(black, w + 1*w, h);
}
}