MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / morphImageTest

Function morphImageTest

test/morph.cpp:152–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150
151template<typename T, bool isDilation, bool isColor>
152void morphImageTest(string pTestFile, dim_t seLen) {
153 SUPPORTED_TYPE_CHECK(T);
154 IMAGEIO_ENABLED_CHECK();
155
156 vector<dim4> inDims;
157 vector<string> inFiles;
158 vector<dim_t> outSizes;
159 vector<string> outFiles;
160
161 readImageTests(pTestFile, inDims, inFiles, outSizes, outFiles);
162
163 size_t testCount = inDims.size();
164
165 for (size_t testId = 0; testId < testCount; ++testId) {
166 af_array _inArray = 0;
167 af_array inArray = 0;
168 af_array maskArray = 0;
169 af_array outArray = 0;
170 af_array _goldArray = 0;
171 af_array goldArray = 0;
172 dim_t nElems = 0;
173
174 inFiles[testId].insert(0, string(TEST_DIR "/morph/"));
175 outFiles[testId].insert(0, string(TEST_DIR "/morph/"));
176
177 af_dtype targetType = static_cast<af_dtype>(dtype_traits<T>::af_type);
178
179 dim4 mdims(seLen, seLen, 1, 1);
180 ASSERT_SUCCESS(af_constant(&maskArray, 1.0, mdims.ndims(), mdims.get(),
181 targetType));
182
183 ASSERT_SUCCESS(
184 af_load_image(&_inArray, inFiles[testId].c_str(), isColor));
185 ASSERT_SUCCESS(af_cast(&inArray, _inArray, targetType));
186
187 ASSERT_SUCCESS(
188 af_load_image(&_goldArray, outFiles[testId].c_str(), isColor));
189 ASSERT_SUCCESS(af_cast(&goldArray, _goldArray, targetType));
190
191 ASSERT_SUCCESS(af_get_elements(&nElems, goldArray));
192
193 af_err error_code = AF_SUCCESS;
194 if (isDilation) {
195 error_code = af_dilate(&outArray, inArray, maskArray);
196 } else {
197 error_code = af_erode(&outArray, inArray, maskArray);
198 }
199
200#if defined(AF_CPU)
201 ASSERT_SUCCESS(error_code);
202 ASSERT_IMAGES_NEAR(goldArray, outArray, 0.018f);
203#else
204 if (targetType != b8 && seLen > 19) {
205 ASSERT_EQ(error_code, AF_ERR_NOT_SUPPORTED);
206 } else {
207 ASSERT_SUCCESS(error_code);
208 ASSERT_IMAGES_NEAR(goldArray, outArray, 0.018f);
209 }

Callers

nothing calls this directly

Calls 10

readImageTestsFunction · 0.85
af_get_elementsFunction · 0.85
af_constantFunction · 0.50
af_load_imageFunction · 0.50
af_castFunction · 0.50
af_dilateFunction · 0.50
af_erodeFunction · 0.50
af_release_arrayFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected