# How can we check if a particular pixel is in this pixel range or not?

I have a BGR value of a pixel in Vec3b format and I want to check if this BGR value is in some predefined BGR range.Now I know we cannot compare two vectors simply like >= or <= so I tried using their magnitude by norm but I am getting false results. Can anyone please suggest something?

My code is

 struct palette
{
Vec3b Lower_range;
Vec3b Upper_range;
string name;

};

struct palette range;

Mat get_dominant_palette(vector<Vec3b> colors) {

range.Lower_range = (75, 5, 0);
range.Upper_range = (252, 142, 32);
range.name = "Royal Blue";
range.Lower_range = (163, 140, 90);
range.Upper_range = (245, 225, 181);
range.name = "Sky Blue";

const int tile_size = 64;
Mat ret = Mat(tile_size, tile_size*colors.size(), CV_8UC3, cv::Scalar(0));

for (int i = 0; i<colors.size(); i++) {
Rect rect(i*tile_size, 0, tile_size, tile_size);
myfile << "[" << (int)colors[i] << " ," << (int)colors[i] << " ," << (int)colors[i] << "]" << endl;
rectangle(ret, rect, Scalar(colors[i], colors[i], colors[i]), CV_FILLED);
}

for (int i = 0; i < colors.size(); i++) {
double colors_magnitude = cv::norm(colors[i], CV_L2);
for (int j = 0; j < 2; j++) {
double Lower_magnitude = cv::norm(range[j].Lower_range, CV_L2);
double Upper_magnitude = cv::norm(range[j].Upper_range, CV_L2);
if (Lower_magnitude <= colors_magnitude <= Upper_magnitude) {

color << range[j].name << "---" << "[" << (int)colors[i] << " ," << (int)colors[i] << " ," << (int)colors[i] << "]" << endl;
}
}
}
return ret;


}

So here my pixel values are in the colors vector and I am checking if the pixel is skyblue or royal blue but I am getting all the pixels as the both colors.

edit retag close merge delete