2011-07-06 15 views

答えて

0

ルミナンスと2つのクロミナンスコンポーネントを持つカラーモデルを使用して変換を試みることができます。輝度成分は輝度を表し、2つの色成分は色を表す。 http://en.wikipedia.org/wiki/YUVをチェックしてみてください。

それ以外の場合:灰色から黒色までの白い灰色から黒色の色は、各チャンネルのビット数が同じRGB形式で等しい値を持ちます(たとえば、(0、0、0)から(255、 255,255))。これが真実であると仮定すると、それから他の値を決定できるように、強度を表現するためにチャネルの1つを取ることができます。これが動作しても保証はありません。

編集: 私は上記のアイデアを示すスニペットを書きました。私はRGB888を使用しましたが、アサーションを破棄し、コメントに記載されているようにピクセルの最大輝度を変更した後にRGB 565でも動作するはずです。 1ピクセルあたり2〜5の異なる強度レベルしかないことに注意してください。したがって、平均強度のスケーリングされたバージョンを使用することができます。

私はhttp://www.smashingmagazine.com/2008/06/09/beautiful-black-and-white-photography/の画像を使用してテストしました。私はそれがあなたのためにアンドロイドにこれを移植するうまくいくことを願っています。

// 2^5 for RGB 565 
private static final int MAX_INTENSITY = (int) Math.pow(2, 8) - 1; 

public static int calculateIntensityAverage(final BufferedImage image) { 
    long intensitySum = 0; 
    final int[] colors = image.getRGB(0, 0, image.getWidth(), 
      image.getHeight(), null, 0, image.getWidth()); 
    for (int i = 0; i < colors.length; i++) { 
     intensitySum += intensityLevel(colors[i]); 
    } 
    final int intensityAverage = (int) (intensitySum/colors.length); 
    return intensityAverage; 
} 

public static int intensityLevel(final int color) { 
    // also see Color#getRed(), #getBlue() and #getGreen() 
    final int red = (color >> 16) & 0xFF; 
    final int blue = (color >> 0) & 0xFF; 
    final int green = (color >> 8) & 0xFF; 
    assert red == blue && green == blue; // doesn't hold for green in RGB 565 
    return MAX_INTENSITY - blue; 
} 
+0

私はそれを理解しています - 黒は0、白は255です。各ピクセルの値を知り、それを追加して他のラスタと比較するための番号を取得する必要があります。これを行う方法?悪い英語を申し訳ありません。 – Domos

1

これは私が意味したことです。ありがとうございます。これは誰かを助けることができますか?私は各ピクセルの強度0..255を取得し、平均を取得します。

 Bitmap cropped = Bitmap.createBitmap(myImage, 503, 270,myImage.getWidth() - 955,   myImage.getHeight() - 550); 



    Bitmap cropped2 = Bitmap.createBitmap(cropped, 0, 0,cropped.getWidth() , cropped.getHeight()/2); 



final double GS_RED = 0.35; 

final double GS_GREEN = 0.55; 

final double GS_BLUE = 0.1; 

int R, G, B; 
int result = 0; 
int g = 0; 
int ff; 
    for(int x = 0; x < cropped2.getWidth(); x++) 
    { 
     int ff_y = 0;  
     for(int y = 0; y < cropped2.getHeight(); y++) 
     {    
      Pixel = cropped.getPixel(x, y);  

      R = Color.red(Pixel); 

      G = Color.green(Pixel); 

      B = Color.blue(Pixel);   

      ff = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B) ; 
      ff_y += ff; 

     } 
     result += ff_y; 
     g = result/(cropped2.getWidth()*cropped2.getHeight()); 

    } 
    Toast.makeText(this, "00" + g, Toast.LENGTH_LONG).show(); 
関連する問題