SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
BFSSegmentation.cpp
Go to the documentation of this file.
1
18#include <memory>
19#include <vector>
20#include <list>
21#include <iostream>
22
25
29
32
34
36
37namespace SourceXtractor {
38
41 auto detection_image = frame->getThresholdedImage();
43
44 VisitedMap visited(detection_image->getWidth(), detection_image->getHeight());
45
46 for (auto& tile : tiles) {
47 auto chunk = detection_image->getChunk(tile.offset.m_x, tile.offset.m_y, tile.width, tile.height);
48 for (int y=0; y<tile.height; y++) {
49 for (int x=0; x<tile.width; x++) {
51 if (!visited.wasVisited(pixel) && chunk->getValue(x, y) > 0.0) {
53 }
54 }
55 }
56 }
57}
58
62 VisitedMap& visited_map) const {
65
68
71
72 visited_map.markVisited(pc);
73 pixels_to_process.emplace_back(pc);
74
77
78 while (pixels_to_process.size() > 0) {
79 auto pixel = pixels_to_process.back();
80 pixels_to_process.pop_back();
81 source_pixels.emplace_back(pixel);
82
83 minPixel.m_x = std::min(minPixel.m_x, pixel.m_x);
84 minPixel.m_y = std::min(minPixel.m_y, pixel.m_y);
85 maxPixel.m_x = std::max(maxPixel.m_x, pixel.m_x);
86 maxPixel.m_y = std::max(maxPixel.m_y, pixel.m_y);
87
88 if (maxPixel.m_x - minPixel.m_x > m_max_delta || maxPixel.m_y - minPixel.m_y > m_max_delta) {
89 // The source extends over a too large area, ignore it
90 return;
91 }
92
93 for (auto& offset : offsets) {
94 auto new_pixel = pixel + offset;
95
96 if (!visited_map.wasVisited(new_pixel) && detectionAccessor.getValue(new_pixel) > 0.0) {
97 visited_map.markVisited(new_pixel);
98 pixels_to_process.emplace_back(new_pixel);
99 }
100 }
101 }
102
103 auto source = m_source_factory->createSource();
105 source->setProperty<SourceId>();
106 listener.publishSource(std::move(source));
107}
108
110 int tile_width = TileManager::getInstance()->getTileWidth();
111 int tile_height = TileManager::getInstance()->getTileHeight();
112
114
115
116 int size = std::max((image.getWidth() + tile_width - 1) / tile_width,
117 (image.getHeight() + tile_height - 1) / tile_height);
118
119 HilbertCurve curve(size);
120
121 for (auto& coord : curve.getCurve()) {
122 int x = coord.m_x * tile_width;
123 int y = coord.m_y * tile_height;
124
125 if (x < image.getWidth() && y < image.getHeight()) {
126 tiles.emplace_back(BFSSegmentation::Tile {
128 std::min(tile_width, image.getWidth() - x),
129 std::min(tile_height, image.getHeight() - y)
130 });
131 }
132 }
133
134 return tiles;
135}
136
137}
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
std::vector< BFSSegmentation::Tile > getTiles(const DetectionImage &image) const
void labelSource(PixelCoordinate pc, Segmentation::LabellingListener &listener, DetectionImage &detection_image, VisitedMap &visited_map) const
void labelImage(Segmentation::LabellingListener &listener, std::shared_ptr< const DetectionImageFrame > frame) override
std::shared_ptr< SourceFactory > m_source_factory
static std::shared_ptr< TileManager > getInstance()
T max(T... args)
T min(T... args)
T move(T... args)
A pixel coordinate made of two integers m_x and m_y.