0

I am trying to convert a bitmap image to look like captured in thermal or night.

But i have no idea what/how to modify the pixels to look like that. I only know

public static Bitmap newBitmapwithNightOrThermalEffect(Bitmap bmp) {
        long start = System.currentTimeMillis();
        int width = bmp.getWidth();
        int height = bmp.getHeight();
        Bitmap bitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.RGB_565);
        int pixColor = 0;
        int pixR = 0;
        int pixG = 0;
        int pixB = 0;
        int newR = 0;
        int newG = 0;
        int newB = 0;
        int[] pixels = new int[width * height];
        bmp.getPixels(pixels, 0, width, 0, 0, width, height);
        for (int i = 0; i < height; i++) {
            for (int k = 0; k < width; k++) {
                pixColor = pixels[width * i + k];
                pixR = Color.red(pixColor);
                pixG = Color.green(pixColor);
                pixB = Color.blue(pixColor);

        //how can i modify newR,newG and newB to look like night or thermal


                newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);  
                newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
                newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
                int newColor = Color.argb(255, newR > 255 ? 255 : newR,
                        newG > 255 ? 255 : newG, newB > 255 ? 255 : newB);
                pixels[width * i + k] = newColor;
            }
        }

        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        long end = System.currentTimeMillis();
        Log.d("may", "used time=" + (end - start));
        return bitmap;
    }

Read my comment in Code

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • A similar question has been asked some days ago. I suggested to first make the image Gray Scaled and then apply a Green toning. For reference: https://www.google.com/search?q=infrared+vision&espv=2&biw=1280&bih=615&source=lnms&tbm=isch&sa=X&ei=Y1AuVavLIKPnyQPQ_ILYCg&ved=0CAYQ_AUoAQ#tbm=isch&q=night+vision And, **instead of a (x,y) nested loop**, you better use **ColorMatrices**, for speed sake! – Phantômaxx Apr 15 '15 at 11:50
  • And how can i apply green toning. – Zar E Ahmer Apr 15 '15 at 12:01
  • The same way as you greyscale an image: with a ColorMatrix. See this answer (it's SEPIA - just change the color parameters to create a green toning): http://stackoverflow.com/a/9149010/2649012 – Phantômaxx Apr 15 '15 at 12:03

0 Answers0