78 return total_intensity;
88 if (parent !=
nullptr) {
89 parent->flagAsSplit();
130 auto parent_source_id = original_source->getProperty<
SourceId>().getSourceId();
132 auto& detection_frame = original_source->getProperty<
DetectionFrame>();
135 const auto labelling_image = detection_frame_images.getLockedImage(
LayerFilteredImage);
137 auto& pixel_boundaries = original_source->getProperty<
PixelBoundaries>();
139 auto& pixel_coords = original_source->getProperty<
PixelCoordinateList>().getCoordinateList();
141 auto offset = pixel_boundaries.getMin();
143 pixel_boundaries.getWidth(), pixel_boundaries.getHeight());
144 thumbnail_image->fillValue(0);
146 auto min_value = original_source->getProperty<
PeakValue>().getMinValue() * .8;
147 auto peak_value = original_source->getProperty<
PeakValue>().getMaxValue();
151 for (
auto pixel_coord : pixel_coords) {
152 auto value = labelling_image->getValue(pixel_coord);
153 thumbnail_image->setValue(pixel_coord - offset, value);
157 auto root = std::make_shared<MultiThresholdNode>(pixel_coords, 0);
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)) {
189 auto new_node = std::make_shared<MultiThresholdNode>(pixel_group.pixel_list, threshold);
190 node->addChild(new_node);
191 active_nodes.push_back(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()) {
226 return { original_source };
229 for (
auto source_node : source_nodes) {
231 for (
auto& pixel : source_node->getPixels()) {
232 thumbnail_image->setValue(pixel - offset, 0);
238 new_source->setProperty<
DetectionFrame>(detection_frame.getEncapsulatedFrame());
243 auto new_sources =
reassignPixels(sources, pixel_coords, thumbnail_image, source_nodes, offset);
245 for (
auto& new_source : new_sources) {
246 new_source->setProperty<
DetectionFrame>(detection_frame.getEncapsulatedFrame());
247 new_source->setProperty<
SourceId>(parent_source_id);
262 for (
auto& source : sources) {
266 auto thresh = source->getProperty<
PeakValue>().getMinValue();
267 auto peak = source->getProperty<
PeakValue>().getMaxValue();
269 auto dist = pixel_list.size() / (2.0 * M_PI * shape_parameters.getAbcor() * shape_parameters.getEllipseA() * shape_parameters.getEllipseB());
270 auto amp = dist < 70.0 ? thresh * expf(dist) : 4.0 * peak;
273 if (amp > 4.0 * peak) {
280 for (
auto pixel : pixel_coords) {
281 if (image->getValue(pixel - offset) > 0) {
282 SeFloat cumulated_probability = 0;
289 for (
auto& source : sources) {
293 auto dx = pixel.m_x - pixel_centroid.getCentroidX();
294 auto dy = pixel.m_y - pixel_centroid.getCentroidY();
296 auto dist = 0.5 * (shape_parameters.getEllipseCxx()*
dx*
dx +
297 shape_parameters.getEllipseCyy()*
dy*
dy + shape_parameters.getEllipseCxy()*
dx*
dy) /
300 if (dist < min_dist) {
302 closest_source_node = source_nodes[i];
305 cumulated_probability += dist < 70.0 ? amplitudes[i] * expf(-dist) : 0.0;
307 probabilities.
push_back(cumulated_probability);
311 if (probabilities.
back() > 1.0e-31) {
313 auto drand = double(probabilities.
back()) *
double(
rand()) / RAND_MAX;
316 for (; i<probabilities.
size() && drand >= probabilities[i]; i++);
317 if (i < source_nodes.size()) {
318 source_nodes[i]->addPixel(pixel);
325 closest_source_node->addPixel(pixel);
330 int total_pixels = 0;
333 for (
auto source_node : source_nodes) {
335 for (
auto& pixel : source_node->getPixels()) {
336 image->setValue(pixel - offset, 0);
341 auto pixels = source_node->getPixels();
342 total_pixels += pixels.size();
T shared_from_this(T... args)
std::shared_ptr< EngineParameter > dx
std::shared_ptr< EngineParameter > dy