Skip to content

Commit

Permalink
Implemented support for using TissueSegmentation on Image #199
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Dec 12, 2023
1 parent cf3c2db commit ca375a6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
41 changes: 31 additions & 10 deletions source/FAST/Algorithms/TissueSegmentation/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,42 @@
using namespace fast;

TEST_CASE("Tissue segmentation", "[fast][wsi][TissueSegmentation][visual]") {
auto importer = WholeSlideImageImporter::New();
importer->setFilename(Config::getTestDataPath() + "/WSI/CMU-1.svs");
auto importer = WholeSlideImageImporter::create(Config::getTestDataPath() + "/WSI/CMU-1.svs");

auto segmentation = TissueSegmentation::New();
segmentation->setInputConnection(importer->getOutputPort());
auto segmentation = TissueSegmentation::create()
->connect(importer);

auto renderer = ImagePyramidRenderer::New();
renderer->addInputConnection(importer->getOutputPort());
auto renderer = ImagePyramidRenderer::create()
->connect(importer);

auto segRenderer = SegmentationRenderer::New();
segRenderer->addInputConnection(segmentation->getOutputPort());
auto segRenderer = SegmentationRenderer::create()
->connect(segmentation);
segRenderer->setOpacity(0.5);

auto window = SimpleWindow::New();
window->set2DMode();
auto window = SimpleWindow2D::create();
window->addRenderer(renderer);
window->addRenderer(segRenderer);
window->setTimeout(2000);
window->start();
}

TEST_CASE("Tissue segmentation on image", "[fast][wsi][TissueSegmentation][visual]") {
auto importer = WholeSlideImageImporter::create(Config::getTestDataPath() + "/WSI/CMU-1.svs");

auto access = importer->runAndGetOutputData<ImagePyramid>()->getAccess(ACCESS_READ);
auto image = access->getLevelAsImage(2);

auto segmentation = TissueSegmentation::create()
->connect(image);

auto renderer = ImagePyramidRenderer::create()
->connect(importer);

auto segRenderer = SegmentationRenderer::create()
->connect(segmentation);
segRenderer->setOpacity(0.5);

auto window = SimpleWindow2D::create();
window->addRenderer(renderer);
window->addRenderer(segRenderer);
window->setTimeout(2000);
Expand Down
14 changes: 11 additions & 3 deletions source/FAST/Algorithms/TissueSegmentation/TissueSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ bool TissueSegmentation::getFilterZeros() const {
}

void TissueSegmentation::execute() {
auto wsi = getInputData<ImagePyramid>();
auto access = wsi->getAccess(ACCESS_READ);
auto input = access->getLevelAsImage(wsi->getNrOfLevels()-1);
auto image = getInputData<SpatialDataObject>();

Image::pointer input;
if(auto wsi = std::dynamic_pointer_cast<ImagePyramid>(image)) {
auto access = wsi->getAccess(ACCESS_READ);
input = access->getLevelAsImage(wsi->getNrOfLevels()-1);
} else if(auto patch = std::dynamic_pointer_cast<Image>(image)) {
input = patch;
} else {
throw Exception("TissueSegmentation requires an Image or ImagePyramid data object.");
}

auto output = Image::createSegmentationFromImage(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace fast {
* @brief Segment tissue from a WSI
*
* Uses the GPU to perform a simple threshold-based tissue/glass segmentation of a WSI.
* Since glass is almost white, the thresold is the distance from the pixels color
* Since glass is almost white, the threshold is the distance from the pixels color
* to white (255,255,255).
* A morphological closing (dilation+erosion) is performed after thresholding.
*
* Inputs:
* - 0: ImagePyramid WSI
* - 0: ImagePyramid WSI or Image patch
*
* Outputs:
* - 0: Segmentation tissue mask
Expand Down

0 comments on commit ca375a6

Please sign in to comment.