Skip to content

Commit 72325c2

Browse files
committed
Merge branch 'develop' into feature/dft_background
Pick changes from Martin for the BackgroundConvolution
2 parents 4b7918d + f3f4293 commit 72325c2

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

SEImplementation/SEImplementation/CheckImages/CheckImages.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class CheckImages : public Configurable {
7676
m_filtered_image = filtered_image;
7777
}
7878

79+
void setThresholdedCheckImage(std::shared_ptr<Image<SeFloat>> thresholded_image) {
80+
m_thresholded_image = thresholded_image;
81+
}
82+
7983
std::shared_ptr<WriteableImage<SeFloat>> getWriteableCheckImage(std::string id, int width, int height);
8084
void setCustomCheckImage(std::string id, std::shared_ptr<Image<SeFloat>> image);
8185

@@ -117,6 +121,7 @@ class CheckImages : public Configurable {
117121
std::shared_ptr<DetectionImage> m_detection_image;
118122
std::shared_ptr<Image<SeFloat>> m_background_image;
119123
std::shared_ptr<Image<SeFloat>> m_filtered_image;
124+
std::shared_ptr<Image<SeFloat>> m_thresholded_image;
120125
std::shared_ptr<WeightImage> m_variance_image;
121126
std::shared_ptr<CoordinateSystem> m_coordinate_system;
122127

@@ -128,6 +133,7 @@ class CheckImages : public Configurable {
128133
std::string m_partition_filename;
129134
std::string m_group_filename;
130135
std::string m_filtered_filename;
136+
std::string m_thresholded_filename;
131137
std::string m_auto_aperture_filename;
132138
std::string m_aperture_filename;
133139
std::string m_moffat_filename;

SEImplementation/SEImplementation/Configuration/CheckImagesConfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class CheckImagesConfig : public Euclid::Configuration::Configuration {
5757
return m_filtered_filename;
5858
}
5959

60+
const std::string& getThresholdedFilename() const {
61+
return m_thresholded_filename;
62+
}
63+
6064
const std::string& getAutoApertureFilename() const {
6165
return m_auto_aperture_filename;
6266
}
@@ -79,6 +83,7 @@ class CheckImagesConfig : public Euclid::Configuration::Configuration {
7983
std::string m_partition_filename;
8084
std::string m_group_filename;
8185
std::string m_filtered_filename;
86+
std::string m_thresholded_filename;
8287
std::string m_auto_aperture_filename;
8388
std::string m_aperture_filename;
8489
std::string m_moffat_filename;

SEImplementation/SEImplementation/Segmentation/BackgroundConvolution.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,32 @@ class BgConvolutionImageSource : public ProcessingImageSource<DetectionImage::Pi
4646
DetectionImage::PixelType conv_weight = 0;
4747
DetectionImage::PixelType conv_weight_ignoring_threshold = 0;
4848

49-
for (int cy = 0; cy < m_kernel->getHeight(); cy++) {
50-
for (int cx = 0; cx < m_kernel->getWidth(); cx++) {
49+
if (m_variance->getValue(ix, iy) < m_threshold) {
5150

52-
auto x2 = ix + cx - hx;
53-
auto y2 = iy + cy - hy;
51+
for (int cy = 0; cy < m_kernel->getHeight(); cy++) {
52+
for (int cx = 0; cx < m_kernel->getWidth(); cx++) {
5453

55-
if (x2 >= 0 && x2 < image->getWidth() && y2 >= 0 && y2 < image->getHeight()) {
56-
if (m_variance->getValue(x2, y2) < m_threshold) {
57-
total += image->getValue(x2, y2) * m_kernel->getValue(cx, cy);
58-
conv_weight += m_kernel->getValue(cx, cy);
54+
auto x2 = ix + cx - hx;
55+
auto y2 = iy + cy - hy;
56+
57+
if (x2 >= 0 && x2 < image->getWidth() && y2 >= 0 && y2 < image->getHeight()) {
58+
if (m_variance->getValue(x2, y2) < m_threshold) {
59+
total += image->getValue(x2, y2) * m_kernel->getValue(cx, cy);
60+
conv_weight += m_kernel->getValue(cx, cy);
61+
}
62+
total_ignoring_threshold += image->getValue(x2, y2) * m_kernel->getValue(cx, cy);
63+
conv_weight_ignoring_threshold += m_kernel->getValue(cx, cy);
64+
}
65+
if (conv_weight > 0) {
66+
tile.getImage()->setValue(ix - x, iy - y, total / conv_weight);
67+
} else {
68+
tile.getImage()->setValue(ix - x, iy - y, total_ignoring_threshold / conv_weight_ignoring_threshold);
5969
}
60-
total_ignoring_threshold += image->getValue(x2, y2) * m_kernel->getValue(cx, cy);
61-
conv_weight_ignoring_threshold += m_kernel->getValue(cx, cy);
6270
}
6371
}
6472
}
65-
if (conv_weight > 0) {
66-
tile.getImage()->setValue(ix - x, iy - y, total / conv_weight);
67-
} else {
68-
tile.getImage()->setValue(ix - x, iy - y, total_ignoring_threshold / conv_weight_ignoring_threshold);
73+
else {
74+
tile.getImage()->setValue(ix - x, iy - y, 0);
6975
}
7076
}
7177
}

SEImplementation/SEImplementation/Segmentation/Lutz.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef _SEIMPLEMENTATION_SEGMENTATION_LUTZ_H_
99
#define _SEIMPLEMENTATION_SEGMENTATION_LUTZ_H_
1010

11+
#include "ElementsKernel/Logging.h"
12+
1113
#include "SEFramework/Source/SourceFactory.h"
1214
#include "SEFramework/Task/TaskProvider.h"
1315
#include "SEFramework/Source/SourceWithOnDemandProperties.h"

SEImplementation/src/lib/CheckImages/CheckImages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void CheckImages::configure(Euclid::Configuration::ConfigManager& manager) {
5555
m_partition_filename = config.getPartitionFilename();
5656
m_group_filename = config.getGroupFilename();
5757
m_filtered_filename = config.getFilteredFilename();
58+
m_thresholded_filename = config.getThresholdedFilename();
5859
m_auto_aperture_filename = config.getAutoApertureFilename();
5960
m_aperture_filename = config.getApertureFilename();
6061
m_moffat_filename = config.getMoffatFilename();
@@ -169,6 +170,11 @@ void CheckImages::saveImages() {
169170
FitsWriter::writeFile(*m_filtered_image, m_filtered_filename, m_coordinate_system);
170171
}
171172

173+
// if possible, save the thresholded image
174+
if (m_thresholded_image != nullptr && m_thresholded_filename != "") {
175+
FitsWriter::writeFile(*m_thresholded_image, m_thresholded_filename, m_coordinate_system);
176+
}
177+
172178
// if possible, create and save the residual image
173179
if (m_check_image_model_fitting != nullptr && m_residual_filename != "") {
174180
auto residual_image = SubtractImage<SeFloat>::create(m_detection_image, m_check_image_model_fitting);

SEImplementation/src/lib/Configuration/CheckImagesConfig.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static const std::string CHECK_SEGMENTATION { "check-image-segmentation" };
2424
static const std::string CHECK_PARTITION { "check-image-partition" };
2525
static const std::string CHECK_GROUPING { "check-image-grouping" };
2626
static const std::string CHECK_FILTERED { "check-image-filtered" };
27+
static const std::string CHECK_THRESHOLDED { "check-image-thresholded" };
2728
static const std::string CHECK_AUTO_APERTURE { "check-image-auto-aperture" };
2829
static const std::string CHECK_APERTURE { "check-image-aperture" };
2930
static const std::string CHECK_MOFFAT { "check-image-moffat" };
@@ -49,6 +50,8 @@ std::map<std::string, Configuration::OptionDescriptionList> CheckImagesConfig::g
4950
"Path to save the grouping check image"},
5051
{CHECK_FILTERED.c_str(), po::value<std::string>()->default_value(""),
5152
"Path to save the filtered check image"},
53+
{CHECK_THRESHOLDED.c_str(), po::value<std::string>()->default_value(""),
54+
"Path to save the thresholded check image"},
5255
{CHECK_AUTO_APERTURE.c_str(), po::value<std::string>()->default_value(""),
5356
"Path to save the auto aperture check image"},
5457
{CHECK_APERTURE.c_str(), po::value<std::string>()->default_value(""),
@@ -67,6 +70,7 @@ void CheckImagesConfig::initialize(const UserValues& args) {
6770
m_partition_filename = args.find(CHECK_PARTITION)->second.as<std::string>();
6871
m_group_filename = args.find(CHECK_GROUPING)->second.as<std::string>();
6972
m_filtered_filename = args.find(CHECK_FILTERED)->second.as<std::string>();
73+
m_thresholded_filename = args.find(CHECK_THRESHOLDED)->second.as<std::string>();
7074
m_auto_aperture_filename = args.find(CHECK_AUTO_APERTURE)->second.as<std::string>();
7175
m_aperture_filename = args.find(CHECK_APERTURE)->second.as<std::string>();
7276
m_moffat_filename = args.find(CHECK_MOFFAT)->second.as<std::string>();

SEMain/src/program/SExtractor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class SEMain : public Elements::Program {
311311
<< " RMS: " << sqrt(detection_frame->getVarianceMap()->getValue(0,0))
312312
<< " threshold: " << detection_frame->getDetectionThreshold();
313313

314-
CheckImages::getInstance().setFilteredCheckImage(detection_frame->getFilteredImage());
314+
//CheckImages::getInstance().setFilteredCheckImage(detection_frame->getFilteredImage());
315315

316316
// Perform measurements (multi-threaded part)
317317
measurement->startThreads();
@@ -326,6 +326,7 @@ class SEMain : public Elements::Program {
326326
measurement->waitForThreads();
327327

328328
CheckImages::getInstance().setFilteredCheckImage(detection_frame->getFilteredImage());
329+
CheckImages::getInstance().setThresholdedCheckImage(detection_frame->getThresholdedImage());
329330
CheckImages::getInstance().saveImages();
330331
TileManager::getInstance()->flush();
331332
size_t n_writen_rows = output->flush();

0 commit comments

Comments
 (0)