2012-07-19 131 views
1

我知道java代碼灰度是(0.2126 *紅色+ 0.7152 *綠色+ 0.0722 *藍色( 我想知道如果有人知道我怎麼能找到更多種顏色公式,就像我想要使畫面舊的方式方法,橙,使其變亮,或更暗......尖銳等java圖像顏色公式

int pixel = image.getRGB(j, i); 
int red = (pixel) & 0xff; 
int green = (pixel >> 8) & 0xff; 
int blue = (pixel >> 16) & 0xff; 
int newPixel = (int) (0.2126 * red + 0.7152 * green + 0.0722 * blue); 
        image1.setRGB(j, i, newPixel); 

回答

2

你提到的舊時尚方式被稱爲「棕褐色」效果。看看this question特別this answer這指出了下面的代碼片段(注意,我沒有寫這個代碼,只是在尋找答案你的問題幫忙)

/** 
* 
* @param img Image to modify 
* @param sepiaIntensity From 0-255, 30 produces nice results 
* @throws Exception 
*/ 
public static void applySepiaFilter(BufferedImage img, int 
sepiaIntensity) throws Exception 
{ 
// Play around with this. 20 works well and was recommended 
// by another developer. 0 produces a grey image 
int sepiaDepth = 20; 

int w = img.getWidth(); 
int h = img.getHeight(); 

WritableRaster raster = img.getRaster(); 

// We need 3 integers (for R,G,B color values) per pixel. 
int[] pixels = new int[w*h*3]; 
raster.getPixels(0, 0, w, h, pixels); 

// Process 3 ints at a time for each pixel. Each pixel has 3 RGB 
colors in array 
for (int i=0;i<pixels.length; i+=3) 
{ 
int r = pixels[i]; 
int g = pixels[i+1]; 
int b = pixels[i+2]; 

int gry = (r + g + b)/3; 
r = g = b = gry; 
r = r + (sepiaDepth * 2); 
g = g + sepiaDepth; 

if (r>255) r=255; 
if (g>255) g=255; 
if (b>255) b=255; 

// Darken blue color to increase sepia effect 
b-= sepiaIntensity; 

// normalize if out of bounds 
if (b<0) b=0; 
if (b>255) b=255; 

pixels[i] = r; 
pixels[i+1]= g; 
pixels[i+2] = b; 
} 
raster.setPixels(0, 0, w, h, pixels); 
} 
+0

棕褐色嗯,聽說過它,thanx很多讓我去閱讀 – 2012-07-19 07:12:49

+0

@behzad_b我假設在以下wiki文章的前兩張照片是你的意思:http://en.wikipedia.org/wiki/Photographic_print_toning – posdef 2012-07-19 07:15:38

+0

@ posdef是的 – 2012-07-19 07:17:05

1

我只想用數字玩。

橙,

更紅和多一點綠色(紅色+綠色=黃色)

增加所有因素

較暗

減少的所有因素

銳利

這是比較周圍像素找到邊緣的特定過濾器。這不僅僅是玩顏色的問題。

順便說一句:你應該添加值的上限。即Math.min(255,Math.max(0,value))

+0

我只是玩數字,使圖像更模糊? – 2012-07-19 07:11:38

+0

模糊也是一個過濾器(在某些方面銳化的相反)你必須考慮周圍的所有像素以獲得模糊的圖像(而不是改變顏色) – 2012-07-19 07:13:20

+0

所以我該怎麼做,我該如何應用這些過濾器 – 2012-07-19 07:21:38

0

你可以操縱的顏色之間的比例頻道爲了改變現場的「氣氛」。下面的圖片是使用ColorChannel插件創建的。

enter image description here

該算法的源代碼如下。方法getAttribute()獲取用戶傳遞的參數(紅色,綠色,藍色)。方法getIntComponent0,getIntComponent1getIntComponent2獲取每個顏色通道(紅色,綠色和藍色)。方法setIntColor設置每個通道的值。

@Override 
public void process 
(
    MarvinImage imageIn, 
    MarvinImage imageOut, 
    MarvinAttributes attrOut, 
    MarvinImageMask mask, 
    boolean preview 
) { 

    int vr = (Integer)getAttribute("red"); 
    int vg = (Integer)getAttribute("green"); 
    int vb = (Integer)getAttribute("blue"); 

    double mr = 1+Math.abs((vr/100.0)*2.5); 
    double mg = 1+Math.abs((vg/100.0)*2.5); 
    double mb = 1+Math.abs((vb/100.0)*2.5); 

    mr = (vr > 0? mr : 1.0/mr); 
    mg = (vg > 0? mg : 1.0/mg); 
    mb = (vb > 0? mb : 1.0/mb); 

    int red,green,blue; 
    for(int y=0; y<imageIn.getHeight(); y++){ 
     for(int x=0; x<imageIn.getWidth(); x++){ 
      red = imageIn.getIntComponent0(x, y); 
      green = imageIn.getIntComponent1(x, y); 
      blue = imageIn.getIntComponent2(x, y); 

      red  = (int)Math.min(red * mr, 255); 
      green = (int)Math.min(green * mg, 255); 
      blue = (int)Math.min(blue * mb, 255); 

      imageOut.setIntColor(x, y, 255, red, green, blue); 
     } 
    } 
}