Skip to content

Commit b822a88

Browse files
authored
POL5788 fix FP bug observed on Centrin dataset (PolusAI#282)
1 parent 2adb2e4 commit b822a88

15 files changed

+93
-115
lines changed

src/nyx/environment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void Environment::show_cmdline_help()
194194
void Environment::show_summary(const std::string& head, const std::string& tail)
195195
{
196196
std::cout << head;
197-
std::cout << "Available memory: " << Nyxus::virguler(get_ram_limit()) << " bytes\n\n";
197+
std::cout << "Available memory: " << Nyxus::virguler_ulong(get_ram_limit()) << " bytes\n\n";
198198
std::cout << "Work plan:\n"
199199
<< "\tdimensionality: " << dim() << "\n"
200200
<< "\tlabels\t" << labels_dir << "\n"

src/nyx/gpucache.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ namespace NyxusGpu
493493
size_t amt = 0;
494494
OK(gpu_get_free_mem(amt));
495495

496-
VERBOSLVL1(std::cout << "GPU RAM amt = " << Nyxus::virguler(amt) << "\n");
496+
VERBOSLVL1(std::cout << "GPU RAM amt = " << Nyxus::virguler_ulong(amt) << "\n");
497497

498498
int n_gabFilters = n_gabor_filters + 1; // '+1': an extra filter for the baseline signal
499499

@@ -508,16 +508,16 @@ namespace NyxusGpu
508508
roi_kontur_cloud_len,
509509
n_rois, roi_w, roi_h, n_gabFilters, gabor_ker_side);
510510

511-
VERBOSLVL1(std::cout << "szb for " << Nyxus::virguler(n_rois) << " ROIs (ideal ROI px:" << Nyxus::virguler(roi_cloud_len) << ", ideal contour px:" << Nyxus::virguler(roi_kontur_cloud_len) << ") = " << Nyxus::virguler(szb) << "\n");
511+
VERBOSLVL1(std::cout << "szb for " << Nyxus::virguler_ulong(n_rois) << " ROIs (ideal ROI px:" << Nyxus::virguler_ulong(roi_cloud_len) << ", ideal contour px:" << Nyxus::virguler_ulong(roi_kontur_cloud_len) << ") = " << Nyxus::virguler_ulong(szb) << "\n");
512512

513513
batch_len = n_rois;
514514
size_t critAmt = amt * 0.75; // 75% GPU RAM as critical RAM
515515

516-
VERBOSLVL1(std::cout << "critical GPU RAM amt = " << Nyxus::virguler(critAmt) << "\n");
516+
VERBOSLVL1(std::cout << "critical GPU RAM amt = " << Nyxus::virguler_ulong(critAmt) << "\n");
517517

518518
if (critAmt < szb)
519519
{
520-
VERBOSLVL1(std::cout << "Need to split " << Nyxus::virguler(n_rois) << " ROIs into batches \n");
520+
VERBOSLVL1(std::cout << "Need to split " << Nyxus::virguler_ulong(n_rois) << " ROIs into batches \n");
521521

522522
size_t try_nrois = 0;
523523
for (try_nrois = n_rois; try_nrois>=0; try_nrois--)

src/nyx/grayscale_tiff.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#include "abs_tile_loader.h"
33

44
#ifdef __APPLE__
5-
#define uint64 uint64_hack_
6-
#define int64 int64_hack_
7-
#include <tiffio.h>
8-
#undef uint64
9-
#undef int64
5+
#define uint64 uint64_hack_
6+
#define int64 int64_hack_
7+
#include <tiffio.h>
8+
#undef uint64
9+
#undef int64
1010
#else
11-
#include <tiffio.h>
11+
#include <tiffio.h>
1212
#endif
1313
#include <cstring>
1414
#include <sstream>

src/nyx/helpers/helpers.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ namespace Nyxus
410410
return { smallest, largest };
411411
}
412412

413-
inline std::string virguler (size_t x)
413+
inline std::string virguler_ulong (size_t x)
414414
{
415415
const char SEP = ',';
416416

@@ -437,6 +437,23 @@ namespace Nyxus
437437
return s2;
438438
}
439439

440+
inline std::string virguler_real (double x)
441+
{
442+
// integer part
443+
size_t y = (size_t)x;
444+
445+
// fractional part ("123.4567" -> "4567")
446+
double f = x - (int)x;
447+
std::string s = x < 0.0 ? "-" : "";
448+
std::string frac = std::to_string(f);
449+
if (frac.length()>=1)
450+
frac = frac.erase(0, 1);
451+
452+
// all together
453+
s += virguler_ulong(y) + frac;
454+
return s;
455+
}
456+
440457
template <typename T>
441458
inline std::string virguler (const std::vector<T> & x)
442459
{

src/nyx/phase1.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -118,84 +118,6 @@ namespace Nyxus
118118
return true;
119119
}
120120

121-
//
122-
// whole-slide 2D case
123-
//
124-
bool gather_wholeslide_metrics (const std::string& intens_fpath, ImageLoader& L, LR & roi)
125-
{
126-
PixIntens minI = std::numeric_limits<PixIntens>::max(),
127-
maxI = std::numeric_limits<PixIntens>::min();
128-
AABB a;
129-
130-
int lvl = 0, // Pyramid level
131-
lyr = 0; // Layer
132-
133-
// Read the tiff. The image loader is put in the open state in processDataset()
134-
size_t nth = L.get_num_tiles_hor(),
135-
ntv = L.get_num_tiles_vert(),
136-
fw = L.get_tile_width(),
137-
th = L.get_tile_height(),
138-
tw = L.get_tile_width(),
139-
tileSize = L.get_tile_size(),
140-
fullwidth = L.get_full_width(),
141-
fullheight = L.get_full_height();
142-
143-
int cnt = 1;
144-
for (unsigned int row = 0; row < nth; row++)
145-
for (unsigned int col = 0; col < ntv; col++)
146-
{
147-
// Fetch the tile
148-
bool ok = L.load_tile(row, col);
149-
if (!ok)
150-
{
151-
std::string erm = "Error fetching tile row:" + std::to_string(row) + " col:" + std::to_string(col) + " from " + intens_fpath;
152-
#ifdef WITH_PYTHON_H
153-
throw erm;
154-
#endif
155-
std::cerr << erm << "\n";
156-
return false;
157-
}
158-
159-
// Get ahold of tile's pixel buffer
160-
const std::vector<uint32_t>& dataI = L.get_int_tile_buffer();
161-
162-
// Iterate pixels
163-
for (size_t i = 0; i < tileSize; i++)
164-
{
165-
int y = row * th + i / tw,
166-
x = col * tw + i % tw;
167-
168-
// Skip tile buffer pixels beyond the image's bounds
169-
if (x >= fullwidth || y >= fullheight)
170-
continue;
171-
172-
// Update whole slide's vROI metrics
173-
PixIntens I = dataI[i];
174-
minI = std::min (minI, I);
175-
maxI = std::max (maxI, I);
176-
}
177-
178-
#ifdef WITH_PYTHON_H
179-
if (PyErr_CheckSignals() != 0)
180-
throw pybind11::error_already_set();
181-
#endif
182-
183-
// Show progress info
184-
VERBOSLVL2(
185-
if (cnt++ % 4 == 0)
186-
std::cout << "\t" << int((row * nth + col) * 100 / float(nth * ntv) * 100) / 100. << "%\t" << uniqueLabels.size() << " ROIs" << "\n";
187-
);
188-
}
189-
190-
// Per-ROI
191-
roi.aux_area = fullwidth * fullheight;
192-
roi.aux_min = minI;
193-
roi.aux_max = maxI;
194-
roi.aabb.init_from_widthheight (fullwidth, fullheight);
195-
196-
return true;
197-
}
198-
199121
//
200122
// segmented 2.5D case (aka layoutA, collections of 2D slice images e.g. blah_z1_blah.ome.tif, blah_z2_blah.ome.tif, ..., blah_z500_blah.ome.tif)
201123
// prerequisite: 'theImLoader' needs to be pre-opened !

src/nyx/raw_format.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ class RawFormatLoader
88
public:
99

1010
RawFormatLoader (const std::string_view & name, const std::string & filePath)
11-
: infostring_(name), filePath_(filePath) {}
11+
: infostring_(name), filePath_(filePath), fp_pixels_(false) {}
1212

1313
virtual ~RawFormatLoader() = default;
1414

1515
std::string get_infostring() { return infostring_; }
1616

17+
bool get_fp_pixels() { return fp_pixels_; }
18+
1719
virtual void loadTileFromFile (
1820
size_t indexRowGlobalTile,
1921
size_t indexColGlobalTile,
@@ -62,6 +64,10 @@ class RawFormatLoader
6264
return (size_t)std::ceil((double)(fullDepth(level)) / tileDepth(level));
6365
}
6466

67+
protected:
68+
69+
bool fp_pixels_;
70+
6571
private:
6672

6773
std::string infostring_, filePath_;

src/nyx/raw_image_loader.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ size_t RawImageLoader::get_full_height()
259259

260260
std::string RawImageLoader::get_slide_descr()
261261
{
262-
std::string rv = intFL->get_infostring() + " (int) ";
262+
std::string rv = get_fp_phys_pixvoxels() ? "R-" : "N-";
263+
rv += intFL->get_infostring() + " I ";
263264
if (segFL != nullptr)
264-
rv += segFL->get_infostring() + " (seg) ";
265+
rv += segFL->get_infostring() + " M ";
265266
return rv;
266267
}
267268

269+
bool RawImageLoader::get_fp_phys_pixvoxels()
270+
{
271+
return intFL->get_fp_pixels();
272+
}
273+

src/nyx/raw_image_loader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class RawImageLoader
3131
size_t get_full_width();
3232
size_t get_full_height();
3333
std::string get_slide_descr();
34+
bool get_fp_phys_pixvoxels();
3435

3536
private:
3637

src/nyx/raw_omezarr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class RawOmezarrLoader: public RawFormatLoader
5050
else if (dtype_str == "<i2") { data_format_ = 6; } //int16_t
5151
else if (dtype_str == "<i4") { data_format_ = 7; } //int32_t
5252
else if (dtype_str == "<i8") { data_format_ = 8; } //int64_t
53-
else if (dtype_str == "<f2") { data_format_ = 9; } //float
54-
else if (dtype_str == "<f4") { data_format_ = 9; } //float
55-
else if (dtype_str == "<f8") { data_format_ = 10; } //double
53+
else if (dtype_str == "<f2") { data_format_ = 9; fp_pixels_ = true; } //float
54+
else if (dtype_str == "<f4") { data_format_ = 9; fp_pixels_ = true; } //float
55+
else if (dtype_str == "<f8") { data_format_ = 10; fp_pixels_ = true; } //double
5656
else { data_format_ = 2; } //uint16_t
5757

5858
// allocate the buffer

src/nyx/raw_tiff.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class RawTiffTileLoader : public RawFormatLoader
117117
}
118118
break;
119119
case 3:
120+
this->fp_pixels_ = true;
121+
120122
switch (bitsPerSample_)
121123
{
122124
case 8:
@@ -381,6 +383,8 @@ class RawTiffStripLoader : public RawFormatLoader
381383
}
382384
break;
383385
case 3:
386+
this->fp_pixels_ = true;
387+
384388
switch (bitsPerSample_)
385389
{
386390
case 8:

0 commit comments

Comments
 (0)