]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Main.hs
1a716836c5db52096e7c15e6caaf45e307ba83cc
[spline3.git] / src / Main.hs
1 module Main
2 where
3
4 import qualified Data.Array.Repa as R
5 import System.Environment (getArgs)
6
7 import Grid (zoom)
8 import MRI (
9 flip_x,
10 flip_y,
11 mri_shape,
12 mri_slice3d,
13 read_word16s,
14 round_array,
15 swap_bytes,
16 write_values_slice_to_bitmap,
17 write_word16s,
18 z_slice
19 )
20
21 in_file :: FilePath
22 in_file = "./data/mri.bin"
23
24
25 main :: IO ()
26 main = main3d
27
28 main3d :: IO ()
29 main3d = do
30 (s:_) <- getArgs
31 let scale = read s :: Int
32 let zoom_factor = (scale, scale, scale)
33 let out_file = "output.bin"
34 arr <- read_word16s in_file
35 let arr' = swap_bytes arr
36 let arrMRI = R.reshape mri_shape arr'
37 dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrMRI
38 output <- zoom dbl_data zoom_factor
39 word16_output <- R.computeUnboxedP $ round_array output
40 write_word16s out_file word16_output
41 return ()
42
43
44 main2d :: IO ()
45 main2d = do
46 (s:_) <- getArgs
47 let scale = read s :: Int
48 let zoom_factor = (1, scale, scale)
49 let out_file = "output.bmp"
50 arr <- read_word16s in_file
51 arrSlice <- R.computeUnboxedP $ z_slice 50 $ flip_x $ flip_y $ swap_bytes arr
52 let arrSlice' = R.reshape mri_slice3d arrSlice
53
54 -- If zoom isn't being inlined we need to extract the slice before hand,
55 -- and convert it to the require formed.
56 dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrSlice'
57 output <- zoom dbl_data zoom_factor
58 arrSlice0 <- R.computeUnboxedP $ z_slice 0 output
59
60 write_values_slice_to_bitmap arrSlice0 out_file