>I'd like to know how I can strip off .tiff (or .pgm) header in UNIX. I
>used "od -b" to view the binary files, so I know exactly how many bytes to
>strip off, but I don't know which commands or programs to use. Thanks.
The TIFF image format is much more complex than just a header associated to
raw data. TIFF format is made to be flexible, so you can add as much
information as you need, thus a variable header size.
Another point is that the 'header' is not always in the beginning of the file,
but in some other location indicated in the first file bytes.
If you want to handle even a few simple cases, you have to get a TIFF reader,
to take care of these points. Have a look on the TIFF home page on WWW.
An easy solution is a kind of little hack in c to do the job.
This is an example in ANSI C :
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main(int argc, char *argv[])
{
FILE *in, *out ;
char *buffer ;
int offset, bytes ;
if (argc<5)
{
printf("use : %s <in> <out> <offset> <bytes>\n", argv[0]) ;
return(1) ;
}
if ((in = fopen(argv[1],"r")) == (FILE*)NULL)
{
printf("cannot open %s\n", argv[1]) ;
return(-1) ;
}
if ((out = fopen(argv[2],"w")) == (FILE*)NULL)
{
printf("cannot create %s\n", argv[2]) ;
return(-1) ;
}
offset = atoi(argv[3]) ;
bytes = atoi(argv[4]) ;
buffer = (char*)malloc(bytes*sizeof(char)) ;
if (buffer == (char*)NULL)
{
printf("memory allocation failure : aborting\n") ;
return(-1) ;
}
fseek(in, offset,0);
fread(buffer, sizeof(char), bytes, in) ;
fwrite(buffer, sizeof(char), bytes, out) ;
fclose(in) ;
fclose(out) ;
free(buffer) ;
return(0) ;
}
Hope it helps,
Nicolas
______________________________________________________________________
/\ \
\_| Nicolas Devillard | E-mail: nDe...@eso.org |
| European Southern Observatory, | http://www.eso.org/~ndevilla |
| Karl-Schwarzschild-Str. 2, | Phone: +49 89 320-06-340 |
| D-85748 Garching, Germany | |
| __________________________________________________________________|_
\_/____________________________________________________________________/
>On Sun, 17 Sep 1995 15:29:09 GMT Nicolas Devillard wrote:
>! In article 2...@agate.berkeley.edu, hsi...@prometheus.ME.Berkeley.EDU (Andy C.
>Hsia) writes:
>! >I'd like to know how I can strip off .tiff (or .pgm) header in UNIX. I
>! >used "od -b" to view the binary files, so I know exactly how many bytes to
>! >strip off, but I don't know which commands or programs to use. Thanks.
>! The TIFF image format is much more complex than just a header associated to
>! raw data. TIFF format is made to be flexible, so you can add as much
>! information as you need, thus a variable header size.
>! Another point is that the 'header' is not always in the beginning of the file,
>! but in some other location indicated in the first file bytes.
>! If you want to handle even a few simple cases, you have to get a TIFF reader,
>! to take care of these points. Have a look on the TIFF home page on WWW.
>! An easy solution is a kind of little hack in c to do the job.
>! This is an example in ANSI C :
>Or another way is to use the unix command tail, for example:
>tail +100c input > output
>would copy everything after the 100th byte in the file input to the file
>output.
>Jim
>--
> Jim Vaughan Tel: +44 (0) 1273 642247
> Image Processing Research Unit Fax: +44 (0) 1273 642255
> University of Brighton, Lewes Road Jim.V...@bton.ac.uk
> Brighton, BN2 4GJ, England http://www.eng.bton.ac.uk/Jim/
Remember also that there is no requirement in TIFF for all the image to be
consecutive. TIFF knows about strips, and to save memory allows an image to be
loaded/written a strip at a time. The order of strips is potentially random,
as the header information gives the file offsets for each strip. That said, I
have read TIFF files by simply ignoring the header. However, there is no set
length or file location for the TIFF header, and there are often multiple
images in a TIFF file (e.g. thumbnail and main image).
A. Paul R. Cooper
British Antarctic Survey
ap...@pcmail.nerc-bas.ac.uk
***** Any opinions given here are my own, *****
***** and not necessarily those of British Antarctic Survey *****