X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMRI.hs;h=cb89af91d145c8c25c130a73b9814c9a6bfde869;hb=be270c8af37aae540ae6649aed91762017d07ac2;hp=2dd6f6592e6e3bb7ac8d1eefbe73a4764e3cf787;hpb=65eed42ae2b9ca947bd7c08c2a102c1cf5dce8cc;p=spline3.git diff --git a/src/MRI.hs b/src/MRI.hs index 2dd6f65..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 @@ -6,6 +17,7 @@ import Data.Bits import Data.Array.Repa as R import Data.Array.Repa.IO.Binary as R import Data.Array.Repa.IO.ColorRamp as R +import Data.Array.Repa.IO.BMP as R (writeComponentsToBMP) import Values @@ -36,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 @@ -47,7 +56,6 @@ read_word16s path = do return arr -{-# INLINE bracket #-} bracket :: Double -> Word16 bracket x | x < mri_lower_threshold = 0 @@ -59,7 +67,6 @@ bracket x r = numerator/denominator -{-# INLINE flip16 #-} flip16 :: Word16 -> Word16 flip16 xx = shift xx 8 .|. (shift xx (-8) .&. 0x00ff) @@ -69,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 @@ -112,30 +123,19 @@ 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) + + + +write_values_slice_to_bitmap :: Values2D -> FilePath -> IO () +write_values_slice_to_bitmap v3d path = + R.writeComponentsToBMP path routput goutput boutput + where + arr_bracketed = bracket_array v3d + colors = values_to_colors $ R.map fromIntegral arr_bracketed + routput = R.map (\(red, _, _) -> red) colors + goutput = R.map (\(_, green, _) -> green) colors + boutput = R.map (\(_, _, blue) -> blue) colors