カテゴリー
未分類

彩度をあげる

icon_flash8.jpgの彩度を上げる演算についてちとスタディ中。
理屈としてはRGBのうちのもっとも値の高いものを255へ。2番目をそのまま保持。3番目を0へという振り方になるのだけど、(この辺によっては0まで振らないのだけど、その辺の算出方は検証中)これを各点のカラー情報を取得してると重すぎるので、マトリックスで一括で計算できるような形にできないものかと考え中。あほだから各点のRGB値を取得しないでそういう演算ができる方法を思いつかない・・。
普通に加算していったら明度もあがっちゃうしなぁ・・、相対的な処理を参照なしにできないものかなあ・・。この辺画像数値計算系のよいとかないかいな?

「彩度をあげる」への7件の返信

このへんね・・。
—-
C-9 WHAT WEIGHTING OF RED, GREEN AND BLUE CORRESPONDS TO BRIGHTNESS?
Direct acquisition of luminance requires use of a very specific spectral
weighting. However, luminance can also be computed as a weighted sum of
red, green and blue components.
If three sources appear red, green and blue, and have the same radiance in
the visible spectrum, then the green will appear the brightest of the three
because the luminous efficiency function peaks in the green region of the
spectrum. The red will appear less bright, and the blue will be the darkest
of the three. As a consequence of the luminous efficiency function, all
saturated blue colors are quite dark and all saturated yellows are quite
light. If luminance is computed from red, green and blue, the coefficients
will be a function of the particular red, green and blue spectral weighting
functions employed, but the green coefficient will be quite large, the red
will have an intermediate value, and the blue coefficient will be the
smallest of the three.
Contemporary CRT phosphors are standardized in Rec. 709 [8], to be
described in section 17. The weights to compute true CIE luminance from
linear red, green and blue (indicated without prime symbols), for the Rec.
709, are these:
Y = 0.212671 * R + 0.715160 * G + 0.072169 * B;
This computation assumes that the luminance spectral weighting can be
formed as a linear combination of the scanner curves, and assumes that the
component signals represent linear-light. Either or both of these
conditions can be relaxed to some extent depending on the application.
Some computer systems have computed brightness using (R+G+B)/3. This is at
odds with the properties of human vision, as will be discussed under What
are HSB and HLS? in section 36.
The coefficients 0.299, 0.587 and 0.114 properly computed luminance for
monitors having phosphors that were contemporary at the introduction of
NTSC television in 1953. They are still appropriate for computing video
luma to be discussed below in section 11. However, these coefficients do
not accurately compute luminance for contemporary monitors.

ここも・・・
—-
C-18 HOW DO I TRANSFORM BETWEEN CIE XYZ AND A PARTICULAR SET OF RGB
PRIMARIES?
RGB values in a particular set of primaries can be transformed to and from
CIE XYZ by a three-by-three matrix transform. These transforms involve
tristimulus values, that is, sets of three linear-light components that
conform to the CIE color matching functions. CIE XYZ is a special case of
tristimulus values. In XYZ, any color is represented by a positive set of
values.
Details can be found in SMPTE RP 177-1993 [11].
To transform from CIE XYZ into Rec. 709 RGB (with its D65 white point), put
an XYZ column vector to the right of this matrix, and multiply:
[ R709 ] [ 3.240479 -1.53715 -0.498535 ] [ X ]
[ G709 ]=[-0.969256 1.875991 0.041556 ]*[ Y ]
[ B709 ] [ 0.055648 -0.204043 1.057311 ] [ Z ]
As a convenience to C programmers, here are the coefficients as a C array:
{{ 3.240479,-1.53715 ,-0.498535},
{-0.969256, 1.875991, 0.041556},
{ 0.055648,-0.204043, 1.057311}}
This matrix has some negative coefficients: XYZ colors that are out of
gamut for a particular RGB transform to RGB where one or more RGB
components is negative or greater than unity.
Here’s the inverse matrix. Because white is normalized to unity, the
middle row sums to unity:
[ X ] [ 0.412453 0.35758 0.180423 ] [ R709 ]
[ Y ]=[ 0.212671 0.71516 0.072169 ]*[ G709 ]
[ Z ] [ 0.019334 0.119193 0.950227 ] [ B709 ]
{{ 0.412453, 0.35758 , 0.180423},
{ 0.212671, 0.71516 , 0.072169},
{ 0.019334, 0.119193, 0.950227}}
To recover primary chromaticities from such a matrix, compute little x and
y for each RGB column vector. To recover the white point, transform RGB=[1,
1, 1] to XYZ, then compute x and y.
—-

あー基本はこちらです。

C-6 WHAT IS SATURATION?
Again from the CIE, saturation is the colorfulness of an area judged in
proportion to its brightness. Saturation runs from neutral gray through
pastel to saturated colors. Roughly speaking, the more an SPD is
concentrated at one wavelength, the more saturated will be the associated
color. You can desaturate a color by adding light that contains power at
all wavelengths.

余談ですが、colorMatrixには高速バージョンがあって、[
Pentium 3 以降、Apple G4 以降など、SSE/Altivec アクセラレータ対応のプロセッサでのみ使用できます。アクセラレータは、乗数項の範囲が -15.99 ~ 15.99 で、加算項 [4]、a[9]、a[14]、および a[19] の範囲が -8000 ~ 8000 の場合に使用されます。]という条件で高速化されます。

とりあえずclassとか使わないで簡単にfunctionで・・。

function adjustSaturation(s:Number):Void {
var is:Number = 1-s;
var r_lum:Number = 0.212671;
var g_lum:Number = 0.715160;
var b_lum:Number = 0.072169;
var irlum:Number = is*r_lum;
var iglum:Number = is*g_lum;
var iblum:Number = is*b_lum;
image.filters = new Array(new ColorMatrixFilter([irlum+s, iglum, iblum, 0, 0, irlum, iglum+s, iblum, 0, 0, irlum, iglum, iblum+s, 0, 0, 0, 0, 0, 1, 0]));
}

な感じ。
んが、これがphotoshopとかの彩度と同じような働きなのかは不明・・。ついでにいうと最適化はなにもなされていません。しかしcolorMatrixって説明自体がよくわからんな・・。最適化の手法として「アルファのみ。ここに示すようにアルファ成分のみを調整するマトリックスをフィルタに渡すと、フィルタによりそのパフォーマンスが最適化されます。」というのもあるのだけど、これって何をいってるのか?一度乗算したあとに再度
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 N 0
を乗算すると最適化されるってことなんだろうか?

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です