| 396 | * \return New image. */ |
| 397 | |
| 398 | class ClassificationMapper |
| 399 | { |
| 400 | const std::vector<std::shared_ptr<MapColor>>& sourceImageColors; |
| 401 | const KohonenMap& km; |
| 402 | |
| 403 | public: |
| 404 | ClassificationMapper(const std::vector<std::shared_ptr<MapColor>>& sic, KohonenMap& km) |
| 405 | : sourceImageColors(sic) |
| 406 | , km(km) |
| 407 | {} |
| 408 | |
| 409 | double operator()(const QImage& sourceImage, QImage& outputImage, ProgressObserver& observer) const |
| 410 | { |
| 411 | auto const width = outputImage.width(); |
| 412 | auto const height = outputImage.height(); |
| 413 | |
| 414 | auto color = std::unique_ptr<MapColor>( |
| 415 | dynamic_cast<MapColor*>(sourceImageColors[0]->clone())); |
| 416 | |
| 417 | double quality = 0; |
| 418 | for (int y = 0; y < height && !observer.isInterruptionRequested(); y++) |
| 419 | { |
| 420 | for (int x = 0; x < width; x++) |
| 421 | { |
| 422 | double distance; |
| 423 | color->setRGBTriplet(sourceImage.pixel(x, y)); |
| 424 | int index = km.findClosest(*color, distance); |
| 425 | outputImage.setPixel(x, y, index); |
| 426 | quality += color->squares(*sourceImageColors[index]); |
| 427 | } |
| 428 | observer.setPercentage((100*y) / height); |
| 429 | } |
| 430 | return quality; |
| 431 | } |
| 432 | |
| 433 | using concurrent_processing = HorizontalStripes; |
| 434 | }; |
| 435 | Q_STATIC_ASSERT((Concurrency::supported<ClassificationMapper>::value)); |
| 436 | |
| 437 | |