2012-08-25 7 views

Antwort

0

A ist der Vordergrundpixel, B die Hintergrundpixel, C das neue Pixel ist. H ist der Farbtonwert für jedes Pixel, S ist der Sättigungswert, L ist der Helligkeitswert und Y ist der Helligkeitswert. (Nicht sicher, was der Unterschied zwischen Luminanz und Helligkeit ist.

Wie auch immer, im ersten Beispiel werden die Werte für Farbton (H) und Sättigung (S) des neuen Pixels (C) vom Vordergrundpixel (A) kopiert. während die Helligkeit (Y) Wert des neuen Pixels von Luminanz (L) Wert des Hintergrund (B) Pixel

+0

Danke, das ist genau das, was ich brauchte. Aber die Formel ist nicht so einfach, weil das Ergebnis etwas ausgewaschen war. Am Ende habe ich es geschafft, es mit Hilfe von diesem zu arbeiten: http://www.beneaththewaves.net/Photography/Secrets_of_Photoshops_Colour_Blend_Mode_Revealed_Sort_Of.html – Castles

2

Wikipedia hat einen auf mischmodi guten Artikel genommen wird. http://en.wikipedia.org/wiki/Blend_modes

Sie Formeln geben für Multiplizieren, Bildschirm und Overlay-Modus

Multiply 
Formula: Result Color = (Top Color) * (Bottom Color) /255 

Screen 
Formula: Result Color = 255 - [((255 - Top Color)*(255 - Bottom Color))/255] 

Overlay 
Formula: Result Color = if (Bottom Color < 128) 
    then (2 * Top Color * Bottom Color/255) 
    else (255 - 2 * (255 - Top Color) * (255 - Bottom Color)/255) 
+0

Danke, das hat mir sehr geholfen, die Formeln von WikiPedia zu interpretieren (ich habe sie früher überprüft). Nur hinzufügen, diese Formeln sollten separat für jede Farbkomponente (für RGB-Farben) ausgeführt werden. Das war mir zumindest anfangs nicht offensichtlich. – Jouni

5

Vor einiger Zeit habe ich die Photoshop-Füllmethoden umgekehrt.

Werfen Sie einen Blick hier:

http://www.kineticsystem.org/?q=node/13

Und hier unter dem Code, den ich verwende, um zwischen HSY (Farbton, Sättigung, Luminanz) zu und von RGB (Rot, Grün, Blau) zu konvertieren. Photoshop verwendet etwas Hexacones, um die Sättigung zu berechnen.

Giovanni

/** 
* This is the formula used by Photoshop to convert a color from 
* RGB (Red, Green, Blue) to HSY (Hue, Saturation, Luminosity). 
* The hue is calculated using the exacone approximation of the saturation 
* cone. 
* @param rgb The input color RGB normalized components. 
* @param hsy The output color HSY normalized components. 
*/ 
public static void rgbToHsy(double rgb[], double hsy[]) { 

    double r = Math.min(Math.max(rgb[0], 0d), 1d); 
    double g = Math.min(Math.max(rgb[1], 0d), 1d); 
    double b = Math.min(Math.max(rgb[2], 0d), 1d); 

    double h; 
    double s; 
    double y; 

    // For saturation equals to 0 any value of hue are valid. 
    // In this case we choose 0 as a default value. 

    if (r == g && g == b) {   // Limit case. 
     s = 0d; 
     h = 0d; 
    } else if ((r >= g) && (g >= b)) { // Sector 0: 0° - 60° 
     s = r - b; 
     h = 60d * (g - b)/s; 
    } else if ((g > r) && (r >= b)) { // Sector 1: 60° - 120° 
     s = g - b; 
     h = 60d * (g - r)/s + 60d; 
    } else if ((g >= b) && (b > r)) { // Sector 2: 120° - 180° 
     s = g - r; 
     h = 60d * (b - r)/s + 120d; 
    } else if ((b > g) && (g > r)) { // Sector 3: 180° - 240° 
     s = b - r; 
     h = 60d * (b - g)/s + 180d; 
    } else if ((b > r) && (r >= g)) { // Sector 4: 240° - 300° 
     s = b - g; 
     h = 60d * (r - g)/s + 240d; 
    } else {       // Sector 5: 300° - 360° 
     s = r - g; 
     h = 60d * (r - b)/s + 300d; 
    } 

    y = R * r + G * g + B * b; 

    // Approximations erros can cause values to exceed bounds. 

    hsy[0] = h % 360; 
    hsy[1] = Math.min(Math.max(s, 0d), 1d); 
    hsy[2] = Math.min(Math.max(y, 0d), 1d); 
} 

/** 
* This is the formula used by Photoshop to convert a color from 
* HSY (Hue, Saturation, Luminosity) to RGB (Red, Green, Blue). 
* The hue is calculated using the exacone approximation of the saturation 
* cone. 
* @param hsy The input color HSY normalized components. 
* @param rgb The output color RGB normalized components. 
*/ 
public static void hsyToRgb(double hsy[], double rgb[]) { 

    double h = hsy[0] % 360; 
    double s = Math.min(Math.max(hsy[1], 0d), 1d); 
    double y = Math.min(Math.max(hsy[2], 0d), 1d); 

    double r; 
    double g; 
    double b; 

    double k; // Intermediate variable. 

    if (h >= 0d && h < 60d) {   // Sector 0: 0° - 60° 
     k = s * h/60d; 
     b = y - R * s - G * k; 
     r = b + s; 
     g = b + k; 
    } else if (h >= 60d && h < 120d) { // Sector 1: 60° - 120° 
     k = s * (h - 60d)/60d; 
     g = y + B * s + R * k; 
     b = g - s; 
     r = g - k; 
    } else if (h >= 120d && h < 180d) { // Sector 2: 120° - 180° 
     k = s * (h - 120d)/60d; 
     r = y - G * s - B * k; 
     g = r + s; 
     b = r + k; 
    } else if (h >= 180d && h < 240d) { // Sector 3: 180° - 240° 
     k = s * (h - 180d)/60d; 
     b = y + R * s + G * k; 
     r = b - s; 
     g = b - k; 
    } else if (h >= 240d && h < 300d) { // Sector 4: 240° - 300° 
     k = s * (h - 240d)/60d; 
     g = y - B * s - R * k; 
     b = g + s; 
     r = g + k; 
    } else {       // Sector 5: 300° - 360° 
     k = s * (h - 300d)/60d; 
     r = y + G * s + B * k; 
     g = r - s; 
     b = r - k; 
    } 

    // Approximations erros can cause values to exceed bounds. 

    rgb[0] = Math.min(Math.max(r, 0d), 1d); 
    rgb[1] = Math.min(Math.max(g, 0d), 1d); 
    rgb[2] = Math.min(Math.max(b, 0d), 1d); 
} 
+0

Danke, Giovanni! Sie haben nur vergessen, die Definition von R, G, B Variablen zu setzen. Sollten sie R = 0,3, G = 0,59, B = 0,11? Ich habe diese Werte hier gefunden: [http://dev.w3.org/fxtf/compositing-1/#blendingnonseparable](http://dev.w3.org/fxtf/compositing-1/# blendingnonseparable) –

+0

dieser Code funktioniert gut, aber Sie müssen die RGB-Werte z. rgb [0] = Farbe.RED.getRec()/255d; rgb [1] = Farbe.RED.getGreen()/255d; rgb [2] = Farbe.RED.getBlue()/255d; und umgekehrt für das Ergebnis. – Chris

0

Diese Farbmischung Formeln sind ziemlich schwierig, wenn Sie auch den Alpha-Kanal zu übernehmen müssen. Ich war nicht in der Lage, die Vermischung von Photoshop zu reproduzieren, aber Gimp funktioniert wie folgt:

Color mix_hsv(
    ColorMixMode::Enum mode, // blending mode 
    Color cd,    // destination color (bottom pixel) 
    Color cs)    // source color (top pixel) 
{ 
    // Modify the source color 
    float dh, ds, dv; // destination hsv 
    float sh, ss, sv; // source hsv 
    cd.GetHsv(dh, ds, dv); 
    cs.GetHsv(sh, ss, sv); 

    switch (mode) { 
     case HUE:  cs.InitFromHsv(sh, ds, dv); break; 
     case SATURATION: cs.InitFromHsv(dh, ss, dv); break; 
     case COLOR:  cs.InitFromHsv(sh, ss, dv); break; 
     case LUMINOSITY: cs.InitFromHsv(dh, ds, sv); break; 
    } 
    cs.A = std::min(cd.A, cs.A); 

    // Blend the modified source color onto the destination color 
    unsigned char cd_A_orig = cd.A; 
    cd = mix(NORMAL, cd, cs); // normal blending 
    cd.A = cd_A_orig; 
    return cd; 
} 

Wenn Sie premultiplied Alpha verwenden, vergessen Sie nicht richtig es in dem obigen Code zu behandeln. Ich konnte den Code zum Mischen in Gimps Quellcode nicht finden, aber die resultierenden Bilder sind sehr ähnlich.

Photoshops Farbmischung ist deutlich anders, also wenn jemand findet einen Weg, es zu implementieren, lassen Sie es uns wissen alle: o)

Miso

Verwandte Themen