[fitsbits] Batch processing tool for converting .fit format to .jpg/.gif/.bmp
O'NEEL Bruce
bruce.oneel at obs.unige.ch
Tue Mar 14 07:53:38 EST 2000
Rob Christensen writes:
> Can anyone recommend a tool that allows you to convert
> files from the .fit format to a normal graphic type like gif/jpg/bmp?
> I need to convert several hundred .fit files to a web safe format.
> I don't have a lot of time to get this done so a commercial solution
> (if it's easier to use) is perfectly fine but I just don't know what's
> out there. Please email me with your response
>
> Thanks,
> Rob
> robc24 at pacbell.net
>
>
Hi,
Attached below are two files which when built together with Bill
Pence's cfitsio (start at http://heasarc.gsfc.nasa.gov) should produce
a program named fitstoppm. You run it like:
fitstoppm fitsfile.fits | ppmtogif > file.gif
To make this work you need the netpbm toolkit which may be installed,
if not you can get it from (hmm, google finds a lot of choices)
ftp://ftp.digital.com/pub/graphics/netpbm/. It produces images with
the same color map as ximage (start at heasarc again). This was a 5+
year old hack which still works, though I haven't built it for a long
time.
cheers
bruce
-------------- next part --------------
* A fits file read to ppm converter
program fitstoppm
call fitstoppm_sub
stop
end
subroutine fitstoppm_sub
integer*4 lun
character*100 filename
integer*4 rwmode
integer*4 blocksize
integer*4 status
integer*4 maxdim
logical*4 simple
integer*4 bitpix
integer*4 naxis
integer*4 naxes(2)
integer*4 pcount
integer*4 gcount
logical*4 extend
integer*4 group
integer*2 nullval
integer*4 dim1
integer*4 naxis1
integer*4 naxis2
integer*4 MAXIMAGESIZE
parameter (MAXIMAGESIZE=1024)
real*4 image(MAXIMAGESIZE,MAXIMAGESIZE)
integer*4 BMAXIMAGESIZE
parameter (BMAXIMAGESIZE=MAXIMAGESIZE*MAXIMAGESIZE*3)
integer*1 bimage(BMAXIMAGESIZE)
integer*4 bimagecnt
logical*4 anyf
integer*2 minval
integer*4 write
character*70 tstr
integer*4 MAXHIST
parameter (MAXHIST=255)
integer*4 ihist(0:MAXHIST,2)
integer*4 nhist
integer*4 ccolor
real*4 x
integer*4 val
integer*4 MAXCOLOR
parameter (MAXCOLOR=16)
real*4 colortab(3,MAXCOLOR)
data colortab /0.0, 0.0, 0.0,
& 0.3, 0.3, 0.3,
& 0.3, 0.2, 0.7,
& 0.0, 0.1, 0.8,
& 0.4, 0.4, 1.0,
& 0.2, 0.6, 0.73,
& 0.0, 0.8, 0.53,
& 0.1, 0.93,0.27,
& 0.4, 1.0, 0.0,
& 0.67,0.93,0.0,
& 1.0, 1.0, 0.0,
& 1.0, 0.8, 0.0,
& 0.7, 0.4, 0.0,
& 0.9, 0.2, 0.1,
& 1.0, 0.1, 0.0,
& 0.9, 0.9, 0.9/
integer*2 maxval
integer*4 i,j
lun = 10
rwmode = 0
blocksize = 0
call rdforn(filename,i)
call ftopen(lun,filename,rwmode,blocksize,status)
maxdim = 2
call ftghpr(lun,maxdim,simple,bitpix,naxis,naxes,
& pcount,gcount,extend,status)
group = 0
nullval = 0
dim1 = MAXIMAGESIZE
naxis1 = naxes(1)
naxis2 = naxes(2)
call ftg2de(lun,group,nullval,dim1,naxis1,naxis2,image,
& anyf,status)
call ftclos(lun,status)
maxval = -999
minval = 999
if (status .ne. 0) then
write (0,*)'Status from fitsio was ',status
write (0,*)'Filename was ',filename
call ftgerr(status,filename)
write (0,*)'Text was ',filename
call exit(1)
end if
do i=1,MAXHIST
ihist(i,1) = 0
ihist(i,2) = 0
end do
do i=1,naxes(1)
do j=1,naxes(2)
* image(i,j) = log(image(i,j))*10
maxval = max(int(image(i,j)),maxval)
minval = min(int(image(i,j)),minval)
if (image(i,j) .gt. MAXHIST) then
ihist(MAXHIST,1) = ihist(MAXHIST,1) + 1
else if (image(i,j) .lt. 0) then
ihist(0,1) = ihist(0,1) + 1
else
ihist(image(i,j),1) = ihist(image(i,j),1) + 1
end if
end do
end do
nhist = 0
do i=0,MAXHIST
if (ihist(i,1) .gt. 0) then
nhist = nhist + 1
C write (0,*)i,ihist(i,1)
end if
end do
C write (0,*)'Number of distinct values ',nhist
x = float(MAXCOLOR)/float(nhist)
C write (0,*)'colors/histogram bin ',float(MAXCOLOR)/float(nhist)
nhist = 0
ccolor = 1
do i=0,MAXHIST
if (ihist(i,1) .gt. 0) then
ihist(i,2) = ccolor
nhist = nhist + 1
ccolor = (nhist+1)*x + 1
if (ccolor .gt. MAXCOLOR) ccolor = MAXCOLOR
if (ccolor .lt. 1) ccolor = 1
C write (0,*)ihist(i,1),ihist(i,2)
end if
end do
C write (0,*)'Min : ',minval,' Max : ',maxval
C print *,'P6'
C print *,'P3'
C print *,naxes(1),naxes(2)
C print *,MAXCOLOR
bimagecnt = 1
do j=naxes(1),1,-1
do i=1,naxes(2)
C val = (image(i,j) - minval)*16./float(maxval-minval+1) + 1.0
if (image(i,j) .gt. MAXHIST) then
val = ihist(MAXHIST,2)
else if (image(i,j) .lt. 0) then
val = ihist(0,2)
else
val = ihist(image(i,j),2)
end if
C write (6,100)int(colortab(1,val)*MAXCOLOR),
C & int(colortab(2,val)*MAXCOLOR),
C & int(colortab(3,val)*MAXCOLOR)
bimage(bimagecnt) = int(colortab(1,val)*MAXCOLOR)
bimagecnt = bimagecnt + 1
bimage(bimagecnt) = int(colortab(2,val)*MAXCOLOR)
bimagecnt = bimagecnt + 1
bimage(bimagecnt) = int(colortab(3,val)*MAXCOLOR)
bimagecnt = bimagecnt + 1
* print *,bimage(bimagecnt-3),bimage(bimagecnt-2),
* $ bimage(bimagecnt-1)
100 format (3(i4))
end do
end do
tstr = 'P6'//char(10)
i = cwrite(1,tstr,3)
C write (0,*)'First write',i
C print *,naxes(1),naxes(2)
write (tstr,'(x,2(i6,x))')naxes(1),naxes(2)
tstr(30:30) = char(10)
i = cwrite(1,tstr,30)
C write (0,*)'Second write',i
write (tstr,'(x,i6)')MAXCOLOR
tstr(8:8) = char(10)
i = cwrite(1,tstr,8)
C write (0,*)'Third write ',i
i = cwrite(1,bimage,naxes(1)*naxes(2)*3)
C write (0,*)'Return from write ',i
return
end
-------------- next part --------------
/* write out stuff with write */
#include <stdio.h>
void cwrite_(int *tmp,char *str, int *cnt, int length)
{
write(1,str,*cnt);
}
-------------- next part --------------
--
Teleportation is very confusing, even to experts - Matt Conway.
Bruce O'Neel phone: +41 22 950 91 22 (direct)
INTEGRAL Science Data Centre +41 22 950 91 00 (switchb.)
Chemin d'Ecogia 16 fax: +41 22 950 91 33
CH-1290 VERSOIX e-mail: Bruce.Oneel at obs.unige.ch
Switzerland WWW: http://isdc.unige.ch/
More information about the fitsbits
mailing list