如何使用OpenCV在CUDA上查找图像的雾度? [英] How to find haze extent of an image with OpenCV on CUDA?

查看:381
本文介绍了如何使用OpenCV在CUDA上查找图像的雾度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到图像的RGB值的最大和最小。
我计划去的流程是:


  1. 加载图片。

  2. 在加载图片后,在要测试的单元格周围创建一个15x15单元格

  3. 找到测试单元格的RGB的最大值并将其存储在数组中。

  4. 然后打印具有max RGB值的图像。根据我,图像应该是一个DARK图像。 RGB的最大值对应于图像的黑暗部分。

这里的问题是图像处理,opencv。
i不知道如何实现这些我上面提到的事情



DCP:





代码:

  #include< opencv2 / opencv.hpp> 
using namespace cv;

void minFilter(const Mat1b& src,Mat1b& dst,int radius)
{
Mat1b padded;
copyMakeBorder(src,padded,radius,radius,radius,radius,BORDER_CONSTANT,Scalar(255));

int rr = src.rows;
int cc = src.cols;
dst = Mat1b(rr,cc,uchar(0));

for(int c = 0; c {
for(int r = 0; r uchar最低= 255;
for(int i = -radius; i <= radius; ++ i)
{
for(int j = -radius; j <= radius; ++ j)
{
uchar val = padded(radius + r + i,radius + c + j);
if(val< lowest)lowest = val;
}
}
dst(r,c)= lowest;
}
}
}


void minValue3b(const Mat3b& src,Mat1b& dst)
{
int rr = src.rows;
int cc = src.cols;

dst = Mat1b(rr,cc,uchar(0));

for(int c = 0; c {
for(int r = 0; r {
const Vec3b& v = src(r,c);

uchar最低= v [0];
if(v [1]< lowest)lowest = v [1];
if(v [2]< lowest)lowest = v [2];
dst(r,c)= lowest;
}
}
}

void DarkChannel(const Mat3b& img,Mat1b& dark,int patchSize)
{
int radius = patchSize / 2;

Mat1b low;
minValue3b(img,low);
minFilter(low,dark,radius);
}


int main()
{
//加载图片
Mat3b img = imread(path_to_image);

//计算DCP
Mat1b dark;
DarkChannel(img,dark,15);

//显示结果
imshow(Img,img);
imshow(Dark,dark);
waitKey();

return 0;
}


I m trying to find the maximum and minimum of RGB values of an image. the flow in which i was planning to go is:

  1. load the image.
  2. after loading the image, create a 15x15 cell around the cell to be tested
  3. find the max of RGB of the test cell and store it in an array.
  4. then print the image with the value of max RGB, According to me the image should be a DARK image. The max of RGB corresponds to the dark portion of the image

The problem here is i m new to image processing, opencv. i dont know how to implement these things which i mentioned abovei have attached a picture related to my doubt

Here is code, i have just read image and got some details of image

#include "iostream"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "opencv2/opencv.hpp"

float lambda=0.0001;    //lambda
double _w=0.95;         //w
int height=0;           //image Height
int width=0;            //image Width
int size=0;         //total number of pixels
int blockdim = 32;

char img_name[100]="1.png";

Mat read_image()
{
    Mat img = imread(img_name);
    height = img.rows;
    width = img.cols;
    size = img.rows*img.cols;
    Mat real_img(img.rows,img.cols,CV_32FC3);
    img.convertTo(real_img,CV_32FC3);
    return real_img;
 }

//Main Function
int main(int argc, char * argv[])
{
     Mat img = read_image();
    /*****************************************************************/
    // Till here i have done my code. i.e. Read my image and get all   details about the image 
    // Now i'm not getting the logic to find the Min/Max of RGB values in an image for 
    // 15x15 cell

    return 0;
}

Finally i want to implement this on GPU, i have learnt few things about GPU,CUDA and played on GPU. Now i wanna do some stuff related to image processing on GPU(CUDA)

I want to compute the extent of haze of an image for each block. This is done by finding the dark channel value that is used to reflect the extent of haze. This concept is from Kaiming He's paper on a Single Image Haze Removal using Dark Channel Prior.

The dark channel value for each block is defined as follows:

where I^c (x',y') denotes the intensity at a pixel location (x',y') in color channel c (one of Red, Green, or Blue color channel), and omega(x,y) denotes the neighborhood of the pixel location (x',y').

since i m new to Image processing and open cv, i'm not sure how to translate this equation

解决方案

I already implemented this some time ago, and below is the code snippet. Probably could be further optimized, and you should add cuda support by yourself, but this could be a good starting point.

The main steps are:

  1. Load a BGR image
  2. Compute a single channel matrix with the minimum of B,G,R (minValue3b).
  3. Compute the minimum in a patchSize x patchSize neighborhood (minFilter).

NOTES

  • You need to find the minimum value, not the maximum.
  • To avoid border issues while searching the minimum in the neighborhood, you can simply add a border big enough around the image, with the maximum allowed value (i.e. 255). You can use copyMakeBorder for this.

Input:

DCP:

Code:

#include <opencv2/opencv.hpp>
using namespace cv;

void minFilter(const Mat1b& src, Mat1b& dst, int radius)
{
    Mat1b padded;
    copyMakeBorder(src, padded, radius, radius, radius, radius, BORDER_CONSTANT, Scalar(255));

    int rr = src.rows;
    int cc = src.cols;
    dst = Mat1b(rr, cc, uchar(0));

    for (int c = 0; c < cc; ++c)
    {
        for (int r = 0; r < rr; ++r)
        {
            uchar lowest = 255;
            for (int i = -radius; i <= radius; ++i)
            {
                for (int j = -radius; j <= radius; ++j)
                {
                    uchar val = padded(radius + r + i, radius + c + j);
                    if (val < lowest) lowest = val;
                }
            }
            dst(r, c) = lowest;
        }
    }
}


void minValue3b(const Mat3b& src, Mat1b& dst)
{
    int rr = src.rows;
    int cc = src.cols;

    dst = Mat1b(rr, cc, uchar(0));

    for (int c = 0; c<cc; ++c)
    {
        for (int r = 0; r<rr; ++r)
        {
            const Vec3b& v = src(r, c);

            uchar lowest = v[0];
            if (v[1] < lowest) lowest = v[1];
            if (v[2] < lowest) lowest = v[2];
            dst(r, c) = lowest;
        }
    }
}

void DarkChannel(const Mat3b& img, Mat1b& dark, int patchSize)
{
    int radius = patchSize / 2;

    Mat1b low;
    minValue3b(img, low);
    minFilter(low, dark, radius);
}


int main()
{
    // Load the image
    Mat3b img = imread("path_to_image");

    // Compute DCP
    Mat1b dark;
    DarkChannel(img, dark, 15);

    // Show results
    imshow("Img", img);
    imshow("Dark", dark);
    waitKey();

    return 0;
}

这篇关于如何使用OpenCV在CUDA上查找图像的雾度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆