开发者

Intensity 0..255 of each pixel?

I have Black开发者_运维技巧 and White picture - RGB 565, 200x50. as I can calculate the intensity 0..255 of each pixel?


That's what I meant, thanks. ma be this can someone help. I get Intensity 0..255 of each pixel and get the average.

     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();


You could try to convert it using a color model with a luminance and two chrominance components. The luminance component accounts for the brightness while the two chrominance components represent the colors. You might want to check out http://en.wikipedia.org/wiki/YUV.

Otherwise: If I'm correct, the white over gray to black colors have equal values in a RGB format which has the same number of bits for each channel (e.g. from (0, 0, 0) to (255, 255, 255)). Assuming this is true you could just take one of the channels to represent the intensity as you could determine the other values from that. No guarantee if this works.

Edit: I wrote a snippet demonstrating the idea described above. I used RGB888 but it should also work with RGB 565 after dropping the assertion and modifying the maximum intensity of a pixel as described in the comments. Mind that there are only 2^5 different intensity levels per pixel. Hence you might want to use a scaled version of the average intensity.

I tested it using images from http://www.smashingmagazine.com/2008/06/09/beautiful-black-and-white-photography/. I hope it will work out porting this to android for you.

// 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜