| 366 | typename out_image_type |
| 367 | > |
| 368 | void threshold_image ( |
| 369 | const in_image_type& in_img_, |
| 370 | out_image_type& out_img_, |
| 371 | typename pixel_traits<typename image_traits<in_image_type>::pixel_type>::basic_pixel_type thresh |
| 372 | ) |
| 373 | { |
| 374 | COMPILE_TIME_ASSERT( pixel_traits<typename image_traits<in_image_type>::pixel_type>::has_alpha == false ); |
| 375 | COMPILE_TIME_ASSERT( pixel_traits<typename image_traits<out_image_type>::pixel_type>::has_alpha == false ); |
| 376 | |
| 377 | COMPILE_TIME_ASSERT(pixel_traits<typename image_traits<out_image_type>::pixel_type>::grayscale); |
| 378 | |
| 379 | const_image_view<in_image_type> in_img(in_img_); |
| 380 | image_view<out_image_type> out_img(out_img_); |
| 381 | |
| 382 | // if there isn't any input image then don't do anything |
| 383 | if (in_img.size() == 0) |
| 384 | { |
| 385 | out_img.clear(); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | out_img.set_size(in_img.nr(),in_img.nc()); |
| 390 | |
| 391 | for (long r = 0; r < in_img.nr(); ++r) |
| 392 | { |
| 393 | for (long c = 0; c < in_img.nc(); ++c) |
| 394 | { |
| 395 | if (get_pixel_intensity(in_img[r][c]) >= thresh) |
| 396 | assign_pixel(out_img[r][c], on_pixel); |
| 397 | else |
| 398 | assign_pixel(out_img[r][c], off_pixel); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // ---------------------------------------------------------------------------------------- |
| 404 | |