Skip to content

Commit

Permalink
Added missing test file
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Nov 21, 2024
1 parent a80543d commit fdfc96d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions source/FAST/Data/Tests/ImagePyramidTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <FAST/Testing.hpp>
#include <FAST/Data/ImagePyramid.hpp>
#include <FAST/Data/Image.hpp>
#include <FAST/Importers/WholeSlideImageImporter.hpp>
#include <FAST/Algorithms/ImageResizer/ImageResizer.hpp>

using namespace fast;

TEST_CASE("Convert image pyramid to JPEG XL compression", "[fast][ImagePyramid][JPEGXL]") {
auto importer = WholeSlideImageImporter::create(Config::getTestDataPath() + "/WSI/CMU-1.svs");
const int level = 2;
const int targetTileSize = 512;
auto imagePyramid = importer->runAndGetOutputData<ImagePyramid>();
int tilesX = std::ceil(imagePyramid->getLevelWidth(level) / targetTileSize);
int tilesY = std::ceil(imagePyramid->getLevelHeight(level) / targetTileSize);

auto newImagePyramid = ImagePyramid::create(tilesX*targetTileSize, tilesY*targetTileSize, 3, targetTileSize, targetTileSize, ImageCompression::JPEGXL);

auto accessRead = imagePyramid->getAccess(ACCESS_READ);
auto accessWrite = newImagePyramid->getAccess(ACCESS_READ_WRITE);

int counter = 0;
for(int newLevel = 0; newLevel < newImagePyramid->getNrOfLevels(); ++newLevel) {
tilesX = std::ceil(newImagePyramid->getLevelWidth(newLevel) / targetTileSize);
tilesY = std::ceil(newImagePyramid->getLevelHeight(newLevel) / targetTileSize);
int totalTiles = tilesX*tilesY;
for(int tileX = 0; tileX < tilesX; ++tileX) {
for(int tileY = 0; tileY < tilesY; ++tileY) {
try {
auto x = tileX*targetTileSize;
auto y = tileY*targetTileSize;
int pow = (int)std::pow(2, newLevel);
auto patch = accessRead->getPatchAsImage(level, x*pow, y*pow, targetTileSize*pow, targetTileSize*pow);
if(newLevel != 0)
patch = ImageResizer::create(targetTileSize, targetTileSize)->connect(patch)->runAndGetOutputData<Image>();

accessWrite->setPatch(newLevel, x, y, patch, false);
} catch(Exception &e) {
continue;
}
++counter;
std::cout << "Progress: " << counter << " of " << totalTiles << std::endl;

}
}
}
}
1 change: 1 addition & 0 deletions source/FAST/Importers/WholeSlideImageImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void WholeSlideImageImporter::execute() {
readWithTIFF(m_filename);
} catch(Exception &e) {
// Failed to open with FAST and TIFF, try with OpenSlide instead
reportInfo() << "Failed to open TIFF with FAST, trying OpenSlide instead. Error message: " << e.what() << reportEnd();
readWithOpenSlide(m_filename);
}
} else {
Expand Down

0 comments on commit fdfc96d

Please sign in to comment.