imCopy

copy image region to new image

imCopy
(
size_t N
T
)
(
in Image!N img
,
in Region!(N, T) r
)
if (
isIntegral!T
)

Examples

auto a = Image1( [5], ElemInfo( DataType.FLOAT, 2 ) );
a.pixel!vec2(3) = vec2(1,1);
a.pixel!vec2(4) = vec2(2,2);
auto b = imCopy( a, Region!(1,int)(3,2) );
assert( b.pixel!vec2(0) == a.pixel!vec2(3) );
assert( b.pixel!vec2(1) == a.pixel!vec2(4) );
1 ubyte[] data = 
2 [
3     2, 1, 3, 5, 2,
4     9, 1, 2, 6, 0,
5     2, 5, 2, 9, 1,
6     8, 3, 6, 3, 0,
7     6, 2, 8, 1, 5 
8 ];
9 
10 ubyte[] datav1 =
11 [
12     0, 0, 0, 0, 0, 0, 0, 
13     0, 2, 1, 3, 5, 2, 0,
14     0, 9, 1, 2, 6, 0, 0,
15     0, 2, 5, 2, 9, 1, 0,
16     0, 8, 3, 6, 3, 0, 0,
17     0, 6, 2, 8, 1, 5, 0,
18     0, 0, 0, 0, 0, 0, 0 
19 ];
20 
21 ubyte[] datav2 = 
22 [
23     1, 2, 6,
24     5, 2, 9,
25     3, 6, 3
26 ];
27 
28 ubyte[] datav3 =
29 [
30     0, 0, 0, 0,
31     0, 2, 1, 3,
32     0, 9, 1, 2,
33     0, 2, 5, 2
34 ];
35 
36 ubyte[] datav4 =
37 [
38     0, 0, 0, 0, 
39     3, 5, 2, 0,
40     2, 6, 0, 0,
41     2, 9, 1, 0
42 ];
43 
44 ubyte[] datav5 =
45 [
46     0, 2, 5, 2,
47     0, 8, 3, 6,
48     0, 6, 2, 8,
49     0, 0, 0, 0
50 ];
51 
52 ubyte[] datav6 =
53 [
54     2, 9, 1, 0,
55     6, 3, 0, 0,
56     8, 1, 5, 0,
57     0, 0, 0, 0 
58 ];
59 
60 auto orig = Image2( [5,5], DataType.UBYTE, 1, data );
61 auto im = imCopy( orig, iRegion2( 0, 0, 5, 5 ) );
62 assert( orig == im );
63 
64 auto imv1 = Image2( ivec2( 7, 7 ), DataType.UBYTE, 1, datav1 );
65 assert( imCopy( orig, iRegion2( -1, -1, 7, 7 ) ) == imv1 );
66 
67 auto imv2 = Image2( [3,3], DataType.UBYTE, 1, datav2 );
68 assert( imCopy( orig, iRegion2( 1, 1, 3, 3 ) ) == imv2 );
69 
70 auto imv3 = Image2( ivec2(4,4), DataType.UBYTE, 1, datav3 );
71 assert( imCopy( orig, iRegion2( -1, -1, 4, 4 ) ) == imv3 );
72 
73 auto imv4 = Image2( ivec2(4,4), DataType.UBYTE, 1, datav4 );
74 assert( imCopy( orig, iRegion2( 2, -1, 4, 4 ) ) == imv4 );
75 
76 auto imv5 = Image2( ivec2(4,4), DataType.UBYTE, 1, datav5 );
77 assert( imCopy( orig, iRegion2( -1, 2, 4, 4 ) ) == imv5 );
78 
79 auto imv6 = Image2( [4,4], DataType.UBYTE, 1, datav6 );
80 assert( imCopy( orig, iRegion2( 2, 2, 4, 4 ) ) == imv6 );

Meta