title: android, applying Sepia filter in opencv
body: <p>I´m new in Android OpenCV and I´m trying to apply Sepia effect by using Mat kernel. I have a filter class implemented for applying filter in a source Mat.</p>
  
  <p>This is the SepiaFilter class that implementes an interface Filter:</p>
  
  <pre><code>public class SepiaFilter implements Filter {
  
  Mat mSepiaKernel;
  
  public SepiaFilter() {
  
      mSepiaKernel = new Mat(4, 4, CvType.CV_32F);
      mSepiaKernel.put(0, 0, /* R */0.189f, 0.769f, 0.393f, 0f);
      mSepiaKernel.put(1, 0, /* G */0.168f, 0.686f, 0.349f, 0f);
      mSepiaKernel.put(2, 0, /* B */0.131f, 0.534f, 0.272f, 0f);
      mSepiaKernel.put(3, 0, /* A */0.000f, 0.000f, 0.000f, 1f);
  }
  
  @Override
  public void apply(Mat src, Mat dest) {
  
      Mat tmpMat = src.clone();
  
      Core.transform(tmpMat, dest, mSepiaKernel);
     // Imgproc.filter2D(tmpMat, dest, -1, mSepiaKernel); not used
    }
  }
  </code></pre>
  
  <p>This is an static method for getting a Mat from a file.
  I´m using this static method in order to open all images with the same process. 
  I´m not 100% sure yet about the color I should apply for <strong>Imgproc.COLOR_BGR2RGBA</strong>.</p>
  
  <pre><code> public static Mat getMatFromFile(File file){
          Mat rgbLoadedImage = null;
  
          Mat image = Imgcodecs.imread(file.getAbsolutePath());
  
          if (image.width() &gt; 0) {
  
              rgbLoadedImage = new Mat(image.size(), image.type());
  
              Imgproc.cvtColor(image, rgbLoadedImage, Imgproc.COLOR_BGR2RGBA);
  
              LOGD(TAG, "loadedImage: " + "chans: " + image.channels()
                      + ", (" + image.width() + ", " + image.height() + ")");
  
              image.release();
          }
  
          return rgbLoadedImage;
      }
  </code></pre>
  
  <p>And this is the call to the class:</p>
  
  <pre><code>mCurrentImgMat = getMatFromFile(fileImage);
  Mat sepiaMat = new Mat(mCurrentImgMat.size(), mCurrentImgMat.type());
  
  new SepiaFilter().apply(mCurrentImgMat, sepiaMat);
  </code></pre>
  
  <p>The last step is to get a Bitmap form the Mat:</p>
  
  <pre><code> Bitmap bitmap = Bitmap.createBitmap(src.cols(), src.rows(), Bitmap.Config.ARGB_8888);
          Utils.matToBitmap(src, bitmap);
  </code></pre>
  
  <p>Once I apply the filter it is partially or almost all image white instead of the Sepia color. I´d like to know what I´m doing wrong. 
  I guess it can either be the <em>Sepia Kernel</em> or the <em>Core.transformation</em>. I´ve  also tried with <em>Imgproc.COLOR_BGR2RGBA</em>. </p>
  
  <p>Some links that I´ve been checking for getting an idea</p>
  
  <p><a href="http://answers.opencv.org/question/30328/how-to-implement-filters/" rel="nofollow">http://answers.opencv.org/question/30328/how-to-implement-filters/</a></p>
  
  <p><a href="https://github.com/Itseez/opencv/blob/master/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java" rel="nofollow">Here mSepiaKernel</a></p>