Search code examples
androidcameraandroid-camera2android-camerax

How to disable noise reduction with CameraX


So I have an application that uses CameraX ImageCapture use case to take a selfie picture than then is passed to an AI algorithm to do some stuff with it.

Now, I have an user with a Samsung Galaxy S21 who when taking pictures in one specific place with some specific light conditions is producing an image that doesn't work as expected with the AI algorithm. I have examined these images myself and noticed that the problem seems to be that ImageCapture applies strong noise reduction, so strong that even for the human eye it looks wrong, like if it was a painting instead of a photograph.

I sent a modified version of such app to this user for trying which captures the image from the Analysis use case instead and the produced image does not have that problem, so it seems whatever it is, it's some post-processing done by the ImageCapture use case that's not done in the Analysis use case.

Now, I don't seem to find a way to tweak this post-processing in CameraX, in fact I haven't even found how to do it with Camera2 neither. At first I thought it may be HDR, and I found there are some extensions to enable HDR, Night Mode and such in CameraX, but all these are disabled by default according to the documentation, and as far as you use the DEFAULT_FRONT_CAMERA none should be applied, and that's what I'm using.

CameraSelector.DEFAULT_FRONT_CAMERA

In any case it's clear that some heavy post-processing is being done to these images in the ImageCapture use case, so I'm wondering how could I disable these.

BTW, I tried initialising the ImageCapture use case with CAPTURE_MODE_MINIMIZE_LATENCY in the hope that such flag would reduce the post-processing and hopefully remove noise reduction, but that didn't work.

        imageCapture = new ImageCapture.Builder()
                .setTargetResolution(resolution)
                .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
                .build();

Any ideas on how to go beyond this to get that noise reduction filter disabled?

Thanks, Fran


Solution

  • I found a way using Camera2Interop.Extender:

        private void initImageCapture(Size resolution) {
            Log.d(TAG, "initCameraCapture: ");
            ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder();
            imageCaptureBuilder
                    .setTargetResolution(resolution)
                    .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY);
            Camera2Interop.Extender extender = new Camera2Interop.Extender(imageCaptureBuilder);
            extender.setCaptureRequestOption(CaptureRequest.NOISE_REDUCTION_MODE, CaptureRequest.NOISE_REDUCTION_MODE_OFF);
            imageCapture = imageCaptureBuilder.build();
        }