How can Android Bitmap to gray arg as return same as PIL Image.toBytes() at 'L' mode

0

This is my android code with an input Bitmap bt:

    Bitmap bt;
    int[] datas = new int[width * height];    //width and height from bitmap

    bt.getPixels(datas, 0, width, 0, 0, width, height);
    for (int i = 0; i < height; i++) {
        int index = width * i;
        for (int j = 0; j < width; j++) {
            int grey = datas[index];
            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);
            grey = (red  +  green  + blue)/3;
            datas[index] = grey;
            floatBuffer.put(index,((grey/255.0f)-0.5f)*2);
            index ++;
        }
    }

And here is my Python code:

        bytesSource = pic.tobytes()
        args = bytearray(bytesSource)
        st = ''
        for bt in args:
            st += str(bt) +"\n"
        bytes = torch.ByteStorage.from_buffer(bytesSource)

The same picture(Both .jpeg) get byte arg at PIL like this(After I trans byte to ascii int code):

Here is the result source picture and the result I get https://github.com/mawserver/test

And it cause the different result from same model. So I wanna know how to get the same result from android bitmap pixels to the PIL.Image.toBytes()

python-imaging-library
rgb
android-bitmap
tensor
asked on Stack Overflow Dec 8, 2019 by Lian Xucan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0