Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /trunk/src/compiler/fields/image-info.sml
ViewVC logotype

View of /trunk/src/compiler/fields/image-info.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3082 - (download) (annotate)
Mon Mar 16 22:09:18 2015 UTC (4 years, 7 months ago) by jhr
File size: 3789 byte(s)
  detabbing in trunk
(* image-info.sml
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Information about an image object.
 *
 * TODO:
 *      handle images where the symmetries are exploited.
 *)

structure ImageInfo : sig

    type info

  (* are the underlying files the same? *)
    val same : info * info -> bool

  (* hash value (based on image file ID) *)
    val hash : info -> word

  (* make image info from a proxy Nrrd file, target domain dimension, and range shape;
   * return NONE if the domain and/or range do not match the structure of the nrrd file.
   *)
    val fromNrrd : NrrdInfo.info * int * int list -> info option

  (* create a default image from a domain dimension and range shape. *)
    val mkInfo : int * int list -> info

    val toString : info -> string
    val dim : info -> int               (* dimension of space *)
    val sizes : info -> int list        (* size of each dimension (not including the data axis) *)
    val voxelShape : info -> int list   (* shape of voxels; empty list for scalars *)
    val voxelSzB : info -> int          (* size in bytes of a voxel *)
    val stride : info -> int            (* for non-scalar images, this returns the *)
                                        (* number of samples between voxels *)
    val sampleTy : info -> RawTypes.ty  (* representation type of samples *)

  end = struct

  (* Image voxels are tensors of some raw representation type *)
    type voxel_ty = (int list * RawTypes.ty)

    datatype info = ImgInfo of {
        stamp : Stamp.stamp,            (* unique ID *)
        dim : int,                      (* dimension of space *)
        sizes : int list,               (* number of samples along each axis (not including
                                         * the data axis); we follow the Nrrd convention of
                                         * listing the axes in fast to slow order.
                                         *)
        ty : voxel_ty
      }

    fun same (ImgInfo{stamp=s1, ...}, ImgInfo{stamp=s2, ...}) = Stamp.same(s1, s2)
    fun hash (ImgInfo{stamp, ...}) = Stamp.hash stamp

  (* make image info from a proxy Nrrd file, target domain dimension, and range shape *)
    fun fromNrrd (nrrd, dim, dd) = let
          val {elemTy, nElems, ...} = NrrdInfo.voxelInfo nrrd
          val nElems' = List.foldl (op * ) 1 dd
          in
            if (NrrdInfo.dim nrrd <> dim) orelse (nElems <> nElems')
              then NONE
              else SOME(ImgInfo{
                  stamp = Stamp.new(),
                  dim = dim,
                  sizes = NrrdInfo.sizes nrrd,
                  ty = (dd, elemTy)
                })
          end

    fun mkInfo (dim, dd) = ImgInfo{
            stamp = Stamp.new(),
            dim = dim,
            sizes = [], (* unknown *)
            ty = (dd, !RawTypes.realTy)
          }

    fun toString (ImgInfo{dim, ty=(dd, rTy), ...}) = let
          val shape = (case dd
                 of [] => ""
                  | [d] => concat["{", Int.toString d, "}"]
                  | dd => concat["{", String.concatWith "," (List.map Int.toString dd), "}"]
                (* end case *))
          in
            concat[
                "IMAGE", Int.toString dim, "D<", RawTypes.toString rTy, shape, ">"
              ]
          end

    fun dim (ImgInfo{dim, ...}) = dim

    fun sizes (ImgInfo{sizes, ...}) = sizes

    fun voxelShape (ImgInfo{ty=(dd, _), ...}) = dd

    fun voxelSzB (ImgInfo{ty=(dd, rTy), ...}) = let
          val nSamples = List.foldl (op * ) 1 dd
          in
            nSamples * RawTypes.sizeb rTy
          end

    fun stride (ImgInfo{ty=(dd, rTy), ...}) = List.foldl (op * ) 1 dd

    fun sampleTy (ImgInfo{ty=(_, rTy), ...}) = rTy

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0