Raster image I/O

From Madagascar
Revision as of 13:48, 23 June 2009 by Nick (talk | contribs) (New page: ==Converting raster images to RSF files== One option is sfjpg2byte. It requires the JPEG library to be present at the compilation time. <bash> < lena.jpg sfjpg2byte | sfdd type=float > len...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Converting raster images to RSF files

One option is sfjpg2byte. It requires the JPEG library to be present at the compilation time. <bash> < lena.jpg sfjpg2byte | sfdd type=float > lena.rsf </bash> Another option is to use the convert utility from ImageMagick. For a greyscale image: <bash> < lena.jpg convert - lena.gray echo in=lena.gray data_format=native_uchar n1=512 n2=512 | sfdd type=float > lena.rsf </bash> or, for a color image: <bash> < lena.jpg convert - lena.rgb echo in=lena.rgb data_format=native_uchar n1=3 n2=512 n3=512 | sfdd type=float > lena.rsf </bash>

Converting RSF 2-D data to raster images

If Madagascar has been compiled with JPEG support, sfbyte2jpg can be used: <bash> < model.rsf sfbyte | sfbyte2jpg > model.jpg </bash> Then, another program can be used to convert the JPEG file to another format. If ImageMagick is present, it can be used to convert a RSF binary to almost any image format. In a SConstruct, the workflow would look like: <python> Flow('data.gray','data',

   
   transp |  # Make data in row-major order
   byte gainpanell=all allpos=y |  # Convert data to byte representation
   disfil col=1 format="%02X" |  # Dump data in one column in ASCII-hex
   sed -e "s/\s*[0-9]*\:\s*//g" |  # Strip column numbers
   xxd -r -p  # Read ASCII output and convert it to binary form
   )

Flow('data.png','data.gray',

   
   convert -size %dx%d -depth 8 ${SOURCES[0]} ${TARGETS[0]}  # Run ImageMagick
    % (n2, n1), stdin=0, stdout=0)

</python>

To output to another format, just change the extension in the last Flow() from .png to .gif or .jpg, for example. Create the output simply by running: scons data.png