Any easier way to do this?
I want to compare my labeled image to a vector of background labels.if they matches change that label to 255.Here is my code:
void markBackground(Mat input,vector backgroundLabel)
for(int x=0;x<input.cols;x++)
for(int y=0;y<input.rows;y++)
for(int i=0;i<backgroundLabel.size();i++){
if(input.at<uchar>(y,x)==backgroundLabel[i])input.at<int>(y,x)=255;
}
It involes 3 loops not very neat any other way to do this?
how many labels/background labels are there ? are those ordered ?
if you could make it so (like: anything below 5 is bg), it would be an easy:
also:
about 70-50 labels 10-20 of them will be background the label number are pretty much scattered they can be sort in order but I dont see any neccessity.
well, IF you can order the labels, the whole operation boils down to a simple thresholding.
else you could at least reorder it, like
that looks good to me.gona give it a try.thank you.
Also note that what you were doing with the .at<uchar> and .at<int> is not safe and could not work. Make sure you understand what those mean and why they wouldn't work before you use them elsewhere.