Skip to content

Instantly share code, notes, and snippets.

@emilroz
Last active August 29, 2015 14:08
Show Gist options
  • Save emilroz/1828cde0f1c793f7bfe5 to your computer and use it in GitHub Desktop.
Save emilroz/1828cde0f1c793f7bfe5 to your computer and use it in GitHub Desktop.
Example use of Bio-formats CPP library
cmake_minimum_required(VERSION 2.8)
project(test_bio)
set(CMAKE_PREFIX_PATH "/usr/local/lib/cmake/;${CMAKE_PREFIX_PATH}")
set(CMAKE_MODULE_PATH "/usr/local/lib/cmake/;${CMAKE_MODULE_PATH}")
find_package(ome-bioformats REQUIRED)
include_directories(${OME_BIOFORMATS_INCLUDE_DIR})
MESSAGE(STATUS "OME BIOFORMATS: " ${OME_BIOFORMATS_INCLUDE_DIR})
MESSAGE(STATUS "OME BIOFORMATS: " ${OME_BIOFORMATS_LIBRARY})
add_executable(test_bio Main.cxx)
target_link_libraries(test_bio ${OME_BIOFORMATS_LIBRARY})
/*
:author: Emil Rozbicki <[email protected]>
Copyright (C) 2014 Glencoe Software, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/time.h>
#include <ome/bioformats/VariantPixelBuffer.h>
#include <ome/bioformats/in/TIFFReader.h>
#include <ome/bioformats/tiff/TIFF.h>
#include <ome/bioformats/in/MinimalTIFFReader.h>
#include <ome/bioformats/FileInfo.h>
using ome::bioformats::tiff::TIFF;
#include <iostream> // std::cout
#include <string> // std::string, std::stod
using ome::bioformats::dimension_size_type;
using ome::bioformats::VariantPixelBuffer;
using ome::bioformats::in::TIFFReader;
int main (int argc, char* argv[])
{
ome::bioformats::in::TIFFReader tiff_reader;
std::string file_name = argv[1];
tiff_reader.setId(file_name);
std::vector<std::string> files = tiff_reader.getUsedFiles();
std::cout << "Files: " << "\n";
for (int f = 0; f < files.size(); f++) {
std::cout << "\t" << files.at(f) << "\n";
}
std::cout << "Series count = " << tiff_reader.getSeriesCount() << "\n\n";
for (int s = 0; s < tiff_reader.getSeriesCount(); s++) {
std::cout << "Series #" << s << "\n"
<< "\tImage count = " << tiff_reader.getImageCount() << "\n"
<< "\tRGB = " << tiff_reader.getRGBChannelCount() << "\n";
if (tiff_reader.isInterleaved()) {
std::cout << "\tInterleaved = " << "true" << "\n";
} else {
std::cout << "\tInterleaved = " << "false" << "\n";
}
if (tiff_reader.isIndexed()) {
std::cout << "\tIndexed = " << "true" << "\n";
} else {
std::cout << "\tIndexed = " << "false" << "\n";
}
std::cout << "\tWidth = " << tiff_reader.getSizeX() << "\n"
<< "\tHeight = " << tiff_reader.getSizeY() << "\n"
<< "\tSizeZ = " << tiff_reader.getSizeZ() << "\n"
<< "\tSizeT = " << tiff_reader.getSizeT() << "\n"
<< "\tSizeC = " << tiff_reader.getSizeC() << "\n"
<< "\tThumbnail size = " << tiff_reader.getThumbSizeX()
<< " x " << tiff_reader.getThumbSizeY() << "\n";
if (tiff_reader.isLittleEndian()) {
std::cout << "\tEndianness = " << "little"<< "\n";
} else {
std::cout << "\tEndianness = " << "not little"<< "\n";
}
if (tiff_reader.isOrderCertain()) {
std::cout << "\tDimension order = " << tiff_reader.getDimensionOrder() << " (certain)\n";
} else {
std::cout << "\tDimension order = " << tiff_reader.getDimensionOrder() << " (not certain)\n";
}
std::cout << "\tPixel Type = " << tiff_reader.getPixelType() << "\n"
<< "\tBits per Pixel = " << tiff_reader.getBitsPerPixel() << "\n";
if (tiff_reader.isMetadataComplete()) {
std::cout << "\tMetadata complete = " << "true" << "\n";
} else {
std::cout << "\tMetadata complete = " << "false" << "\n";
}
if (tiff_reader.isThumbnailSeries()) {
std::cout << "\tThumbnail series = " << "true" << "\n";
} else {
std::cout << "\tThumbnail series = " << "false" << "\n";
}
}
ome::bioformats::MetadataMap series_map = tiff_reader.getSeriesMetadata();
ome::bioformats::MetadataMap global_map = tiff_reader.getGlobalMetadata();
std::cout << "\nGlobal Metadata\n";
for(auto it = global_map.begin(); it != global_map.end(); ++it)
{
std::cout << it->first << ": " << it->second << "\n";
}
std::cout << "\nSeries Metadata\n";
std::string holder;
for(auto it = series_map.begin(); it != series_map.end(); ++it)
{
holder = it->first;
if (holder.compare("StripByteCounts") != 0 && holder.compare("StripOffsets") != 0) {
std::cout << it->first << ": " << it->second << "\n";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment