]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/MRI.hs
Clean up the imports/exports between MRI and Main.
[spline3.git] / src / MRI.hs
index 5f2ceea483437bc7a9216f066e86e1d32867288d..cb89af91d145c8c25c130a73b9814c9a6bfde869 100644 (file)
@@ -1,4 +1,15 @@
-module MRI
+module MRI (
+  flip_x,
+  flip_y,
+  mri_shape,
+  mri_slice3d,
+  read_word16s,
+  round_array,
+  swap_bytes,
+  write_values_slice_to_bitmap,
+  write_word16s,
+  z_slice
+  )
 where
 
 import Data.Word
@@ -37,9 +48,6 @@ type RawData3D = RawData DIM3
 type RGB = (Word8, Word8, Word8)
 type ColorData sh = Array sh RGB
 
-rgb_to_dbl :: RGB -> (Double, Double, Double)
-rgb_to_dbl (x,y,z) = (fromIntegral x, fromIntegral y, fromIntegral z)
-
 
 read_word16s :: FilePath -> IO RawData3D
 read_word16s path = do
@@ -48,7 +56,6 @@ read_word16s path = do
   return arr
 
 
-{-# INLINE bracket #-}
 bracket :: Double -> Word16
 bracket x
         | x < mri_lower_threshold      = 0
@@ -60,7 +67,6 @@ bracket x
               r = numerator/denominator
 
 
-{-# INLINE flip16 #-}
 flip16 :: Word16 -> Word16
 flip16 xx =
   shift xx 8 .|. (shift xx (-8) .&. 0x00ff)
@@ -70,11 +76,15 @@ swap_bytes :: (Shape sh) => (RawData sh) -> (RawData sh)
 swap_bytes arr =
     R.force $ R.map flip16 arr
 
+
 bracket_array :: (Shape sh) => (Values sh) -> (RawData sh)
 bracket_array arr =
-  R.force $ R.map f arr
-  where
-    f = bracket
+  R.force $ R.map bracket arr
+
+
+round_array :: (Shape sh) => (Values sh) -> (RawData sh)
+round_array arr =
+  R.force $ R.map round arr
 
 
 flip_y :: RawData3D -> RawData3D
@@ -113,53 +123,12 @@ values_to_colors arr =
         b' = truncate (b * 255)
 
 
-red_dbl_data :: (Shape sh) => (ColorData sh) -> Array sh Double
-red_dbl_data =
-  R.map (get_r . rgb_to_dbl)
-  where
-    get_r :: (Double, Double, Double) -> Double
-    get_r (r, _, _) = r
-
-green_dbl_data :: (Shape sh) => (ColorData sh) -> Array sh Double
-green_dbl_data =
-  R.map (get_g . rgb_to_dbl)
-  where
-    get_g :: (Double, Double, Double) -> Double
-    get_g (_, g, _) = g
-
-
-blue_dbl_data :: (Shape sh) => (ColorData sh) -> Array sh Double
-blue_dbl_data =
-  R.map (get_b . rgb_to_dbl)
-  where
-    get_b :: (Double, Double, Double) -> Double
-    get_b (_, _, b) = b
-
-
 
 z_slice :: Elt a => Int -> Array DIM3 a -> Array DIM2 a
 z_slice n arr =
   slice arr (Any :. n :. All :. All)
 
 
-transpose_zx :: Elt a => Array DIM3 a -> Array DIM3 a
-transpose_zx arr =
-  traverse arr
-           (\(Z :. zdim :. ydim :. xdim) -> (Z :. xdim :. ydim :. zdim))
-           (\_ -> (\(Z :. z :. y :. x) -> arr ! (Z :. x :. y :. z)))
-
-
-z_slice3 :: Elt a => Int -> Array DIM3 a -> Array DIM3 a
-z_slice3 n arr
-  | n == 0 = transpose_zx $ current R.++ next
-  | n == zdim-1 = transpose_zx $ previous R.++ current
-  | otherwise = transpose_zx $ previous R.++ current R.++ next
-  where
-    (Z :. zdim :. _ :. _) = extent arr
-    previous = transpose_zx $ reshape mri_slice3d (z_slice (n-1) arr)
-    current = transpose_zx $ reshape mri_slice3d (z_slice n arr)
-    next = transpose_zx $ reshape mri_slice3d (z_slice (n+1) arr)
-
 
 write_values_slice_to_bitmap :: Values2D -> FilePath -> IO ()
 write_values_slice_to_bitmap v3d path =
@@ -170,13 +139,3 @@ write_values_slice_to_bitmap v3d path =
     routput = R.map (\(red, _,     _)    -> red)   colors
     goutput = R.map (\(_,   green, _)    -> green) colors
     boutput = R.map (\(_,   _,     blue) -> blue)  colors
-
-
-write_values_chunk_to_bitmap :: Values3D -> FilePath -> IO ()
-write_values_chunk_to_bitmap v3d path
-  | zdim /= 3 = error "not a 3xMxN chunk"
-  | otherwise = write_values_slice_to_bitmap target_slice path
-  where
-    (Z :. zdim :. _ :. _) = extent v3d
-    target_slice = z_slice 1 v3d
-