77 return total_intensity;
87 if (parent !=
nullptr) {
88 parent->flagAsSplit();
129 auto parent_source_id = original_source->getProperty<
SourceId>().getSourceId();
131 auto& detection_frame = original_source->getProperty<
DetectionFrame>();
132 const auto labelling_image = detection_frame.
getFrame()->getFilteredImage();
134 auto& pixel_boundaries = original_source->getProperty<
PixelBoundaries>();
136 auto& pixel_coords = original_source->getProperty<
PixelCoordinateList>().getCoordinateList();
138 auto offset = pixel_boundaries.getMin();
140 pixel_boundaries.getWidth(), pixel_boundaries.getHeight());
141 thumbnail_image->fillValue(0);
143 auto min_value = original_source->getProperty<
PeakValue>().getMinValue() * .8;
144 auto peak_value = original_source->getProperty<
PeakValue>().getMaxValue();
148 for (
auto pixel_coord : pixel_coords) {
149 auto value = labelling_image->getValue(pixel_coord);
150 thumbnail_image->setValue(pixel_coord - offset, value);
154 auto root = std::make_shared<MultiThresholdNode>(pixel_coords, 0);
162 auto threshold = min_value *
pow(peak_value / min_value, (
double) i /
m_thresholds_nb);
169 for (
auto& node : active_nodes_copy) {
170 int nb_of_groups_inside = 0;
171 for (
auto& pixel_group : lutz.
getGroups()) {
172 if (pixel_group.pixel_list.size() >=
m_min_deblend_area && node->contains(pixel_group)) {
173 nb_of_groups_inside++;
177 if (nb_of_groups_inside == 0) {
178 active_nodes.remove(node);
181 if (nb_of_groups_inside > 1) {
182 active_nodes.remove(node);
184 for (
auto& pixel_group : lutz.
getGroups()) {
185 if (pixel_group.pixel_list.size() >=
m_min_deblend_area && node->contains(pixel_group)) {
186 auto new_node = std::make_shared<MultiThresholdNode>(pixel_group.pixel_list, threshold);
187 node->addChild(new_node);
188 active_nodes.push_back(new_node);
196 double intensity_threshold = root->getTotalIntensity(*thumbnail_image, offset) *
m_contrast;
199 while (!junction_nodes.
empty()) {
200 auto node = junction_nodes.
back();
203 int nb_of_children_above_threshold = 0;
205 for (
auto child : node->getChildren()) {
206 if (child->getTotalIntensity(*thumbnail_image, offset) > intensity_threshold) {
207 nb_of_children_above_threshold++;
211 if (nb_of_children_above_threshold >= 2) {
213 for (
auto child : node->getChildren()) {
214 if (child->getTotalIntensity(*thumbnail_image, offset) > intensity_threshold && !child->isSplit()) {
222 if (source_nodes.
empty()) {
223 return { original_source };
226 for (
auto source_node : source_nodes) {
228 for (
auto& pixel : source_node->getPixels()) {
229 thumbnail_image->setValue(pixel - offset, 0);
235 new_source->setProperty<
DetectionFrame>(detection_frame.getFrame());
240 auto new_sources =
reassignPixels(sources, pixel_coords, thumbnail_image, source_nodes, offset);
242 for (
auto& new_source : new_sources) {
243 new_source->setProperty<
DetectionFrame>(detection_frame.getFrame());
244 new_source->setProperty<
SourceId>(parent_source_id);
259 for (
auto& source : sources) {
263 auto thresh = source->getProperty<
PeakValue>().getMinValue();
264 auto peak = source->getProperty<
PeakValue>().getMaxValue();
266 auto dist = pixel_list.size() / (2.0 * M_PI * shape_parameters.getAbcor() * shape_parameters.getEllipseA() * shape_parameters.getEllipseB());
267 auto amp = dist < 70.0 ? thresh * expf(dist) : 4.0 * peak;
270 if (amp > 4.0 * peak) {
277 for (
auto pixel : pixel_coords) {
278 if (image->getValue(pixel - offset) > 0) {
279 SeFloat cumulated_probability = 0;
286 for (
auto& source : sources) {
290 auto dx = pixel.m_x - pixel_centroid.getCentroidX();
291 auto dy = pixel.m_y - pixel_centroid.getCentroidY();
293 auto dist = 0.5 * (shape_parameters.getEllipseCxx()*
dx*
dx +
294 shape_parameters.getEllipseCyy()*
dy*
dy + shape_parameters.getEllipseCxy()*
dx*
dy) /
297 if (dist < min_dist) {
299 closest_source_node = source_nodes[i];
302 cumulated_probability += dist < 70.0 ? amplitudes[i] * expf(-dist) : 0.0;
304 probabilities.
push_back(cumulated_probability);
308 if (probabilities.
back() > 1.0e-31) {
310 auto drand = double(probabilities.
back()) * double(
rand()) / RAND_MAX;
313 for (; i<probabilities.
size() && drand >= probabilities[i]; i++);
314 if (i < source_nodes.size()) {
315 source_nodes[i]->addPixel(pixel);
322 closest_source_node->addPixel(pixel);
327 int total_pixels = 0;
330 for (
auto source_node : source_nodes) {
332 for (
auto& pixel : source_node->getPixels()) {
333 image->setValue(pixel - offset, 0);
338 auto pixels = source_node->getPixels();
339 total_pixels += pixels.size();