| 54 | } |
| 55 | |
| 56 | bool 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 | } |
nothing calls this directly
no test coverage detected