Nested if-else conditions
Hello All...I know this is very small and stupid doubt but I don't know why I'm getting stuck here. I am using nested if-else loops inside "for" loop in my code but it at all not going inside this "for" loop. I checked it by putting Log.d statements inside each condition but none of then are getting printed. My block of code is as follows:
Mat fin = new Mat (gray.rows(), gray.cols(), CvType.CV_8UC3);
for (int ii=0;ii<rows;ii++)
{
for (int j=0;j<cols;j++)
{
if ( gray.get(ii, j)[0] < 32)
{
fin.get(ii, j)[0] = 1;
}
else if (gray.get(ii, j)[0]>31 && gray.get(ii, j)[0] < 64)
{
fin.get(ii, j)[0] = 2;
}
else if (gray.get(ii, j)[0] > 63 && gray.get(ii, j)[0] < 96)
{
fin.get(ii, j)[0] = 3;
}
else if (gray.get(ii, j)[0] > 95 && gray.get(ii, j)[0] < 128)
{
fin.get(ii, j)[0] = 4;
}
else if (gray.get(ii, j)[0] > 127 && gray.get(ii, j)[0] < 160)
{
fin.get(ii, j)[0] = 5;
}
else if (gray.get(ii, j)[0] > 159 && gray.get(ii, j)[0] < 192)
{
fin.get(ii, j)[0] = 6;
}
else if (gray.get(ii, j)[0] > 191 && gray.get(ii, j)[0] < 224)
{
fin.get(ii, j)[0] = 7;
}
else if (gray.get(ii, j)[0] > 223 && gray.get(ii, j)[0] < 256)
{
fin.get(ii, j)[0] = 8;
}
}
}
Please help!! Thanks in advance!!
may i know what you are trying to achieve here? May be there is no need to loop through pixels!
Hello, first where you find get() method for cv::Mat class? It is not existed in official docs. Second thing is if conditions - they are overloaded, see
if( x < 32) else if( x > 31 && x < 64)
is equivalent ofif( x < 32) else if( x < 64)
, but last one demands less computationsmay be something like this :
@Balaji R:: I am trying to divide 256 pixels values into 8 bins. Just like normalization.
@pi-null-mezon:: This get() method is used for fetching the respective location. I got it from this forum only earlier.
@LBerger:: I tried with this earlier but getting all values as zero.
I don't know java but you have to split plane first and merge after. in C++ :
it is not really optimized because you split a mat with zero.
Please could you answer to @Balaji R ?
@pi-null-mezon:: The second one is also not working.
You really need to read this "how_to_scan_images"
You really need to read this how_to_scan_images