imGetCopy

copy and repack image from region to new image

imGetCopy
(
string file = __FILE__
size_t line = __LINE__
size_t B
E
)
(
,
in Region!(B, E) copy_reg
,,
size_t[2] repack_dim = [0, 1]
)
if (
isIntegral!E
)

Examples

1 auto a = Image( ivec!1(5), ElemInfo( 2, DataType.FLOAT ) );
2 a.pixel!vec2(3) = vec2(1,1);
3 a.pixel!vec2(4) = vec2(2,2);
4 auto b = imGetCopy( a, Region!(1,int)(3,2) );
5 assert( b.pixel!vec2(0) == a.pixel!vec2(3) );
6 assert( b.pixel!vec2(1) == a.pixel!vec2(4) );
1 ubyte[] imgdata = [
2     1, 2, 3, 4,
3     5, 6, 7, 8,
4     9,10,11,12,
5    13,14,15,16
6 ];
7 
8 auto img = Image( ivec2(4,4), 1, DataType.UBYTE, imgdata );
9 
10 {
11     ubyte[] r = [ 8,12,16, 7,11,15 ];
12     assertEq( imGetCopy( img, iRegion2(2,1,2,3), ImRepack.ROT90 ).mapAs!ubyte, r );
13 }
14 
15 {
16     ubyte[] r = [ 14,10,6, 15,11,7 ];
17     assertEq( imGetCopy( img, iRegion2(1,1,2,3), ImRepack.ROT270 ).mapAs!ubyte, r );
18 }
19 
20 {
21     ubyte[] r= [ 3,2,1, 7,6,5 ];
22     assertEq( imGetCopy( img, iRegion2(0,0,3,2), ImRepack.MIRHOR ).mapAs!ubyte, r );
23 }
24 
25 {
26     ubyte[] r = [ 5,6,7, 1,2,3 ];
27     assert( imGetCopy( img, iRegion2(0,0,3,2), ImRepack.MIRVER ).mapAs!ubyte == r );
28 }
1 ubyte[] img_data =
2 [
3     1,2,3,
4     4,5,6,
5 
6     7,8,9,
7     10,11,12,
8 ];
9 
10 ubyte[] d2l0 = [ 1,2,3,4,5,6 ];
11 ubyte[] d2l1 = [ 7,8,9,10,11,12 ];
12 
13 ubyte[] d1l0 = [ 1,2,3,7,8,9 ];
14 ubyte[] d1l1 = [ 4,5,6,10,11,12 ];
15 
16 ubyte[] d0l0 = [ 1, 4, 7, 10 ];
17 ubyte[] d0l1 = [ 2, 5, 8, 11 ];
18 
19 auto img = Image( ivec3(3,2,2), 1, DataType.UBYTE, img_data );
20 
21 assertEq( imGetCopy( img, CrdRegionD(0,0,0,3,2,1) ).mapAs!ubyte, d2l0 );
22 assertEq( imGetCopy( img, CrdRegionD(0,0,1,3,2,1) ).mapAs!ubyte, d2l1 );
23 
24 assertEq( imGetCopy( img, CrdRegionD(0,0,0,3,1,2) ).mapAs!ubyte, d1l0 );
25 assertEq( imGetCopy( img, CrdRegionD(0,1,0,3,1,2) ).mapAs!ubyte, d1l1 );
26 
27 assertEq( imGetCopy( img, CrdRegionD(0,0,0,1,2,2) ).mapAs!ubyte, d0l0 );
28 assertEq( imGetCopy( img, CrdRegionD(1,0,0,1,2,2) ).mapAs!ubyte, d0l1 );
1 ubyte[] data =
2 [
3     2, 1, 3, 5, 2,
4     9, 1, 2, 6, 3,
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     1, 2, 6, 3, 0, 0, 0,
13     5, 2, 9, 1, 0, 0, 0,
14     3, 6, 3, 0, 0, 0, 0,
15     2, 8, 1, 5, 0, 0, 0,
16     0, 0, 0, 0, 0, 0, 0,
17     0, 0, 0, 0, 0, 0, 0,
18     0, 0, 0, 0, 0, 0, 0
19 ];
20 
21 ubyte[] datav2 =
22 [
23     0, 0, 0, 0, 0, 0, 0,
24     0, 2, 1, 3, 5, 2, 0,
25     0, 9, 1, 2, 6, 3, 0,
26     0, 2, 5, 2, 9, 1, 0,
27     0, 8, 3, 6, 3, 0, 0,
28     0, 6, 2, 8, 1, 5, 0,
29     0, 0, 0, 0, 0, 0, 0
30 ];
31 
32 
33 auto orig = Image( ivec2( 7, 7 ), ElemInfo( 1, DataType.UBYTE ) );
34 auto im = Image( ivec2( 5, 5 ), 1, DataType.UBYTE, data );
35 
36 auto res = Image(orig);
37 imCopy( res, ivec2(-1,-1), im );
38 assert( res.data == datav1 );
39 
40 res = Image(orig);
41 imCopy( res, ivec2(1,1), im );
42 assert( res.data == datav2 );

Meta