在网络上找了很久,得知伽马转化的原理 大致就是有一个函数,进行然后里面有一个伽马因子,然后去改变每个像素的值。
于是我写了下面的代码
- /**
- * 伽码矫正
- */
- private Bitmap gammaCorrectFilter(Bitmap bitmap){
- Mat src = new Mat();
- Utils.bitmapToMat(bitmap,src);
- float fPrecompensation = 1F / 2.2F;
- //构建一个伽码数组表
- int[] g_GammaLUT = new int[256];
- float f = 0F;
- for(int i = 0; i < 256; i++){
- f = (i + 0.5F) / 256;
- f = (int) Math.pow(f,fPrecompensation);
- g_GammaLUT[i] = (int) f;
- }
- int[] tempInt = new int[src.channels()];
- for(int i = 0; i < src.rows(); i++){
- for(int j = 0; j < src.cols(); j++){
- src.get(i,j,tempInt);
- for(int x = 0; x < tempInt.length; x++){
- tempInt[x] = g_GammaLUT[tempInt[x]];
- }
- src.put(i,j,tempInt);
- }
- }
- Utils.matToBitmap(src,bitmap);
- return bitmap;
- }
复制代码 图片形式的代码:
然后这里出现了一个问题,就是Mat对象在get的时候,需要是“CV_32S”类型。
而我如何把Mat的type转成CV_32S类型呢?
说到底,Mat的类型转化,我不知道如何转化,麻烦各位大神了。
|