-
-
Save EnderChris/5ae6a7b28994451ef7c0c38a81de23eb to your computer and use it in GitHub Desktop.
Writting TIFF image with deflate compression corrupt in memory image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROJECT(ImageRW) | |
cmake_minimum_required(VERSION 3.0) | |
set(CMAKE_CXX_STANDARD 14) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
########################### | |
########### ITK ########### | |
########################### | |
find_package(ITK) | |
IF (ITK_FOUND) | |
INCLUDE(${ITK_USE_FILE}) | |
ENDIF (ITK_FOUND) | |
LINK_LIBRARIES( | |
${ITK_LIBRARIES} | |
) | |
########################### | |
########### END ########### | |
########################### | |
set(CMAKE_INCLUDE_CURRENT_DIR ON) | |
INCLUDE_DIRECTORIES( | |
${CMAKE_CURRENT_SOURCE_DIR} | |
${CMAKE_CURRENT_BINARY_DIR} | |
) | |
LINK_DIRECTORIES( | |
${CMAKE_CURRENT_SOURCE_DIR} | |
) | |
SET(ImageRW_SRCS | |
main.cxx | |
) | |
ADD_EXECUTABLE(ImageRW ${ImageRW_SRCS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "itkImage.h" | |
#include "itkImageFileWriter.h" | |
#include "itkImageFileReader.h" | |
#include <itkTIFFImageIO.h> | |
#include <itkTestingComparisonImageFilter.h> | |
#include "main.h" | |
#define INPUT_FILE "C:/Users/User/Desktop/0.mhd" | |
#define OUTPUT_FILE "C:/Users/User/Desktop/output.tiff" | |
int main() | |
{ | |
typedef itk::Image<unsigned short, 3> ImageType; | |
typedef itk::ImageFileReader<ImageType> ReaderType; | |
ImageType::Pointer image; | |
ImageType::Pointer image2; | |
{ | |
ReaderType::Pointer reader = ReaderType::New(); | |
reader->SetFileName(INPUT_FILE); | |
reader->Update(); | |
image = reader->GetOutput(); | |
} | |
{ | |
ReaderType::Pointer reader = ReaderType::New(); | |
reader->SetFileName(INPUT_FILE); | |
reader->Update(); | |
image2 = reader->GetOutput(); | |
} | |
{ | |
itk::TIFFImageIO::Pointer tiffIO = itk::TIFFImageIO::New(); | |
tiffIO->SetCompression(itk::TIFFImageIO::Deflate); | |
typedef itk::ImageFileWriter<ImageType> WriterType; | |
WriterType::Pointer writer = WriterType::New(); | |
writer->SetInput(image); | |
writer->SetFileName(OUTPUT_FILE); | |
writer->SetUseCompression(true); | |
writer->SetImageIO(tiffIO); | |
writer->Update(); | |
} | |
// Now compare the two images | |
using DiffType = itk::Testing::ComparisonImageFilter<ImageType, ImageType>; | |
DiffType::Pointer diff = DiffType::New(); | |
diff->SetValidInput(image2); | |
diff->SetTestInput(image); | |
diff->UpdateLargestPossibleRegion(); | |
const unsigned long numberOfPixelsWithDifferences = | |
diff->GetNumberOfPixelsWithDifferences(); | |
if (numberOfPixelsWithDifferences == 0) | |
std::cout << "OK" << std::endl; | |
else | |
std::cout << "KO" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment