@@ -96,66 +96,59 @@ namespace WSICS::Normalization
96
96
parameters.eosin_percentile ,
97
97
spacing,
98
98
is_multiresolution_image));
99
- HE_Staining::HE_Classifier he_classifier;
100
99
101
- if (he_masks.first .full_mask .size () == cv::Size (0 , 0 ))
100
+ if (he_masks.first .full_mask .size () != cv::Size (0 , 0 ) &&
101
+ he_masks.second .full_mask .size () != cv::Size (0 , 0 ))
102
102
{
103
- throw std::runtime_error (" Unable to create Hematoxylin mask" );
104
- }
105
- else if (he_masks.second .full_mask .size () == cv::Size (0 , 0 ))
106
- {
107
- throw std::runtime_error (" Unable to create Eosin mask" );
108
- }
109
-
110
- HE_Staining::ClassificationResults classification_results;
111
- try
112
- {
113
- classification_results = he_classifier.Classify (hsd_image, background_mask, he_masks.first , he_masks.second );
114
- }
115
- catch (const std::exception & e)
116
- {
117
- throw std::runtime_error (" Unable to classify HE stained tissue." );
118
- }
119
-
120
- // Wanna keep?
121
- // Randomly pick samples and Fill in Cx-Cy-D major sample vectors
122
- if (classification_results.train_and_class_data .train_data .rows >= min_training_size)
123
- {
124
- if (logging_instance->GetOutputLevel () == IO::Logging::DEBUG && !m_debug_dir_.empty ())
103
+ HE_Staining::HE_Classifier he_classifier;
104
+ HE_Staining::ClassificationResults classification_results;
105
+ try
125
106
{
126
- cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (random_numbers[current_tile]) + " _classified.tif" , classification_results.all_classes * 100 );
127
-
128
- std::vector<cv::Mat> channels;
129
- channels.push_back (he_masks.second .full_mask );
130
- channels.push_back (background_mask);
131
- channels.push_back (he_masks.first .full_mask );
132
-
133
- cv::Mat classes;
134
- cv::merge (channels, classes);
135
- classes.convertTo (classes, CV_8UC1);
136
- cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (random_numbers[current_tile]) + " _classes.tif" , classes * 100 );
107
+ classification_results = he_classifier.Classify (hsd_image, background_mask, he_masks.first , he_masks.second );
108
+ }
109
+ catch (const std::exception & e)
110
+ {
111
+ throw std::runtime_error (" Unable to classify HE stained tissue." );
137
112
}
138
113
114
+ // Wanna keep?
115
+ // Randomly pick samples and Fill in Cx-Cy-D major sample vectors
116
+ if (classification_results.train_and_class_data .train_data .rows >= min_training_size)
117
+ {
118
+ if (logging_instance->GetOutputLevel () == IO::Logging::DEBUG && !m_debug_dir_.empty ())
119
+ {
120
+ cv::Mat classifications_scaled (classification_results.all_classes * 100 );
121
+ cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (random_numbers[current_tile]) + " _classified.tif" , classifications_scaled);
122
+
123
+ std::vector<cv::Mat> channels;
124
+ channels.push_back (he_masks.second .full_mask );
125
+ channels.push_back (background_mask);
126
+ channels.push_back (he_masks.first .full_mask );
127
+
128
+ cv::Mat classes;
129
+ cv::merge (channels, classes);
130
+ classes.convertTo (classes, CV_8UC1);
131
+ classes *= 100 ;
132
+ cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (random_numbers[current_tile]) + " _classes.tif" , classes);
133
+ }
134
+
135
+ InsertTrainingData_ (hsd_image, classification_results, sample_information, total_hema_count, total_eosin_count, total_background_count, parameters.max_training_size );
136
+ ++selected_images_count;
137
+
138
+ size_t hema_count_real = total_hema_count > parameters.max_training_size * 9 / 20 ? hema_count_real = parameters.max_training_size * 9 / 20 : total_hema_count;
139
+ size_t eosin_count_real = total_eosin_count > parameters.max_training_size * 9 / 20 ? eosin_count_real = parameters.max_training_size * 9 / 20 : total_eosin_count;
140
+ size_t background_count_real = total_background_count > parameters.max_training_size * 1 / 10 ? background_count_real = parameters.max_training_size * 1 / 10 : total_background_count;
141
+
142
+ logging_instance->QueueCommandLineLogging (std::to_string (hema_count_real + eosin_count_real + background_count_real) + " training samples are filled, out of " + std::to_string (parameters.max_training_size ) + " required." , IO::Logging::NORMAL);
143
+ logging_instance->QueueFileLogging (" Filled: " + std::to_string (hema_count_real + eosin_count_real + background_count_real) + " / " + std::to_string (parameters.max_training_size ), m_log_file_id_, IO::Logging::NORMAL);
144
+ logging_instance->QueueFileLogging (" Hema: " + std::to_string (hema_count_real) + " , Eos: " + std::to_string (eosin_count_real) + " , BG: " + std::to_string (background_count_real), m_log_file_id_, IO::Logging::NORMAL);
145
+ }
139
146
140
- // TrainingSampleInformation& sample_information, const cv::Mat& cx_cy, const cv::Mat& density, const std::vector<cv::Point>& data_pixels, const size_t insertion_start, const size_t pixels_to_insert, const uint8_t class_id
141
-
142
-
143
- InsertTrainingData_ (hsd_image, classification_results, sample_information, total_hema_count, total_eosin_count, total_background_count, parameters.max_training_size );
144
- ++selected_images_count;
145
-
146
- size_t hema_count_real = total_hema_count > parameters.max_training_size * 9 / 20 ? hema_count_real = parameters.max_training_size * 9 / 20 : total_hema_count;
147
- size_t eosin_count_real = total_eosin_count > parameters.max_training_size * 9 / 20 ? eosin_count_real = parameters.max_training_size * 9 / 20 : total_eosin_count;
148
- size_t background_count_real = total_background_count > parameters.max_training_size * 1 / 10 ? background_count_real = parameters.max_training_size * 1 / 10 : total_background_count;
149
-
150
- logging_instance->QueueCommandLineLogging (std::to_string (hema_count_real + eosin_count_real + background_count_real) + " training sets are filled, out of " + std::to_string (parameters.max_training_size ) + " required." , IO::Logging::NORMAL);
151
- logging_instance->QueueFileLogging (" Filled: " + std::to_string (hema_count_real + eosin_count_real + background_count_real) + " / " + std::to_string (parameters.max_training_size ), m_log_file_id_, IO::Logging::NORMAL);
152
- logging_instance->QueueFileLogging (" Hema: " + std::to_string (hema_count_real) + " , Eos: " + std::to_string (eosin_count_real) + " , BG: " + std::to_string (background_count_real), m_log_file_id_, IO::Logging::NORMAL);
153
- }
154
-
155
- if (total_hema_count >= parameters.max_training_size * 9 / 20 && total_eosin_count >= parameters.max_training_size * 9 / 20 && total_background_count >= parameters.max_training_size / 10 )
156
- {
157
- break ;
158
- }
147
+ if (total_hema_count >= parameters.max_training_size * 9 / 20 && total_eosin_count >= parameters.max_training_size * 9 / 20 && total_background_count >= parameters.max_training_size / 10 )
148
+ {
149
+ break ;
150
+ }
151
+ }
159
152
}
160
153
161
154
if ((total_hema_count < parameters.max_training_size * 9 / 20 || total_eosin_count < parameters.max_training_size * 9 / 20 || total_background_count < parameters.max_training_size / 10 ))
@@ -193,9 +186,9 @@ namespace WSICS::Normalization
193
186
parameters.epoch_size = 3 ;
194
187
parameters.count_threshold = 4 ;
195
188
196
- int sigma = 4 ;
197
- int low_threshold = 45 ;
198
- int high_threshold = 80 ;
189
+ int sigma = 4 ;
190
+ int low_threshold = 45 ;
191
+ int high_threshold = 80 ;
199
192
200
193
// Prepares the logger and a string holding potential failure messages.
201
194
IO::Logging::LogHandler* logging_instance (IO::Logging::LogHandler::GetInstance ());
@@ -205,11 +198,13 @@ namespace WSICS::Normalization
205
198
{
206
199
cv::Mat temporary_matrix;
207
200
hsd_image.density .convertTo (temporary_matrix, CV_8UC1);
208
- cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (tile_id) + " _density.tif" , temporary_matrix * 100 );
201
+ temporary_matrix *= 100 ;
202
+ cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (tile_id) + " _density.tif" , temporary_matrix);
209
203
210
204
HE_Staining::MaskGeneration::ApplyBlur (temporary_matrix, temporary_matrix, sigma);
211
205
HE_Staining::MaskGeneration::ApplyCannyEdge (temporary_matrix, temporary_matrix, low_threshold, high_threshold);
212
- cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (tile_id) + " _binary.tif" , temporary_matrix * 255 );
206
+ temporary_matrix *= 255 ;
207
+ cv::imwrite (m_debug_dir_ + " /tile_" + std::to_string (tile_id) + " _binary.tif" , temporary_matrix);
213
208
}
214
209
215
210
// Attempts to detect ellispes. Applies a blur and canny edge operation on the density matrix before detecting ellipses through a randomized Hough transform.
@@ -220,7 +215,7 @@ namespace WSICS::Normalization
220
215
std::pair<HE_Staining::HematoxylinMaskInformation, HE_Staining::EosinMaskInformation> mask_acquisition_results;
221
216
222
217
// If the min_ellipses variable has been set as positive, prefer it over a calculation.
223
- double min_detected_ellipses = min_ellipses > 0 ? hsd_image.red_density .rows * hsd_image.red_density .rows * spacing[0 ] * spacing[0 ] * (150 / 247700.0 ) : min_ellipses;
218
+ double min_detected_ellipses = min_ellipses == 0 ? hsd_image.red_density .rows * hsd_image.red_density .rows * spacing[0 ] * spacing[0 ] * (150 / 247700.0 ) : min_ellipses;
224
219
if (detected_ellipses.size () > min_detected_ellipses || (detected_ellipses.size () > 10 && !is_multiresolution))
225
220
{
226
221
logging_instance->QueueFileLogging (" Passed step 1: Number of nuclei " + std::to_string (detected_ellipses.size ()), m_log_file_id_, IO::Logging::NORMAL);
0 commit comments