Raster image I/O

From Madagascar
Revision as of 17:16, 12 August 2011 by Nick (talk | contribs) (→‎Converting RSF 2-D data to raster images)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Converting raster images to RSF files

One option is sftif2byte or sfjpg2byte. It requires the TIFF or JPEG library, respectively, to be present at the compilation time. <bash> < lena.tif sftif2byte | sfdd type=float > lena.rsf </bash> <bash> < lena.jpg sfjpg2byte | sfdd type=float > lena.rsf </bash> Another option is to use the convert utility from ImageMagick. For a grayscale 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

  1. Red component:

< lena_rgb.rsf sfwindow n1=1 f1=0 > lena_red.rsf

  1. Green:

< lena_rgb.rsf sfwindow n1=1 f1=1 > lena_green.rsf

  1. Blue:

< lena_rgb.rsf sfwindow n1=1 f1=2 > lena_blue.rsf </bash>

Converting RSF 2-D data to raster images

If Madagascar has been compiled with TIFF support, sfbyte2tif can be used: <bash> < model.rsf sfbyte | sfbyte2tif > model.tif </bash> 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 number=n format="%02X" |  # Dump data in one column in ASCII-hex
   xxd -r -p  # Read ASCII output and convert it to binary form


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


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