You are right, thanks. I created a bitmap image with 24 bits per pixel, changed vtkPNGReader into vtkBMPReader and now this code works. I can read output tif file with vtkTIFFReader as well.
Unfortunately, I did not find a solution for reading my another tiff file in the same way.
I did not find the root of problem, but I can explain the structure of my tiff file.
It has the standard header (see TIFF: Summary from the Encyclopedia of Graphics File Formats as well) (49 49 2a 00), then First IFD Offset. In This IFD there are all needed parameters, e.g.
image_width = 37888
image_length = 49152
tile_width = 256
tile_length = 256
compression = 7
planar_configuration = 1
tile_offsets, tile_bytes
jpeg_table with jpeg_tables_size = 574
JPEG Table has the following structure:
FF D8 (SOI)
FF DB (DQT) with some data
FF DB (DQT) with some data
FF C4 (DHT) with some data
FF C4 (DHT) with some data
FF C4 (DHT) with some data
FF C4 (DHT) with some data
FF D9 (EOI)
Data for offset 0 has 1831 bytes and has the following structure:
FF D8 (SOI)
FF C0 (SOF0) with some data
FF DA (SOS) with some data
image data (1796 bytes)
Other data has the similar structures.
The problem is that vtkTIFFReader 8.1 and 9.1 can’t read this my file. Version 8.1 reads it but displays a wrong image and 9.1 fails in tif_jpeg.c on the line 1255
TIFFErrorExt(tif->tif_clientdata, module,
"Improper JPEG sampling factors %d,%d\n"
"Apparently should be %"PRIu16",%"PRIu16".",
sp->cinfo.d.comp_info[0].h_samp_factor,
sp->cinfo.d.comp_info[0].v_samp_factor,
sp->h_sampling, sp->v_sampling);
because sp->cinfo.d.comp_info[0].h_samp_factor and sp->cinfo.d.comp_info[0].v_samp_factor are equal to 1 while sp->h_sampling and sp->v_sampling are 2. The last two parameters have been set to 2 in the same file on the line 1039:
switch (sp->photometric) {
case PHOTOMETRIC_YCBCR:
sp->h_sampling = td->td_ycbcrsubsampling[0];
sp->v_sampling = td->td_ycbcrsubsampling[1];
break;
I have to add that GIMP opens this tiff file but its structure if violated. But Windows Photo Viewer displays this file good. Matlab open this tiff file good as well.
I wrote a python script that creates a buffer, copy there jpeg table without the last two bytes and then copy there image by index without the first two bytes. I get the right jpeg file in this way. Then I combine all those images and have the right result.
Unfortunately I can’t attach this image because of its size and non-disclosure agreement, but I hope you could point me out the right place where I can get some help.