133 auto parent_source_id = original_source->getProperty<
SourceId>().getSourceId();
135 auto& detection_frame = original_source->getProperty<
DetectionFrame>();
138 const auto labelling_image = detection_frame_images.getLockedImage(
LayerFilteredImage);
140 auto& pixel_boundaries = original_source->getProperty<
PixelBoundaries>();
142 auto& pixel_coords = original_source->getProperty<
PixelCoordinateList>().getCoordinateList();
144 auto offset = pixel_boundaries.getMin();
146 pixel_boundaries.getWidth(), pixel_boundaries.getHeight());
147 thumbnail_image->fillValue(0);
149 auto min_value = original_source->getProperty<
PeakValue>().getMinValue() * .8;
150 auto peak_value = original_source->getProperty<
PeakValue>().getMaxValue();
152 for (
auto pixel_coord : pixel_coords) {
153 auto value = labelling_image->getValue(pixel_coord);
154 thumbnail_image->setValue(pixel_coord - offset, value);
165 auto threshold = min_value *
pow(peak_value / min_value, (
double) i /
m_thresholds_nb);
172 for (
auto& node : active_nodes_copy) {
173 int nb_of_groups_inside = 0;
174 for (
auto& pixel_group : lutz.
getGroups()) {
175 if (pixel_group.pixel_list.size() >=
m_min_deblend_area && node->contains(pixel_group)) {
176 nb_of_groups_inside++;
180 if (nb_of_groups_inside == 0) {
181 active_nodes.
remove(node);
184 if (nb_of_groups_inside > 1) {
185 active_nodes.
remove(node);
187 for (
auto& pixel_group : lutz.
getGroups()) {
188 if (pixel_group.pixel_list.size() >=
m_min_deblend_area && node->contains(pixel_group)) {
190 node->addChild(new_node);
199 double intensity_threshold = root->getTotalIntensity(*thumbnail_image, offset) *
m_contrast;
202 while (!junction_nodes.
empty()) {
203 auto node = junction_nodes.
back();
206 int nb_of_children_above_threshold = 0;
208 for (
auto child : node->getChildren()) {
209 if (child->getTotalIntensity(*thumbnail_image, offset) > intensity_threshold) {
210 nb_of_children_above_threshold++;
214 if (nb_of_children_above_threshold >= 2) {
216 for (
auto child : node->getChildren()) {
217 if (child->getTotalIntensity(*thumbnail_image, offset) > intensity_threshold && !child->isSplit()) {
225 if (source_nodes.
empty()) {
230 for (
auto source_node : source_nodes) {
232 for (
auto& pixel : source_node->getPixels()) {
233 thumbnail_image->setValue(pixel - offset, 0);
239 new_source->setProperty<
DetectionFrame>(detection_frame.getEncapsulatedFrame());
244 auto new_sources =
reassignPixels(sources, pixel_coords, thumbnail_image, source_nodes, offset);
246 for (
auto& new_source : new_sources) {
247 new_source->setProperty<
DetectionFrame>(detection_frame.getEncapsulatedFrame());
248 new_source->setProperty<
SourceId>(parent_source_id);
263 for (
auto& source : sources) {
267 auto thresh = source->getProperty<
PeakValue>().getMinValue();
268 auto peak = source->getProperty<
PeakValue>().getMaxValue();
270 auto dist = pixel_list.size() / (2.0 * M_PI * shape_parameters.getAbcor() * shape_parameters.getEllipseA() * shape_parameters.getEllipseB());
271 auto amp = dist < 70.0 ? thresh * expf(dist) : 4.0 * peak;
274 if (amp > 4.0 * peak) {
281 for (
auto pixel : pixel_coords) {
282 if (image->getValue(pixel - offset) > 0) {
283 SeFloat cumulated_probability = 0;
290 for (
auto& source : sources) {
294 auto dx = pixel.m_x - pixel_centroid.getCentroidX();
295 auto dy = pixel.m_y - pixel_centroid.getCentroidY();
297 auto dist = 0.5 * (shape_parameters.getEllipseCxx()*dx*dx +
298 shape_parameters.getEllipseCyy()*dy*dy + shape_parameters.getEllipseCxy()*dx*dy) /
301 if (dist < min_dist) {
303 closest_source_node = source_nodes[i];
306 cumulated_probability += dist < 70.0 ? amplitudes[i] * expf(-dist) : 0.0;
308 probabilities.
push_back(cumulated_probability);
312 if (probabilities.
back() > 1.0e-31) {
313 auto drand = double(probabilities.
back()) * boost::random::uniform_01<double>()
317 for (; i<probabilities.
size() && drand >= probabilities[i]; i++);
318 if (i < source_nodes.size()) {
319 source_nodes[i]->addPixel(pixel);
326 closest_source_node->addPixel(pixel);
331 int total_pixels = 0;
334 for (
auto source_node : source_nodes) {
336 for (
auto& pixel : source_node->getPixels()) {
337 image->setValue(pixel - offset, 0);
342 auto pixels = source_node->getPixels();
343 total_pixels += pixels.size();