## Ordered Dither: Bayer recurrence relation

### Ordered Dither: Bayer recurrence relation

Hi,
i have to implement the Bayer recurrence  relation in c++, but i dont
really know how it works.

The realtion:

T_N(i,j) = [ 4T_N/2                       4T_N/2 + 2U_N/2]
[ 4T_N/2 + 3U_N/2       4T_N/2 + U_N/2]

U_N is a N x N matrix where every element is 1.
Can somebody give me tips or explain how to do this?

Greetings,
Sven

### Ordered Dither: Bayer recurrence relation

Quote:>i have to implement the Bayer recurrence  relation in c++, but i dont
>really know how it works.

>The realtion:

>T_N(i,j) = [ 4T_N/2                       4T_N/2 + 2U_N/2]
>                 [ 4T_N/2 + 3U_N/2       4T_N/2 + U_N/2]

>U_N is a N x N matrix where every element is 1.
>Can somebody give me tips or explain how to do this?

Is this for a class? How is it you know the formula but not what it
means? Please use a monospaced font for 2D equations.

You omit a crucial detail: the 2x2 matrix is

(2)   [0 2]
T    = [3 1]

The next larger matrix will double in size to 4x4. It is made of four
blocks, each a 2x2 matrix.

[ [0 2]  [1 1]     [0 2]  [1 1] ]
(4)   [4[3 1]+0[1 1]    4[3 1]+2[1 1] ]
T    = [                               ]
[ [0 2]  [1 1]     [0 2]  [1 1] ]
[4[3 1]+3[1 1]    4[3 1]+1[1 1] ]

[  0  8     2 10 ]
[ 12  4    14  6 ]
= [                ]
[  3 11     1  9 ]
[ 15  7    13  5 ]

The next matrix will be 8x8, made of four 4x4 blocks based on this
one. And so on.

### Ordered Dither: Bayer recurrence relation

Quote:

> You omit a crucial detail: the 2x2 matrix is

>    (2)   [0 2]
>   T    = [3 1]

> The next larger matrix will double in size to 4x4. It is made of four
> blocks, each a 2x2 matrix.

How to get from here:

Quote:>          [ [0 2]  [1 1]     [0 2]  [1 1] ]
>    (4)   [4[3 1]+0[1 1]    4[3 1]+2[1 1] ]
>   T    = [                               ]
>          [ [0 2]  [1 1]     [0 2]  [1 1] ]
>          [4[3 1]+3[1 1]    4[3 1]+1[1 1] ]

here:?

Quote:>          [  0  8     2 10 ]
>          [ 12  4    14  6 ]
>        = [                ]
>          [  3 11     1  9 ]
>          [ 15  7    13  5 ]

> The next matrix will be 8x8, made of four 4x4 blocks based on this
> one. And so on.

That is the problem! How can i do this?
Greetings,
Sven

### Ordered Dither: Bayer recurrence relation

Quote:>How to get from here:

>>          [ [0 2]  [1 1]     [0 2]  [1 1] ]
>>    (4)   [4[3 1]+0[1 1]    4[3 1]+2[1 1] ]
>>   T    = [                               ]
>>          [ [0 2]  [1 1]     [0 2]  [1 1] ]
>>          [4[3 1]+3[1 1]    4[3 1]+1[1 1] ]

>here:?

>>          [  0  8     2 10 ]
>>          [ 12  4    14  6 ]
>>        = [                ]
>>          [  3 11     1  9 ]
>>          [ 15  7    13  5 ]

>> The next matrix will be 8x8, made of four 4x4 blocks based on this
>> one. And so on.

>That is the problem! How can i do this?

The entry "11" is 4*2 + 3*1. The entry "14" is 4*3 + 2*1. Beyond that,

### Ordered Dither: Bayer recurrence relation

Quote:

> The entry "11" is 4*2 + 3*1. The entry "14" is 4*3 + 2*1. Beyond that,

Ok now i understand how the relation works. But i dont know how to
implement it in C++.
I have to know how to return a matrix from a function. Does anybody know how
it works?

Greetings Sven

### Ordered Dither: Bayer recurrence relation

Sven Braun:

Quote:>Ok now i understand how the relation works. But i dont know how to
>implement it in C++.
>I have to know how to return a matrix from a function. Does anybody know how
>it works?

Define your own class that stores a matrix.

Or return an array of primitive values. You could define that the
values of a one-dimensional array are to be interpreted left to right,
top to bottom. Or use a two-dimensional array.

Regards,
Marco

### Ordered Dither: Bayer recurrence relation

Quote:> Define your own class that stores a matrix.

> Or return an array of primitive values. You could define that the
> values of a one-dimensional array are to be interpreted left to right,
> top to bottom. Or use a two-dimensional array.

Thx,
How to return a 2D array?
Can you show me a sample source code?

### Ordered Dither: Bayer recurrence relation

Quote:>Ok now i understand how the relation works. But i dont know how to
>implement it in C++.
>I have to know how to return a matrix from a function. Does anybody know how
>it works?

We all do. At this point you are not asking about graphics algorithms,
you are trying to learn how to program in C++. That is off-topic for
this newsgroup. We welcome your graphics-specific questions here; as
for the rest, try one of these groups

Does anyone know of any algorithms for ordered dithering using only 16 colors?

TKK Enterprises, Inc.                   CIS UserID: 76167,2273