How to replace single color in an image?
in
Programming Questions
•
2 years ago
Hi.
I'm building an image from a database of around two millions lines. Each line is of one of 3 colors.
This process is very long and I would like to avoid it when possible.
After the image has been composed, according to the aestethical result, I would like to change a single color WITHOUT recalculating the whole database. I cannot find an algorithm to do this.
If there is no smooth (and no antialiasing) it is easy: I scan the image replacing pure original color pixels.
With smooth() antialiasing doesn't let this simple approach.
This source shows the problem:
- color colbg = #000000;
- color col1a = #008844;
- color col2a = #884400;
- color col3a = #440088;
- color col1b = #ff88ff;
- color col2b = #88ffff;
- color col3b = #ffff88;
- void setup() {
- size(400,400);
- background(colbg);
- smooth();
- strokeWeight(35);
- noFill();
- // draw lines
- stroke(col2a);
- bezier(70,50,150,650,300,-250,300,300);
- stroke(col3a);
- bezier(50,150,50,50,350,300,350,350);
- stroke(col1a);
- bezier(50,50,50,150,250,250,200,300);
- // replace a single color
- loadPixels();
- for (int i=0; i<pixels.length; i++) {
- if (pixels[i] == col1a) pixels[i] = col1b;
- }
- updatePixels();
- }
- void draw() {
- }
With antialiasing the border of pink curve is greenish, a souvenir of its original color.
Is there an algorithm to replace the green original color in a more effective way to remove this artefact?
I thought to play with different PGraphics (one for each color) and find a way to manage transparencies but I saw that smooth() doesn't work in PGraphics.
Any idea? Libraries?
Thanks in advance
Alessandro
1