色盲的颜色校正/滤色器

color correction/filter for colorblind(色盲的颜色校正/滤色器)

本文介绍了色盲的颜色校正/滤色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Android创建一个可以显示图片的应用程序,我想添加一个支持色盲滤镜的功能,这意味着如果某人有颜色缺陷,他会看到更好的图片(就像Windows的滤色器或一些视频游戏也有滤色器一样)。 现在,我已经构建了我需要的所有图片处理代码,我只需要正确过滤图片的值,使它们与色盲类型相对应。我找到了这个网站: http://web.archive.org/web/20081014161121/http://www.colorjack.com/labs/colormatrix/

然而,这并不能修复颜色,而是模拟色盲人士看到它们的方式。我不想要色盲模拟器,我想为特定类型固定颜色。我一直在寻找我能想到的一切,但我没有找到任何能帮上忙的东西。我发现的唯一东西是:
https://community.windows.com/en-us/stories/color-filter#wcss-main-content

这是微软的Windows滤色器,显然,每种盲色类型的解释都写在它的旁边。例如,后视眼-对于红绿色盲,增加了对绿色色调的关注,所以我似乎需要增加对绿色色调的关注,但我仍然不知道应该如何做到这一点。

我希望你明白我的意思。有没有人有什么可以帮助我的东西,或者我可以在我的图片上应用的值的东西(RGB值或类似的值)?

非常感谢

推荐答案

您可以使用ColorMatrixColorFilter过滤位图。 下面是一个例子:

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);
    }
}

如您所见,Protanopia和其余部分的颜色与您在Microsoft's windows color filters中看到的颜色不同。因此,要么你必须对此做更多的研究,要么开发一款可以滑动/调整颜色的应用程序。

这篇关于色盲的颜色校正/滤色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:色盲的颜色校正/滤色器