I want to threshold an color image with particular range. If the input image pixel is with in that range it must be present in the output image. i.e. my range is : R: 122-200 ; G: 80-100 ; B:40-68
if a particular pixel of image I(x,y) is with in the range eg. I(100,130) { R:130; G:94; B: 53} then the values must be copied to output image O(x,y);
Inrange function gives binary image as output; i need RGB image as output.
i tried the following.
input image -> HSV;
HSV range selection;
HSV->RGB
input matrix: img;
output matrix : A
for (int i=0;i<img.rows;i++)
{
for(int j=0;j<img.cols;j++)
{
Vec3f intensity = img.at<Vec3b>(i,j);
float H=intensity.val[0];
float S=intensity.val[1];
float V=intensity.val[2];
if( ((H>170 && H<=179) && (S>155 && S<255) && (V>150 && V<230))
{
A.data[A.step[0]*i + A.step[1]* j + 0] = H;
A.data[A.step[0]*i + A.step[1]* j + 1] =S;
A.data[A.step[0]*i + A.step[1]* j + 2] = V;
}
}
}
the output is
it works but slows down. is there any alternative?