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
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