[Insight-users] RGB images from Visible Human Dataset

Luis Ibanez luis . ibanez at kitware . com
Fri, 31 Oct 2003 15:34:46 -0500


Hi Stefan,

It is strange that the error in the execution of the
python script is showing up for the value i=20. It
looks like the read() is not retrieving the total
number of requested bytes.

Can you please verify the size of the arrays:

             rdata, gdata, bdata

just after you read them something like

      rdata = file.read( slicesize )
      print len( rdata )

The fact that the script is doing partial reading of
data looks like the old-annoying problem of MS-Windows
of opening files for default in ASCII mode instead
of binary mode. You may want to open the files using
something like

      file = open("inputVisibleHumanSlice",'rb')

The 'rb' characters specify that the file is being
open for "reading" and in "binary" mode.

Make sure you do a similar thing for writing:

    outputFile = open("reorderedFile",'wb')

where 'wb' specifies to open the file for writing
and in "binary" mode.


Please let us know if you find any further problems


BTW, we talked about this issue in our weekly
developers meeting and decided to write an ITK
class for reading VisibleHuman slices. We plan
to put together a prototype of this class pretty
soon.


    Luis



--------------------------
Stefan Lindenau wrote:
> Hi Luis,
> 
> thank you for the good explanation.
> I have tried the script you attached but it is not working for me. I 
> just made some adaptations regarding the filename and the slicesize 
> since I am not using cropped images from the female dataset.
> But whenever I execute the script I get the following error:
> 
> reorganizing  c:\avf1262a.raw  into  vwavf12.raw
> Traceback (most recent call last):
>  File "C:\reorder VHD.py", line 27, in ?
>    reorderRGB("c:\\avf1262a.raw")
>  File "C:\reorder VHD.py", line 18, in reorderRGB
>    rgbfile.write( gdata[i] )
> IndexError: string index out of range
> 
> In the stackview I see that the variable i has the value 20.
> I think the reason for this failure is that the rdata,gdata,bdata 
> strings are not filled as expected.
> 
> Iam using Python 2.3.2 with TK 8.4 on Windows.
> 
> That is the code I am using:
> ------------------------------
> #!/usr/bin/python
> 
> import glob
> 
> def reorderRGB( filename ):
>  slicesize = 2048 *1216
>  file=open(filename)
>  rdata=file.read( slicesize )
>  gdata=file.read( slicesize )
>  bdata=file.read( slicesize )
>  file.close()
>  outfilename="vw"+filename[3:8]+".raw"
>  print "reorganizing ", filename, " into " , outfilename
>  rgbfile=open( outfilename, 'w' )
>  for i in range(0,slicesize-1):
>    rgbfile.write( rdata[i] )
>    rgbfile.write( gdata[i] )
>    rgbfile.write( bdata[i] )
>  rgbfile.close()
> 
> 
> def printfile( filename ):
>  print filename
> 
> 
> 
> listfiles=glob.glob("avf1*.raw")
> for filename in listfiles:
>  reorderRGB( filename )
> 
> print "Files reorganized"
> ------------------------------
> 
> 
> 
> Thank you
> Stefan
> 
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>