X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMRI.hs;h=c142dcd22b4d74e5b815841b894e212181131791;hb=1edcaa0d2e4b5f04ceb10024debb3219ac037057;hp=510e4c011191f8cc78c99fac464a04175a8ed9af;hpb=c8ec035a77f871e4deaa976ed6f3a65a32c07048;p=spline3.git diff --git a/src/MRI.hs b/src/MRI.hs index 510e4c0..c142dcd 100644 --- a/src/MRI.hs +++ b/src/MRI.hs @@ -1,4 +1,20 @@ -module MRI +-- | The MRI module contains functionsd and definitions relevant (and +-- specific) to the MRI data files found at, +-- +-- +-- +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 @@ -31,15 +47,16 @@ mri_upper_threshold = 2500 mri_slice3d :: DIM3 mri_slice3d = (Z :. 1 :. mri_height :. mri_width) +-- | RawData is an array of words (16 bits), as contained in the MRI +-- data files. type RawData sh = Array sh Word16 + +-- | A specialization of the 'RawData' type, to three dimensions. 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 +65,6 @@ read_word16s path = do return arr -{-# INLINE bracket #-} bracket :: Double -> Word16 bracket x | x < mri_lower_threshold = 0 @@ -60,7 +76,6 @@ bracket x r = numerator/denominator -{-# INLINE flip16 #-} flip16 :: Word16 -> Word16 flip16 xx = shift xx 8 .|. (shift xx (-8) .&. 0x00ff) @@ -117,53 +132,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 =