zb3 / MTKBetterCam

Tools for dealing with RAW image files produced by the MTK EngineerMode app...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MTKBetterCam

Note: This repository is a nonsense. Cameras in MTK phones are so crappy it doesn't make sense to even bother. But I wanted to see what I could theoretically do, what's the highest quality image I could get. Resulting images are better than MTK's jpegs (total rubbish, just like this repository), but the quality is still very low.

There are two main tools:

  • fixraw - prepend TIFF metadata to RAW image files produced by the MTK EngineerMode app (and optionally remove noise) so that we can open them using dcraw/UFRaw
  • fiximage.py - use machine learning to fix colors of the (already processed) image. This needs to be "trained" (and is slow), see below. This tool is universal, but you may need to change the model parameters.

fixraw

... is written in C, so let's compile it:

make

Then we have:

$ ./fixraw
./fixraw [-w WIDTH] [-h HEIGHT] [-b BPP] [-u VALUE_TO_SUBTRACT] INPUT OUTPUT

Non-obvious options are:

  • b - bits per pixel, by default set to 10
  • u - "unbias", this denoises the image by subtracting a given value from each pixel. For instance, files produced on my phone have a bias value of 64.

This tool assumes that the RAW file is encoded using little-endian, and that the bayer pattern starts with BG. In practice, files produced by this tool are usable only in dcraw-based programs...

fiximage

  1. ctable.py file builds a color table to be used for training the model. You can tweak the table here.
  2. display-ctable.py displays that table so you can take a picture of it with MTK app
  3. detectable.py is used to detect and extract this color table from a photo using OpenCV (but NOT from a RAW file, this assumes the image is already processed ). See the source of this file.
  4. trainmodel.py then trains a polynomial regression model, where colors seen in photo are input, and colors generated by ctable.py are output. This kinda works, but see the source.
  5. fiximage.py applies that model to a given (processed) image to make its colors look better.

You will need:

  • Python 3
  • OpenCV
  • scikit-learn

Training the model

python display-ctable.py

Then take a picture of it... use fixraw, then process it, making the image as good as you can, then:

python detectable.py processed_photo.ppm

... and it should work, showing you the table (press any key then). But this tool is not magic, it has alot of parameters so check out the source. Then:

python trainmodel.py

This outputs self-score and crossvalidated score, if it's not something like 0.97 or more then you should tweak the parameters or even use different model like neural networks...

Fixing images

If you have a processed image file X, run this to fix its colors:

python fiximage.py X

About

Tools for dealing with RAW image files produced by the MTK EngineerMode app...


Languages

Language:Python 73.7%Language:C 25.4%Language:Makefile 0.9%