-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathconvenience.php
151 lines (118 loc) · 3.97 KB
/
convenience.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
use Jcupitt\Vips;
class VipsConvenienceTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
$this->image = Vips\Image::newFromFile($filename);
/* The original value of pixel (0, 0).
*/
$this->pixel = $this->image->getpoint(0, 0);
}
public function testVipsBandjoin()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$rgb = $image->bandjoin([$image, $image]);
$this->assertEquals($rgb->width, 3);
$this->assertEquals($rgb->height, 2);
$this->assertEquals($rgb->bands, 3);
}
public function testVipsBandsplit()
{
$arr = $this->image->bandsplit();
$this->assertEquals(count($arr), 3);
$this->assertEquals($arr[0]->bands, 1);
}
public function testVipsAddConst()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$image = $image->add(1);
$pixel = $image->crop(0, 0, 1, 1)->avg();
$this->assertEquals($pixel, 2);
}
public function testVipsSubtractConst()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$image = $image->subtract(1);
$pixel = $image->getpoint(1, 1);
$this->assertEquals(count($pixel), 1);
$this->assertEquals($pixel[0], 4);
}
public function testVipsMultiplyConst()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$image = $image->multiply(2);
$pixel = $image->getpoint(1, 1);
$this->assertEquals(count($pixel), 1);
$this->assertEquals($pixel[0], 10);
}
public function testVipsDivideConst()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$image = $image->divide(2);
$pixel = $image->getpoint(0, 1);
$this->assertEquals(count($pixel), 1);
$this->assertEquals($pixel[0], 2);
}
public function testVipsGetPoint()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$rgb = $image->bandjoin([$image, $image]);
$rgb = $rgb->add(1);
$pixel = $rgb->getpoint(0, 0);
$this->assertEquals($pixel, [2, 2, 2]);
}
public function testVipsBandjoinConst()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$imagea = $image->bandjoin(255);
$pixel = $imagea->getpoint(0, 0);
$this->assertEquals($pixel, [1, 255]);
}
public function testVipsIfthenelseConst()
{
$if = $this->image->more(34)->ifthenelse(255, $this->image);
$pixel = $if->getpoint(0, 0);
$this->assertEquals($pixel, [255, 255, 34]);
$if = $this->image->more(34)->ifthenelse($this->image, 255);
$pixel = $if->getpoint(0, 0);
$this->assertEquals($pixel, [39, 38, 255]);
$if = $this->image->more(34)->ifthenelse(128, 255);
$pixel = $if->getpoint(0, 0);
$this->assertEquals($pixel, [128, 128, 255]);
}
public function testVipsIfthenelseBlend()
{
$mask = $this->image[1];
$blended = $mask->ifthenelse($mask, [255, 0, 0], ["blend" => true]);
$pixel = $blended->getpoint(0, 0);
$this->assertEquals($pixel, [223, 6, 6]);
}
public function testVipsMaxpos()
{
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$result = $image->maxpos();
$this->assertEquals($result, [6, 2, 1]);
}
public function testVipsBandrank()
{
$vips = $this->image->bandrank($this->image);
$result = $vips->getpoint(0, 0);
$this->assertEquals($result, [39, 38, 34]);
}
public function testVipsMedian()
{
$vips = $this->image->median(5);
$result = $vips->getpoint(0, 0);
$this->assertEquals($result, [37, 38, 33]);
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: expandtab sw=4 ts=4 fdm=marker
* vim<600: expandtab sw=4 ts=4
*/