MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / process

Method process

imgproc/wholeslide/ArithmeticWholeSlideFilter.cpp:56–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56bool ArithmeticWholeSlideFilter::process() {
57 std::shared_ptr<MultiResolutionImage> img = _input.lock();
58 std::vector<unsigned long long> dims = img->getLevelDimensions(this->_processedLevel);
59 double downsample = img->getLevelDownsample(this->_processedLevel);
60
61 MultiResolutionImageWriter writer;
62 writer.setColorType(pathology::ColorType::Monochrome);
63 writer.setCompression(pathology::Compression::LZW);
64 writer.setDataType(pathology::DataType::UInt32);
65 writer.setInterpolation(pathology::Interpolation::NearestNeighbor);
66 writer.setTileSize(512);
67 std::vector<double> spacing = img->getSpacing();
68 if (!spacing.empty()) {
69 spacing[0] *= downsample;
70 spacing[1] *= downsample;
71 writer.setSpacing(spacing);
72 }
73 if (writer.openFile(_outPath) != 0) {
74 std::cerr << "ERROR: Could not open file for writing" << std::endl;
75 return false;
76 }
77 writer.setProgressMonitor(_monitor);
78 writer.writeImageInformation(dims[0], dims[1]);
79
80 std::vector<unsigned char> labels;
81 std::vector<std::string> stringLabels = core::split(_expression, ",");
82 labels.resize(core::fromstring<unsigned int>(stringLabels.back()), 0);
83 for (unsigned int i = 0; i < stringLabels.size() - 1; ++i) {
84 labels[core::fromstring<unsigned int>(stringLabels[i])] = 1;
85 }
86 unsigned int* tile = new unsigned int[512 * 512];
87 unsigned int* out_tile = new unsigned int[512 * 512];
88 for (unsigned long long t_y = 0; t_y < dims[1]; t_y += 512) {
89 for (unsigned long long t_x = 0; t_x < dims[0]; t_x += 512) {
90 img->getRawRegion<unsigned int>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
91 for (unsigned int y = 0; y < 512; ++y) {
92 for (unsigned int x = 0; x < 512; ++x) {
93 float curVal = tile[y * 512 + x];
94 if (curVal > 0 && labels[curVal]==0) {
95 out_tile[y * 512 + x] = curVal;
96 }
97 else {
98 out_tile[y * 512 + x] = 0;
99 }
100 }
101 }
102 writer.writeBaseImagePart(reinterpret_cast<void*>(out_tile));
103 }
104 }
105 writer.finishImage();
106
107 delete[] tile;
108 delete[] out_tile;
109 return true;
110}

Callers

nothing calls this directly

Calls 12

splitFunction · 0.85
getLevelDimensionsMethod · 0.80
getLevelDownsampleMethod · 0.80
getSpacingMethod · 0.80
emptyMethod · 0.80
writeImageInformationMethod · 0.80
sizeMethod · 0.80
writeBaseImagePartMethod · 0.80
setSpacingMethod · 0.45
openFileMethod · 0.45
setProgressMonitorMethod · 0.45
finishImageMethod · 0.45

Tested by

no test coverage detected