comparison UnitTestsSources/ImageProcessingTests.cpp @ 3503:46cf170ba121

ImageProcessing::SeparableConvolution()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Aug 2019 12:10:13 +0200
parents e0841192d7d0
children 18566f9e1831
comparison
equal deleted inserted replaced
3502:c160eafc42a9 3503:46cf170ba121
210 std::vector<ImageProcessing::ImagePoint> points; 210 std::vector<ImageProcessing::ImagePoint> points;
211 points.push_back(ImageProcessing::ImagePoint(1,1)); 211 points.push_back(ImageProcessing::ImagePoint(1,1));
212 points.push_back(ImageProcessing::ImagePoint(1,5)); 212 points.push_back(ImageProcessing::ImagePoint(1,5));
213 points.push_back(ImageProcessing::ImagePoint(5,5)); 213 points.push_back(ImageProcessing::ImagePoint(5,5));
214 214
215 Orthanc::ImageProcessing::FillPolygon(image, points, 255); 215 ImageProcessing::FillPolygon(image, points, 255);
216 216
217 // outside polygon 217 // outside polygon
218 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0)); 218 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0));
219 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 6)); 219 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 6));
220 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 6, 6)); 220 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 6, 6));
237 points.push_back(ImageProcessing::ImagePoint(0, 0)); 237 points.push_back(ImageProcessing::ImagePoint(0, 0));
238 points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),0)); 238 points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),0));
239 points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),image.GetHeight())); 239 points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),image.GetHeight()));
240 points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight())); 240 points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight()));
241 241
242 ASSERT_THROW(Orthanc::ImageProcessing::FillPolygon(image, points, 255), Orthanc::OrthancException); 242 ASSERT_THROW(ImageProcessing::FillPolygon(image, points, 255), OrthancException);
243 } 243 }
244 244
245 TYPED_TEST(TestIntegerImageTraits, FillPolygonFullImage) 245 TYPED_TEST(TestIntegerImageTraits, FillPolygonFullImage)
246 { 246 {
247 ImageAccessor& image = this->GetImage(); 247 ImageAccessor& image = this->GetImage();
252 points.push_back(ImageProcessing::ImagePoint(0, 0)); 252 points.push_back(ImageProcessing::ImagePoint(0, 0));
253 points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,0)); 253 points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,0));
254 points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,image.GetHeight() - 1)); 254 points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,image.GetHeight() - 1));
255 points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight() - 1)); 255 points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight() - 1));
256 256
257 Orthanc::ImageProcessing::FillPolygon(image, points, 255); 257 ImageProcessing::FillPolygon(image, points, 255);
258 258
259 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0)); 259 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0));
260 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, image.GetWidth() - 1, image.GetHeight() - 1)); 260 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, image.GetWidth() - 1, image.GetHeight() - 1));
261 } 261 }
262
263
264
265
266 static void SetGrayscale8Pixel(ImageAccessor& image,
267 unsigned int x,
268 unsigned int y,
269 uint8_t value)
270 {
271 ImageTraits<PixelFormat_Grayscale8>::SetPixel(image, value, x, y);
272 }
273
274 static bool TestGrayscale8Pixel(const ImageAccessor& image,
275 unsigned int x,
276 unsigned int y,
277 uint8_t value)
278 {
279 PixelTraits<PixelFormat_Grayscale8>::PixelType p;
280 ImageTraits<PixelFormat_Grayscale8>::GetPixel(p, image, x, y);
281 return p == value;
282 }
283
284 static void SetRGB24Pixel(ImageAccessor& image,
285 unsigned int x,
286 unsigned int y,
287 uint8_t red,
288 uint8_t green,
289 uint8_t blue)
290 {
291 PixelTraits<PixelFormat_RGB24>::PixelType p;
292 p.red_ = red;
293 p.green_ = green;
294 p.blue_ = blue;
295 ImageTraits<PixelFormat_RGB24>::SetPixel(image, p, x, y);
296 }
297
298 static bool TestRGB24Pixel(const ImageAccessor& image,
299 unsigned int x,
300 unsigned int y,
301 uint8_t red,
302 uint8_t green,
303 uint8_t blue)
304 {
305 PixelTraits<PixelFormat_RGB24>::PixelType p;
306 ImageTraits<PixelFormat_RGB24>::GetPixel(p, image, x, y);
307 return (p.red_ == red &&
308 p.green_ == green &&
309 p.blue_ == blue);
310 }
311
312
313 TEST(ImageProcessing, FlipGrayscale8)
314 {
315 {
316 Image image(PixelFormat_Grayscale8, 0, 0, false);
317 ImageProcessing::FlipX(image);
318 ImageProcessing::FlipY(image);
319 }
320
321 {
322 Image image(PixelFormat_Grayscale8, 1, 1, false);
323 SetGrayscale8Pixel(image, 0, 0, 128);
324 ImageProcessing::FlipX(image);
325 ImageProcessing::FlipY(image);
326 ASSERT_TRUE(TestGrayscale8Pixel(image, 0, 0, 128));
327 }
328
329 {
330 Image image(PixelFormat_Grayscale8, 3, 2, false);
331 SetGrayscale8Pixel(image, 0, 0, 10);
332 SetGrayscale8Pixel(image, 1, 0, 20);
333 SetGrayscale8Pixel(image, 2, 0, 30);
334 SetGrayscale8Pixel(image, 0, 1, 40);
335 SetGrayscale8Pixel(image, 1, 1, 50);
336 SetGrayscale8Pixel(image, 2, 1, 60);
337
338 ImageProcessing::FlipX(image);
339 ASSERT_TRUE(TestGrayscale8Pixel(image, 0, 0, 30));
340 ASSERT_TRUE(TestGrayscale8Pixel(image, 1, 0, 20));
341 ASSERT_TRUE(TestGrayscale8Pixel(image, 2, 0, 10));
342 ASSERT_TRUE(TestGrayscale8Pixel(image, 0, 1, 60));
343 ASSERT_TRUE(TestGrayscale8Pixel(image, 1, 1, 50));
344 ASSERT_TRUE(TestGrayscale8Pixel(image, 2, 1, 40));
345
346 ImageProcessing::FlipY(image);
347 ASSERT_TRUE(TestGrayscale8Pixel(image, 0, 0, 60));
348 ASSERT_TRUE(TestGrayscale8Pixel(image, 1, 0, 50));
349 ASSERT_TRUE(TestGrayscale8Pixel(image, 2, 0, 40));
350 ASSERT_TRUE(TestGrayscale8Pixel(image, 0, 1, 30));
351 ASSERT_TRUE(TestGrayscale8Pixel(image, 1, 1, 20));
352 ASSERT_TRUE(TestGrayscale8Pixel(image, 2, 1, 10));
353 }
354 }
355
356
357
358 TEST(ImageProcessing, FlipRGB24)
359 {
360 Image image(PixelFormat_RGB24, 2, 2, false);
361 SetRGB24Pixel(image, 0, 0, 10, 100, 110);
362 SetRGB24Pixel(image, 1, 0, 20, 100, 110);
363 SetRGB24Pixel(image, 0, 1, 30, 100, 110);
364 SetRGB24Pixel(image, 1, 1, 40, 100, 110);
365
366 ImageProcessing::FlipX(image);
367 ASSERT_TRUE(TestRGB24Pixel(image, 0, 0, 20, 100, 110));
368 ASSERT_TRUE(TestRGB24Pixel(image, 1, 0, 10, 100, 110));
369 ASSERT_TRUE(TestRGB24Pixel(image, 0, 1, 40, 100, 110));
370 ASSERT_TRUE(TestRGB24Pixel(image, 1, 1, 30, 100, 110));
371
372 ImageProcessing::FlipY(image);
373 ASSERT_TRUE(TestRGB24Pixel(image, 0, 0, 40, 100, 110));
374 ASSERT_TRUE(TestRGB24Pixel(image, 1, 0, 30, 100, 110));
375 ASSERT_TRUE(TestRGB24Pixel(image, 0, 1, 20, 100, 110));
376 ASSERT_TRUE(TestRGB24Pixel(image, 1, 1, 10, 100, 110));
377 }
378
379
380 TEST(ImageProcessing, ResizeBasicGrayscale8)
381 {
382 Image source(PixelFormat_Grayscale8, 2, 2, false);
383 SetGrayscale8Pixel(source, 0, 0, 10);
384 SetGrayscale8Pixel(source, 1, 0, 20);
385 SetGrayscale8Pixel(source, 0, 1, 30);
386 SetGrayscale8Pixel(source, 1, 1, 40);
387
388 {
389 Image target(PixelFormat_Grayscale8, 2, 4, false);
390 ImageProcessing::Resize(target, source);
391 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 0, 10));
392 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 0, 20));
393 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 1, 10));
394 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 1, 20));
395 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 2, 30));
396 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 2, 40));
397 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 3, 30));
398 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 3, 40));
399 }
400
401 {
402 Image target(PixelFormat_Grayscale8, 4, 2, false);
403 ImageProcessing::Resize(target, source);
404 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 0, 10));
405 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 0, 10));
406 ASSERT_TRUE(TestGrayscale8Pixel(target, 2, 0, 20));
407 ASSERT_TRUE(TestGrayscale8Pixel(target, 3, 0, 20));
408 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 1, 30));
409 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 1, 30));
410 ASSERT_TRUE(TestGrayscale8Pixel(target, 2, 1, 40));
411 ASSERT_TRUE(TestGrayscale8Pixel(target, 3, 1, 40));
412 }
413 }
414
415
416 TEST(ImageProcessing, ResizeBasicRGB24)
417 {
418 Image source(PixelFormat_RGB24, 2, 2, false);
419 SetRGB24Pixel(source, 0, 0, 10, 100, 110);
420 SetRGB24Pixel(source, 1, 0, 20, 100, 110);
421 SetRGB24Pixel(source, 0, 1, 30, 100, 110);
422 SetRGB24Pixel(source, 1, 1, 40, 100, 110);
423
424 {
425 Image target(PixelFormat_RGB24, 2, 4, false);
426 ImageProcessing::Resize(target, source);
427 ASSERT_TRUE(TestRGB24Pixel(target, 0, 0, 10, 100, 110));
428 ASSERT_TRUE(TestRGB24Pixel(target, 1, 0, 20, 100, 110));
429 ASSERT_TRUE(TestRGB24Pixel(target, 0, 1, 10, 100, 110));
430 ASSERT_TRUE(TestRGB24Pixel(target, 1, 1, 20, 100, 110));
431 ASSERT_TRUE(TestRGB24Pixel(target, 0, 2, 30, 100, 110));
432 ASSERT_TRUE(TestRGB24Pixel(target, 1, 2, 40, 100, 110));
433 ASSERT_TRUE(TestRGB24Pixel(target, 0, 3, 30, 100, 110));
434 ASSERT_TRUE(TestRGB24Pixel(target, 1, 3, 40, 100, 110));
435 }
436
437 {
438 Image target(PixelFormat_RGB24, 4, 2, false);
439 ImageProcessing::Resize(target, source);
440 ASSERT_TRUE(TestRGB24Pixel(target, 0, 0, 10, 100, 110));
441 ASSERT_TRUE(TestRGB24Pixel(target, 1, 0, 10, 100, 110));
442 ASSERT_TRUE(TestRGB24Pixel(target, 2, 0, 20, 100, 110));
443 ASSERT_TRUE(TestRGB24Pixel(target, 3, 0, 20, 100, 110));
444 ASSERT_TRUE(TestRGB24Pixel(target, 0, 1, 30, 100, 110));
445 ASSERT_TRUE(TestRGB24Pixel(target, 1, 1, 30, 100, 110));
446 ASSERT_TRUE(TestRGB24Pixel(target, 2, 1, 40, 100, 110));
447 ASSERT_TRUE(TestRGB24Pixel(target, 3, 1, 40, 100, 110));
448 }
449 }
450
451
452 TEST(ImageProcessing, ResizeEmptyGrayscale8)
453 {
454 {
455 Image source(PixelFormat_Grayscale8, 0, 0, false);
456 Image target(PixelFormat_Grayscale8, 2, 2, false);
457 ImageProcessing::Resize(target, source);
458 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 0, 0));
459 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 0, 0));
460 ASSERT_TRUE(TestGrayscale8Pixel(target, 0, 1, 0));
461 ASSERT_TRUE(TestGrayscale8Pixel(target, 1, 1, 0));
462 }
463
464 {
465 Image source(PixelFormat_Grayscale8, 2, 2, false);
466 Image target(PixelFormat_Grayscale8, 0, 0, false);
467 ImageProcessing::Resize(target, source);
468 }
469 }