From b19b7a5fefbb3180a817b4aadc21f25675cb366f Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 4 Oct 2011 15:56:38 -0400 Subject: [PATCH] Clean up the imports/exports between MRI and Main. --- src/MRI.hs | 57 +++++++++++------------------------------------------ src/Main.hs | 14 +++++++++++-- 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/MRI.hs b/src/MRI.hs index 157b899..cb89af9 100644 --- a/src/MRI.hs +++ b/src/MRI.hs @@ -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 @@ -115,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 = diff --git a/src/Main.hs b/src/Main.hs index 0afe2f7..80f5e97 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -5,8 +5,18 @@ import qualified Data.Array.Repa as R import System.Environment (getArgs) import Grid (zoom) -import MRI - +import MRI ( + flip_x, + flip_y, + mri_shape, + mri_slice3d, + read_word16s, + round_array, + swap_bytes, + write_values_slice_to_bitmap, + write_word16s, + z_slice + ) in_file :: FilePath in_file = "./data/mri.bin" -- 2.44.2