0

I want to average pixel color between two similar pixels. White pixels between black pixels should become black and vice versa. This rule must apply in all directions. This is the complete example of what should happen:

Horizontal:
□■□ -> □□□

Vertical:
□   ->  □
■   ->  □
□   ->  □

■□■ -> ■■■


■   ->  ■
□   ->  ■
■   ->  ■


□■□  ->   □□□   ->   □□□
■■■  ->   ■■■   ->   ■□■
■□■  ->   ■□■   ->   ■□■

Can OpenCV do this? Can anyone make algorighm like this? This is what I tried:

while(i<image->width){
    while(j<image->height){
        if(pixel[i,j-1] == pixel[i,j+1]){
            pixel[i,j] = pixel[i,j-1];
        }else if(pixel[i-1,j] == pixel[i+1,j]){
            pixel[i,j] = pixel[i-1,j];
        }
        j++;
    }
    i++;
}
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

1 Answers1

0

You didn't access the image pixels correctly.

For gray-scale image (in your example, Mat pixel), to access its pixel, you should use:

pixel.at<uchar>(j, i) = ...;
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174