76 return total_intensity;
86 if (parent !=
nullptr) {
87 parent->flagAsSplit();
128 auto parent_source_id = original_source->getProperty<
SourceId>().getSourceId();
130 auto& detection_frame = original_source->getProperty<
DetectionFrame>();
131 const auto labelling_image = detection_frame.
getFrame()->getFilteredImage();
133 auto& pixel_boundaries = original_source->getProperty<
PixelBoundaries>();
135 auto& pixel_coords = original_source->getProperty<
PixelCoordinateList>().getCoordinateList();
137 auto offset = pixel_boundaries.getMin();
139 pixel_boundaries.getWidth(), pixel_boundaries.getHeight());
140 thumbnail_image->fillValue(0);
142 auto min_value = original_source->getProperty<
PeakValue>().getMinValue() * .8;
143 auto peak_value = original_source->getProperty<
PeakValue>().getMaxValue();
145 for (
auto pixel_coord : pixel_coords) {
146 auto value = labelling_image->getValue(pixel_coord);
147 thumbnail_image->setValue(pixel_coord - offset, value);
150 auto root = std::make_shared<MultiThresholdNode>(pixel_coords, 0);
158 auto threshold = min_value *
pow(peak_value / min_value, (
double) i /
m_thresholds_nb);
165 for (
auto& node : active_nodes_copy) {
166 int nb_of_groups_inside = 0;
167 for (
auto& pixel_group : lutz.
getGroups()) {
168 if (pixel_group.pixel_list.size() >=
m_min_deblend_area && node->contains(pixel_group)) {
169 nb_of_groups_inside++;
173 if (nb_of_groups_inside == 0) {
174 active_nodes.remove(node);
177 if (nb_of_groups_inside > 1) {
178 active_nodes.remove(node);
180 for (
auto& pixel_group : lutz.
getGroups()) {
181 if (pixel_group.pixel_list.size() >=
m_min_deblend_area && node->contains(pixel_group)) {
182 auto new_node = std::make_shared<MultiThresholdNode>(pixel_group.pixel_list, threshold);
183 node->addChild(new_node);
184 active_nodes.push_back(new_node);
192 double intensity_threshold = root->getTotalIntensity(*thumbnail_image, offset) *
m_contrast;
195 while (!junction_nodes.
empty()) {
196 auto node = junction_nodes.
back();
199 int nb_of_children_above_threshold = 0;
201 for (
auto child : node->getChildren()) {
202 if (child->getTotalIntensity(*thumbnail_image, offset) > intensity_threshold) {
203 nb_of_children_above_threshold++;
207 if (nb_of_children_above_threshold >= 2) {
209 for (
auto child : node->getChildren()) {
210 if (child->getTotalIntensity(*thumbnail_image, offset) > intensity_threshold && !child->isSplit()) {
218 if (source_nodes.
empty()) {
219 return { original_source };
222 for (
auto source_node : source_nodes) {
224 for (
auto& pixel : source_node->getPixels()) {
225 thumbnail_image->setValue(pixel - offset, 0);
231 new_source->setProperty<
DetectionFrame>(detection_frame.getFrame());
236 auto new_sources =
reassignPixels(sources, pixel_coords, thumbnail_image, source_nodes, offset);
238 for (
auto& new_source : new_sources) {
239 new_source->setProperty<
DetectionFrame>(detection_frame.getFrame());
240 new_source->setProperty<
SourceId>(parent_source_id);
255 for (
auto& source : sources) {
259 auto thresh = source->getProperty<
PeakValue>().getMinValue();
260 auto peak = source->getProperty<
PeakValue>().getMaxValue();
262 auto dist = pixel_list.size() / (2.0 * M_PI * shape_parameters.getAbcor() * shape_parameters.getEllipseA() * shape_parameters.getEllipseB());
263 auto amp = dist < 70.0 ? thresh * expf(dist) : 4.0 * peak;
266 if (amp > 4.0 * peak) {
273 for (
auto pixel : pixel_coords) {
274 if (image->getValue(pixel - offset) > 0) {
275 SeFloat cumulated_probability = 0;
282 for (
auto& source : sources) {
286 auto dx = pixel.m_x - pixel_centroid.getCentroidX();
287 auto dy = pixel.m_y - pixel_centroid.getCentroidY();
289 auto dist = 0.5 * (shape_parameters.getEllipseCxx()*
dx*
dx +
290 shape_parameters.getEllipseCyy()*
dy*
dy + shape_parameters.getEllipseCxy()*
dx*
dy) /
293 if (dist < min_dist) {
295 closest_source_node = source_nodes[i];
298 cumulated_probability += dist < 70.0 ? amplitudes[i] * expf(-dist) : 0.0;
300 probabilities.
push_back(cumulated_probability);
304 if (probabilities.
back() > 1.0e-31) {
306 auto drand = double(probabilities.
back()) *
double(
rand()) / RAND_MAX;
309 for (; i<probabilities.
size() && drand >= probabilities[i]; i++);
310 if (i < source_nodes.size()) {
311 source_nodes[i]->addPixel(pixel);
318 closest_source_node->addPixel(pixel);
323 int total_pixels = 0;
326 for (
auto source_node : source_nodes) {
328 for (
auto& pixel : source_node->getPixels()) {
329 image->setValue(pixel - offset, 0);
334 auto pixels = source_node->getPixels();
335 total_pixels += pixels.size();
T shared_from_this(T... args)
std::shared_ptr< EngineParameter > dx
std::shared_ptr< EngineParameter > dy