Assigining a negative value to a pixel

后端 未结 2 1640
野趣味
野趣味 2021-01-16 17:39

Using some criterion, there are some pixels in the image which I\'m not interested in. So, I would like to neglect them. I just want to ask if the approach I have followed i

2条回答
  •  长情又很酷
    2021-01-16 17:58

    It depends on how you use the image. A negative value in a pixel doesn't have any real representation. But if you use Matlab function imshow(img,[]) it will scale all the values considering -1 as the lowest number (so it will be represented in the output).

    It is preferible to use a mask. A mask is a binary array of the same size of the image that indicates if a pixel is valid (1) or not (0).

    For example, in OpenCV there are a lot of functions that can use a mask (last argument const CvArr* mask = NULL). Here you have an example on how to use a mask in OpenCV:

    Mat srcImage; //RGB source image
    
    //Create a mask. Here we select a rectangle:
    Mat mask = Mat::zeros(srcImage.size(), CV_8U);  // type of mask is CV_8U
    Mat roi(mask, cv::Rect(10,10,100,100));
    roi = Scalar(255, 255, 255);
    
    //Apply any function to the srcImage ONLY in the points selected by a mask
    SurfFeatureDetector detector();
    std::vector keypoints;
    detector.detect(srcImage, keypoints, mask);     // passing `mask` as a parameter
    

提交回复
热议问题