color correction/filter for colorblind

729 Views Asked by At

I am creating an application in android that has pictures display, and I would like to add a feature that support color blind filters, which means if someone has color deficiency he would see that pictures better (just like how windows has color filters or how some video games have those too).

Now, I have built all the picture processing codes I need, and I only need values for correctly filtering the pictures which makes them correspond to the colorblind type. I have found this website: http://web.archive.org/web/20081014161121/http://www.colorjack.com/labs/colormatrix/

However, this doesn't fix the colors instead it simulates how the colorblind person sees them. I don't want a colorblind simulator, I want to fix the colors for the specific type. I have been searching for everything I could possibly think off, but I found nothing that could help. The only thing I found is this:
https://community.windows.com/en-us/stories/color-filter#wcss-main-content

This is Microsoft's windows color filters and apparently the explanation for each blind type is written next to it. for example "Deuteranopia – For red-green color blindness, adds focus on green hues", so it seems like I need to add focus on green hues, but still I don't know how should I make that.

I hope you understand what I mean. Does anyone has anything that could help or something with values that I could apply on my pictures (with RGB values or such)?

Thank you very much

1

There are 1 best solutions below

0
On

You can filter the bitmaps using ColorMatrixColorFilter. Here is an example:

import android.app.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.os.*;
import android.widget.*;

public class MainActivity extends Activity 
{
    private static final float[] INVERTED = {
        //red, green, blue, alpha, saturation
           -1F,          0,      0,         0,          255F, //red
              0,        -1F,     0,         0,          255F, //green
              0,           0,   -1F,        0,          255F, //blue
              0,           0,      0,       1F,                0, //alpha
    };
    
    private static final float[] GRAYSCALE = {
            0.3F, 0.59F, 0.11F, 0F, 0,
            0.3F, 0.59F, 0.11F, 0F, 0,
            0.3F, 0.59F, 0.11F, 0F, 0,
               0F,       0F,      0F, 1F, 0,
    };
    
    //'Protanopia':[0.567,0.433,0,0,0, 0.558,0.442,0,0,0, 0,0.242,0.758,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Protanomaly':[0.817,0.183,0,0,0, 0.333,0.667,0,0,0, 0,0.125,0.875,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Deuteranopia':[0.625,0.375,0,0,0, 0.7,0.3,0,0,0, 0,0.3,0.7,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Deuteranomaly':[0.8,0.2,0,0,0, 0.258,0.742,0,0,0, 0,0.142,0.858,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Tritanopia':[0.95,0.05,0,0,0, 0,0.433,0.567,0,0, 0,0.475,0.525,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Tritanomaly':[0.967,0.033,0,0,0, 0,0.733,0.267,0,0, 0,0.183,0.817,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Achromatopsia':[0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0,0,0,1,0, 0,0,0,0,1],
    //'Achromatomaly':[0.618,0.320,0.062,0,0, 0.163,0.775,0.062,0,0, 0.163,0.320,0.516,0,0,0,0,0,1,0,0,0,0,0]}[v]);

    private static final float[] PROTANOPIA = {
            0.567F, 0.433F,         0F, 0F, 0,
            0.558F, 0.442F,         0F, 0F, 0,
                    0F, 0.242F, 0.758F, 0F, 0,
                    0F,         0F,        0F, 1F, 0,
    };
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView imageView = findViewById(R.id.iv);
        
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inMutable = true;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.circle, options);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        
        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(PROTANOPIA);
        paint.setColorFilter(filter);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(bitmap, 0, 0, paint);
        Drawable drawable = new BitmapDrawable(getResources(), bitmap);
        imageView.setBackgroundDrawable(drawable);
    }
}

As you see, for Protanopia and the rest, the colors are not the same like those you're seeing in Microsoft's windows color filters. So either you'll have to do more research on that, or make an app that you can slide/adjust the colors.