Ask Your Question
0

Transform gray image to create a pattern effect on while pixels given a mask

asked 2020-07-09 22:20:42 -0600

sn4k3 gravatar image

updated 2020-07-09 22:23:18 -0600

I need to create a pattern on white pixels that basically turn whites into blacks or a given brightness (50 of 255 for example) given a mask, it need to follow some rules:

1) Have a margin, for example 5 pixels each side Giving this and lets asume only 2px margin wide:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Turn into:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Example: (Sorry for bad resolution, but is the best image example i could find) image description

I tried erode with a kernel but it erodes bounds only. I guess theres a easy way to do this...

edit retag flag offensive close merge delete

Comments

so, this is about creating the mask, right ?

and it'll get much easier, if you start with the (smaller) inner region, and add the margin later, using copyMakeBorder()

berak gravatar imageberak ( 2020-07-10 02:23:36 -0600 )edit
1

But how to create that pattern on image? EDIT: Was able to find a solution, will post it tomorrow

sn4k3 gravatar imagesn4k3 ( 2020-07-10 10:20:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-07-11 22:55:05 -0600

sn4k3 gravatar image

Find a solution, don't know if is the best aproach but this work perfectly

CvInvoke.Erode(dst, erode, kernel, anchor, borderSize, BorderType.Default, default);
CvInvoke.Subtract(dst, erode, diff);
CvInvoke.Repeat(evenPattern, dst.Rows / evenPattern.Rows + 1, dst.Cols / evenPattern.Cols + 1, mask);
using (var maskReshape = new Mat(mask, new Rectangle(0, 0, dst.Width, dst.Height)))
{
      CvInvoke.BitwiseAnd(erode, maskReshape, dst);
}
CvInvoke.Add(dst, diff, dst);

result

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-07-09 22:20:42 -0600

Seen: 289 times

Last updated: Jul 11 '20