time Image Processing: Noise in HSV image (openCV)

I am doing a real-time shapes and colors classification system with very high accuracy. It seems like my preprocessing phase is not good enough so that the result is not as accurate as I expected. Here is what I'm doing:

  • Take data from the Camera can crop it to receive ROI.
  • Convert ROI Image from RGB to HSV space.
  • Using a median filter to reduce noise in HSV image.
  • Threshold the image
  • Using dilate and erode to remove small holes and small objects in Image
  • Using findContours and approxPolyDP to detect square objects.
  • This is my preprocessing phase:

    image_cv = cv::cvarrToMat(image_camera); 
    Mat cropped = image_cv(cv::Rect(0, 190, 640, 110));
    imshow("origin", cropped);
    Mat croppedCon = CropConveyor(cropped);
    cv::cvtColor(croppedCon, croppedCon, CV_RGB2HSV);
    medianBlur(croppedCon, croppedCon, 3);
    cv::Mat binRect;
    cv::inRange(croppedCon, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), binRect);
    

    This is the code for detecting squares:

    vector<vector<Point>> contours;
    findContours(binarizedIm, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
    
    vector<Point> approx;
    for (size_t i = 0; i < contours.size(); i++)
    {
        //double arclength = arcLength(Mat(contours[i]), true);
        approxPolyDP(Mat(contours[i]), approx, 3.245 , true);   //0.04 for wood
        if (approx.size() != 4) continue;
        if (isContourConvex(Mat(approx)) && contourArea(Mat(approx)) > 250)
        {
            double MaxCos = 0;
            for (int j = 2; j < 5; j++)
            {
                double cos = angle(approx[j % 4], approx[j - 1], approx[j - 2]);
                MaxCos = MAX(cos, MaxCos);
            }
    
            if (MaxCos < 0.2)
                squares.push_back(approx);
        }
    }
    

    I think noise in HSV Image is the main reason. Here is some images illustrating my problems. I saw a lot of noise in HSV Image, that's why I use a media filter to it to reduce noise but preserve the edges becase I think that edges information is very important when using findContours function. HSV and HSV in separate channels My question is:

  • What is the noise in HSV Image, refer to the above Image, how can I enhance my Image's quality?

  • The reason for noise in your saturation image is noise in your input image. Caused by a bad camera / optics and further increased by JPEG compression.

    That's by far the worst image I have seen in years. You shouldn't invest another second into processing that, unless you live on Mars and need results tomorrow.

    Your input image is super noisy, undersampled, defocussed, underexposed, full of aliasing and compression artifacts and pretty much anything else you can do wrong with an image.

    First rule of signal processing:

    crap in = crap out

    You can get much better cameras basically for free. Find and use one.


    Part of the problem is that you're doing the noise reduction in HSV space. In your example you can see the V channel is better-behaved than H and S. It would be better to do noise-reduction in RGB (which is more linear and closer, though not identical, to the camera's native colour space where the noise originates; of course there's also gamma-correction).

    Maybe consider a stronger edge-preserving noise-reducing filter such as Bilateral Filter.


    I don't get it why are you using HSV for segmenting the objects, the RGB image is good enough. Separate the image into 3 channels (r,g,b) and apply an adaptive threshold on them. dilate and erode the images then add (not merging) those 3 binary images to have one binary image. Finally do level 6 of your recipe to extract the objects. If the noise still effects the result, apply a bilateral filter on r,g,b channels before the threshold.

    链接地址: http://www.djcxy.com/p/79638.html

    上一篇: Octave和MATLAB的区别?

    下一篇: 实时图像处理:HSV图像中的噪声(openCV)