Home | History | Annotate | Download | only in ocl
      1 /*
      2  * cv_image_sharp.cpp - image sharp
      3  *
      4  *  Copyright (c) 2016-2017 Intel Corporation
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *   http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * Author: Andrey Parfenov <a1994ndrey (at) gmail.com>
     19  * Author: Wind Yuan <feng.yuan (at) intel.com>
     20  */
     21 
     22 #include "cv_image_sharp.h"
     23 
     24 namespace XCam {
     25 
     26 
     27 CVImageSharp::CVImageSharp ()
     28     : CVBaseClass ()
     29 {
     30 
     31 }
     32 
     33 cv::Mat
     34 CVImageSharp::sharp_image_gray (const cv::Mat &image, float sigmar)
     35 {
     36     cv::Mat temp_image;
     37     image.convertTo (temp_image, CV_32FC1);
     38     cv::Mat bilateral_image;
     39     cv::bilateralFilter (temp_image, bilateral_image, 5, sigmar, 2);
     40 
     41     cv::Mat sharp_filter = (cv::Mat_<float>(3, 3) << -1, -1, -1, -1, 8, -1, -1, -1, -1);
     42     cv::Mat filtered_image;
     43     cv::filter2D (bilateral_image, filtered_image, -1, sharp_filter);
     44     cv::normalize (filtered_image, filtered_image, 0, 255.0f, cv::NORM_MINMAX);
     45     cv::Mat sharpened = temp_image + filtered_image;
     46     cv::normalize (sharpened, sharpened, 0, 255.0f, cv::NORM_MINMAX);
     47     return sharpened.clone ();
     48 }
     49 
     50 float
     51 CVImageSharp::measure_sharp (const cv::Mat &image)
     52 {
     53     cv::Mat dst;
     54     cv::Laplacian (image, dst, -1, 3, 1, 0, cv::BORDER_CONSTANT);
     55     dst.convertTo (dst, CV_8UC1);
     56     float sum = cv::sum (dst)[0];
     57     sum /= (image.rows * image.cols);
     58     return sum;
     59 }
     60 
     61 }
     62