[ITK] ITK-4.6 problem
Gib Bogle
g.bogle at auckland.ac.nz
Tue Sep 16 01:15:09 EDT 2014
Hi all,
There definitely seems to be a problem with ITK-4.6, at least with the code that got installed while building Slicer. This was carried out with ITKV3_COMPATIBILITY off. I am doing some testing with this installation to try to understand why Slicer cannot handle big tiffs (on my Windows 7 system).
There is something a bit funny about the installed ITK-4.6, in that the compiler complained about some missing include files, vnl_*.h and others, which are in my ITK-4.0 installation but not in 4.6. I just copied them across - I hope this is not a problem.
Anyway, I now find that my very simple program that uses ITK to create a tiff file now crashes when built with 4.6. What is a big clue is that it fails while creating the image, i.e. writing to the buffer, on page 73 - it's surely more than a coincidence that Slicer fails when reading page 72 of a 4 GB tiff. In this case only 73 bytes have been written to buffer when it fails. The whole program is below. It fails having written x=0, y=0, z=0...73 to the console.
Unless my code (which was fine with 4.0) is no longer OK with 4.6, this is a very basic bug, since all I do is set the image size, allocate memory, get a pointer to the buffer and start writing to it.
The program is short enough to paste in its entirety, but the relevant section is just a few lines.
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <string>
#include <sstream>
#include <assert.h>
#include <ctime>
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkSize.h"
typedef itk::Image<unsigned char,3> ImageType;
ImageType::Pointer im;
unsigned char *p;
#define V(a,b,c) p[(c)*xysize+(b)*width+(a)]
int main(int argc, char**argv)
{
int x1, x2, y1, y2, z1, z2;
int x0, y0, z0, dx, dy, dz;
int x, y, z, xx, yy, zz, n, comp_flag;
long long width, height, depth, xysize;
int R, R2;
bool use_compression;
bool use_sphere = false;
if (argc != 4) {
printf("Usage: makebig tiff_file N compress\n");
printf(" the image will be NxNxN\n");
printf(" set compress=1 to use compression, =0 otherwise\n");
return 1;
}
printf("Output image file: %s\n",argv[1]);
sscanf(argv[2],"%d",&n);
sscanf(argv[3],"%d",&comp_flag);
use_compression = (comp_flag == 1);
x0 = n/2;
y0 = n/2;
z0 = n/2;
R = 5;
R2 = R*R;
width = n;
height = n;
depth = n;
xysize = width*height;
printf("Desired image dimensions: width, height, depth: %d %d %d\n",width,height,depth);
ImageType::Pointer im = ImageType::New();
ImageType::SizeType imsize;
imsize[0] = width;
imsize[1] = height;
imsize[2] = depth;
ImageType::IndexType imstart;
imstart[0] = 0;
imstart[1] = 0;
imstart[2] = 0;
ImageType::RegionType imregion;
imregion.SetSize(imsize);
imregion.SetIndex(imstart);
im->SetRegions(imregion);
im->Allocate();
p = (unsigned char *)(im->GetBufferPointer());
width = im->GetLargestPossibleRegion().GetSize()[0];
height = im->GetLargestPossibleRegion().GetSize()[1];
depth = im->GetLargestPossibleRegion().GetSize()[2];
printf("Requested image dimensions: width, height, depth: %d %d %d\n",width,height,depth);
for (x=0; x<width; x++) {
printf("x: %d\n",x);
for (y=0; y<height; y++) {
printf("y: %d\n",y);
for (z=0; z<depth; z++) {
printf("z: %d\n",z);
if (use_sphere) {
dx = x - x0;
dy = y - y0;
dz = z - z0;
if (dx*dx+dy*dy+dz*dz <= R2) {
V(x,y,z) = 255;
} else {
V(x,y,z) = 0;
}
} else {
if (x < x0-R || x > x0+R) {
V(x,y,z) = 0;
} else {
V(x,y,z) = 255;
}
}
}
}
}
typedef itk::ImageFileWriter<ImageType> FileWriterType;
FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName(argv[1]);
writer->SetInput(im);
if (use_compression) {
writer->UseCompressionOn();
}
printf("Writing tiff file\n");
try
{
writer->Update();
}
catch (itk::ExceptionObject &e)
{
std::cout << e << std::endl;
return 4;
}
if (use_compression) {
printf("Created compressed image file: %s\n",argv[1]);
} else {
printf("Created uncompressed image file: %s\n",argv[1]);
}
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140916/12efe70e/attachment.html>
More information about the Community
mailing list