我试图模仿Photoshop"色彩范围"使用Processing。我在这里找到了一些有关算法的有用信息:Emulate PhotoShop's "Color Range" algorithm
但我的问题是将它实现为处理草图,因为我是Java的新手。
我设法完成所有计算,但我不知道如何应用它们,例如。我想将饱和度更改为该范围内的像素。我该怎么做?
顺便说一句,这是我的代码(可能出现了问题)。
// Declaring variables
PImage img;
void setup() {
size(800,800);
colorMode(HSB, 360, 100, 100);
//making the window resizable
// if (frame != null) {
// frame.setResizable(true);
// }
img = loadImage("scanned_texture.jpg");
}
void draw() {
loadPixels();
img.loadPixels();
img.resize(800,800);
//loop through every pixel
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++ ) {
// Calculate the 1D pixel location
int loc = x + y*img.width;
// Get the H,S,B values from image
float h = hue (img.pixels[loc]);
float s = saturation (img.pixels[loc]);
float b = brightness (img.pixels[loc]);;
float Point1hue = hue(27);
float Point1sat = saturation(50);
float Point1bright = brightness(80);
float Point2hue = hue(57);
float Point2sat = saturation(80);
float Point2bright = brightness(100);
//distance between colors
float distance = sqrt(pow((Point2hue - Point1hue),2) + pow((Point2sat - Point1sat),2) + pow((Point2bright - Point1bright),2));
float percentage = distance/sqrt((255)^2+(255)^2+(255)^2);
color c = color(h,s,b);
//change saturation based on color range
if (c == percentage) {
s = +50;
}
pixels[loc] = c;
}
}
updatePixels();
}