void ColorDeconvolutionFilterPlugin::updateSettingsPanelFromFilter() { ColorDeconvolutionFilter<double>* filter = dynamic_cast<ColorDeconvolutionFilter<double>* >(_filter.get()); if (_settingsPanel && filter) { _mutex.lock(); QDoubleSpinBox* stain1R = _settingsPanel->findChild<QDoubleSpinBox*>("Stain1RSpinBox"); QDoubleSpinBox* stain1G = _settingsPanel->findChild<QDoubleSpinBox*>("Stain1GSpinBox"); QDoubleSpinBox* stain1B = _settingsPanel->findChild<QDoubleSpinBox*>("Stain1BSpinBox"); QDoubleSpinBox* stain2R = _settingsPanel->findChild<QDoubleSpinBox*>("Stain2RSpinBox"); QDoubleSpinBox* stain2G = _settingsPanel->findChild<QDoubleSpinBox*>("Stain2GSpinBox"); QDoubleSpinBox* stain2B = _settingsPanel->findChild<QDoubleSpinBox*>("Stain2BSpinBox"); QDoubleSpinBox* stain3R = _settingsPanel->findChild<QDoubleSpinBox*>("Stain3RSpinBox"); QDoubleSpinBox* stain3G = _settingsPanel->findChild<QDoubleSpinBox*>("Stain3GSpinBox"); QDoubleSpinBox* stain3B = _settingsPanel->findChild<QDoubleSpinBox*>("Stain3BSpinBox"); QDoubleSpinBox* rThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("RThreshold"); QDoubleSpinBox* gThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("GThreshold"); QDoubleSpinBox* bThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("BThreshold"); QDoubleSpinBox* globalThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("GlobalThreshold"); QComboBox* outputStain = _settingsPanel->findChild<QComboBox*>("OutputStainComboBox"); std::vector<std::vector<double> > stains = filter->getStain(); std::vector<double> rgbThresholds = filter->getRGBDensityThresholds(); double gbThreshold = filter->getGlobalDensityThreshold(); unsigned int outStain = filter->getOutputStain(); QList<QWidget*> boxes = _settingsPanel->findChildren<QWidget*>(); foreach(QWidget* sb, boxes) { sb->blockSignals(true); }
void ColorDeconvolutionFilterPlugin::revertStainToDefault() { if (_filter) { ColorDeconvolutionFilter<double>* filter = dynamic_cast<ColorDeconvolutionFilter<double>* >(_filter.get()); if (filter) { filter->revertToDefaultStain(); updateSettingsPanelFromFilter(); emit filterParametersChanged(); } } }
void ColorDeconvolutionFilterPlugin::filter(const Patch<double> &input, QVariant &output) { Patch<double>* outImg = new Patch<double>(); ColorDeconvolutionFilter<double>* filter = dynamic_cast<ColorDeconvolutionFilter<double>* >(_filter.get()); if (filter) { if (filter->filter(input, *outImg)) { output = QVariant::fromValue<Patch<double>*>(outImg); } else { delete outImg; } } }
void ColorDeconvolutionFilterPlugin::updateFilterFromSettingsPanel() { ColorDeconvolutionFilter<double>* filter = dynamic_cast<ColorDeconvolutionFilter<double>* >(_filter.get()); if (_settingsPanel && filter) { QDoubleSpinBox* stain1R = _settingsPanel->findChild<QDoubleSpinBox*>("Stain1RSpinBox"); QDoubleSpinBox* stain1G = _settingsPanel->findChild<QDoubleSpinBox*>("Stain1GSpinBox"); QDoubleSpinBox* stain1B = _settingsPanel->findChild<QDoubleSpinBox*>("Stain1BSpinBox"); QDoubleSpinBox* stain2R = _settingsPanel->findChild<QDoubleSpinBox*>("Stain2RSpinBox"); QDoubleSpinBox* stain2G = _settingsPanel->findChild<QDoubleSpinBox*>("Stain2GSpinBox"); QDoubleSpinBox* stain2B = _settingsPanel->findChild<QDoubleSpinBox*>("Stain2BSpinBox"); QDoubleSpinBox* stain3R = _settingsPanel->findChild<QDoubleSpinBox*>("Stain3RSpinBox"); QDoubleSpinBox* stain3G = _settingsPanel->findChild<QDoubleSpinBox*>("Stain3GSpinBox"); QDoubleSpinBox* stain3B = _settingsPanel->findChild<QDoubleSpinBox*>("Stain3BSpinBox"); QDoubleSpinBox* rThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("RThreshold"); QDoubleSpinBox* gThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("GThreshold"); QDoubleSpinBox* bThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("BThreshold"); QDoubleSpinBox* globalThreshold = _settingsPanel->findChild<QDoubleSpinBox*>("GlobalThreshold"); QComboBox* outputStain = _settingsPanel->findChild<QComboBox*>("OutputStainComboBox"); filter->setGlobalDensityThreshold(globalThreshold->value()); std::vector<double> rgbThresholds; rgbThresholds.push_back(rThreshold->value()); rgbThresholds.push_back(gThreshold->value()); rgbThresholds.push_back(bThreshold->value()); filter->setRGBDensityThresholds(rgbThresholds); std::vector<std::vector<double> > stains(3, std::vector<double>(3, 0)); stains[0][0] = stain1R->value(); stains[0][1] = stain1G->value(); stains[0][2] = stain1B->value(); stains[1][0] = stain2R->value(); stains[1][1] = stain2G->value(); stains[1][2] = stain2B->value(); stains[2][0] = stain3R->value(); stains[2][1] = stain3G->value(); stains[2][2] = stain3B->value(); filter->setStain(stains[0], stains[1], stains[2]); filter->setOutputStain(outputStain->currentIndex()); emit filterParametersChanged(); } }
int main(int argc, char *argv[]) { try { std::string inputPth; po::options_description desc("Options"); desc.add_options() ("help,h", "Displays this message") ; po::positional_options_description positionalOptions; positionalOptions.add("input", 1); po::options_description posDesc("Positional descriptions"); posDesc.add_options() ("input", po::value<std::string>(&inputPth)->required(), "Path to input") ; po::options_description descAndPos("All options"); descAndPos.add(desc).add(posDesc); po::variables_map vm; try { po::store(po::command_line_parser(argc, argv).options(descAndPos) .positional(positionalOptions).run(), vm); if (!vm.count("input")) { cout << "Camelyon v1.0" << endl; cout << "Usage: Camelyon.exe input [options]" << endl; } if (vm.count("help")) { std::cout << desc << std::endl; return 0; } po::notify(vm); } catch (boost::program_options::required_option& e) { std::cerr << "ERROR: " << e.what() << std::endl << std::endl; std::cerr << "Use -h or --help for usage information" << std::endl; return 1; } MultiResolutionImageReader reader; MultiResolutionImage* input = reader.open(inputPth); CmdLineProgressMonitor monitor; if (input) { // Assume input has a lvl 8 int lowResLvl = 8; vector<unsigned long long, allocator<unsigned long long>> lowResDim = input->getLevelDimensions(8); Patch<uchar> lowResPatch = input->getPatch<uchar>(0, 0, lowResDim[0], lowResDim[1], lowResLvl); Mat lowResMat = patchToMat(lowResPatch); cvtColor(lowResMat, lowResMat, COLOR_BGR2HSV); imshow("HSV", lowResMat); // Convert level 8 image to HSD color model ColorDeconvolutionFilter<uchar> *filter = new ColorDeconvolutionFilter<uchar>(); Patch<double> cxPatch, cyPatch, dPatch; filter->filter(lowResPatch, cxPatch); filter->setOutputStain(1); filter->filter(lowResPatch, cyPatch); filter->setOutputStain(2); filter->filter(lowResPatch, dPatch); Mat cX = patchToMat(cxPatch); Mat cY = patchToMat(cyPatch); Mat d = patchToMat(dPatch); // (temporary check) imshow("cX", cX); imshow("cY", cY); imshow("D", d); waitKey(0); // Assume 512 always fits integrally int tileWidth = 512; int tileHeight = 512; int lowResTileWidth = tileWidth / pow(2, lowResLvl); int lowResTileHeight = tileHeight / pow(2, lowResLvl); vector<unsigned long long, allocator<unsigned long long>> dim = input->getLevelDimensions(0); int numTilesX = dim[0] / tileWidth; int numTilesY = dim[1] / tileHeight; // Iterate over foreground tiles for (int y = 0; y < numTilesY; y++) { for (int x = 0; x < numTilesX; x++) { Rect r(x * lowResTileWidth, y * lowResTileHeight, lowResTileWidth, lowResTileHeight); if (isForeground(&d, r, 0.2, 0.1)) { // Get level 0 for tile Patch<uchar> p = input->getPatch<uchar>(x * tileWidth, y * tileHeight, tileWidth, tileHeight, 0); Mat m = patchToMat(p); // TODO Convert to HSD // Create histogram Mat rgbHist; int histSize = 256; int channels[] = { 0, 1, 2 }; float range[] = { 0, 256 }; const float* ranges[] = { range }; calcHist(&m, 1, channels, Mat(), rgbHist, 1, &histSize, ranges, true, false); cout << "Histo Created for (" << x << "," << y << ")\n"; // TODO Get avg, median, mode, min, max, variance, stddev, etc.. } } } delete filter; // TODO Output results to csv // TODO Train/Test model // TODO Evaluate results delete input; } else { std::cerr << "ERROR: Invalid input image" << std::endl; } } catch (std::exception& e) { std::cerr << "Unhandled exception: " << e.what() << ", application will now exit" << std::endl; return 2; } return 0; }