中值过滤器OpenMP优化

时间:2016-11-03 12:44:49

标签: c++ performance image-processing openmp median

我正在尝试使用CImg库并行化中值过滤器。代码看起来很简单:

class ViewController: UIViewController {
    @IBOutlet var blurView: UIVisualEffectView!

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        updateBlurViewHole()
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        updateBlurViewHole()
    }

    func updateBlurViewHole() {
        let maskView = UIView(frame: blurView.bounds)
        maskView.clipsToBounds = true;
        maskView.backgroundColor = UIColor.clear

        let outerbezierPath = UIBezierPath.init(roundedRect: blurView.bounds, cornerRadius: 0)
        let rect = CGRect(x: 150, y: 150, width: 100, height: 100)
        let innerCirclepath = UIBezierPath.init(roundedRect:rect, cornerRadius:rect.height * 0.5)
        outerbezierPath.append(innerCirclepath)
        outerbezierPath.usesEvenOddFillRule = true

        let fillLayer = CAShapeLayer()
        fillLayer.fillRule = kCAFillRuleEvenOdd
        fillLayer.fillColor = UIColor.green.cgColor // any opaque color would work
        fillLayer.path = outerbezierPath.cgPath
        maskView.layer.addSublayer(fillLayer)

        blurView.mask = maskView;
    }
}

class ViewController: UIViewController { @IBOutlet var blurView: UIVisualEffectView! override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) updateBlurViewHole() } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() updateBlurViewHole() } func updateBlurViewHole() { let maskView = UIView(frame: blurView.bounds) maskView.clipsToBounds = true; maskView.backgroundColor = UIColor.clearColor() let outerbezierPath = UIBezierPath.init(roundedRect: blurView.bounds, cornerRadius: 0) let rect = CGRect(x: 150, y: 150, width: 100, height: 100) let innerCirclepath = UIBezierPath.init(roundedRect:rect, cornerRadius:rect.height * 0.5) outerbezierPath.appendPath(innerCirclepath) outerbezierPath.usesEvenOddFillRule = true let fillLayer = CAShapeLayer() fillLayer.fillRule = kCAFillRuleEvenOdd fillLayer.fillColor = UIColor.greenColor().CGColor fillLayer.path = outerbezierPath.CGPath maskView.layer.addSublayer(fillLayer) blurView.maskView = maskView } } 函数与此案例无关,但无论如何:

void omp_median_filter(CImg<float> & img) {
  CImg<float> copy(img);
  size_t i;
  #pragma omp parallel for schedule(dynamic)
  for (i = 1; i < img.width()-1; i++) {
    for (size_t j = 1; j < img.height()-1; j++) {
      for (size_t k = 0; k < img.spectrum(); k++) {
        img(i, j, k) = getNeighboursMedian(copy, i, j, k);
      }
    }
  }
}

我的问题是:我可以使用任何额外的编译指示参数来加快速度吗?我一直在尝试一些事情,但没有人增加algorythm的表现......我不知道。

提前致谢。

1 个答案:

答案 0 :(得分:1)

也许您应该查看CImg方法CImg<T>::blur_median()的代码。它还使用openMP并行化实现中值过滤器。在文件CImg.h中搜索。