Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PPM) Use custom TIFF reader for loading cell map #60

Merged
merged 7 commits into from
Nov 14, 2023
Merged

Conversation

csparker247
Copy link
Member

@csparker247 csparker247 commented Nov 13, 2023

This overhauls TIFFIO.hpp to fix some bugs and add new features:

  • Added tiffio::ReadTIFF which can read single image, 8, 16, and 32bpc TIFF files with various pixel types.
  • Added TIFFIO unit tests
  • tiffio::WriteTIFF automatically write TIFFs > 4GB as BigTIFF.
  • tiffio::WriteTIFF better handles obscure, unsupported color conversions (e.g. CV_8SC3 and CV_8SC4 are not supported by cv::cvtColor)
  • (PerPixelMap) Use tiffio::ReadTIFF for loading the cell map (fixes [Bug] PPM error when loading cell map > 1GB #42)
  • (PerPixelMap) Better error handling for mask and cell map loading
  • (PPM Tests) Test mask and cell map serialization

core/src/TIFFIO.cpp Outdated Show resolved Hide resolved
core/src/TIFFIO.cpp Outdated Show resolved Hide resolved
@csparker247 csparker247 marked this pull request as ready for review November 14, 2023 19:39
@csparker247
Copy link
Member Author

For posterity, here's the code I used to test BigTIFF support. It's not a unit test because I don't want to write 4GB files in the unit tests:

#include <limits>
#include <random>
#include <iostream>

#include "vc/core/io/TIFFIO.hpp"
#include "vc/core/io/ImageIO.hpp"

using namespace volcart;

auto main() -> int
{
    using ElemT = std::uint16_t;
    auto low = std::numeric_limits<ElemT>::min();
    auto high = std::numeric_limits<ElemT>::max();
    static std::uniform_int_distribution<ElemT> dist(low, high);
    static std::default_random_engine gen;

    std::cout << "Creating big random image...\n";
    cv::Mat bigImg(50000, 50000, CV_16UC1);
    std::generate(bigImg.begin<ElemT>(), bigImg.end<ElemT>(), []() { return dist(gen); });
    std::cout << "Writing image...\n";
    tiffio::WriteTIFF("big_image.tif", bigImg, tiffio::Compression::NONE);

    std::cout << "OpenCV: Reading image...\n";
    try {
        const cv::Mat img = volcart::ReadImage("big_image.tif");
        std::cout << img.rows << "x" << img.cols << "\n";
        std::cout << cv::typeToString(img.type()) << "\n";
    } catch (const std::exception& e) {
        std::cout << "OpenCV: Failed to read: " << e.what() << "\n";
    }

    std::cout << "TIFFIO: Reading image...\n";
    try {
        const cv::Mat img = tiffio::ReadTIFF("big_image.tif");
        std::cout << img.rows << "x" << img.cols << "\n";
        std::cout << cv::typeToString(img.type()) << "\n";
    } catch (const std::exception& e) {
        std::cout << "TIFFIO: Failed to read: " << e.what() << "\n";
    }
}

@csparker247 csparker247 merged commit bda28ec into develop Nov 14, 2023
2 checks passed
@csparker247 csparker247 deleted the 42-large-ppm branch November 14, 2023 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] PPM error when loading cell map > 1GB
1 participant