]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Main.hs
9742a1f096d5bc6e1ec6946e7b968eeb846a641e
[spline3.git] / src / Main.hs
1 module Main
2 where
3
4 import qualified Data.Array.Repa as R
5 import qualified Data.Array.Repa.IO.BMP as R (writeComponentsToBMP)
6 import System.Environment (getArgs)
7
8 import Grid (make_grid, zoom)
9 import MRI
10 import Values (drop_z, zoom_shape)
11
12 main :: IO ()
13 main = do
14 (s:_) <- getArgs
15 let scale = read s :: Int
16 let zoom_factor = (1, scale, scale)
17 let out_file = "output.bmp"
18 arr <- read_word16s in_file
19 let arr' = swap_bytes arr
20 let arrInv = flip_x $ flip_y arr'
21 let arrSlice = z_slice3 50 arrInv
22 let dbl_data = R.map fromIntegral arrSlice
23 let g = make_grid 1 dbl_data
24 let output = zoom g zoom_factor
25 let arrBrack = bracket_array output
26 print $ "arrBrack extent:" ++ (show $ R.extent arrBrack)
27 let arrBrack' = z_slice 1 arrBrack
28 print $ "arrBrack' extent:" ++ (show $ R.extent arrBrack')
29 let mri_slice2d = drop_z $ zoom_shape zoom_factor mri_slice3d
30 let colors = values_to_colors $ R.reshape mri_slice2d
31 $ R.map fromIntegral arrBrack'
32 let routput = R.map (\(red, _, _) -> red) colors
33 let goutput = R.map (\(_, green, _) -> green) colors
34 let boutput = R.map (\(_, _, blue) -> blue) colors
35 R.writeComponentsToBMP out_file routput goutput boutput
36
37
38 in_file :: FilePath
39 in_file = "./data/mri.bin"
40
41 main3d :: IO ()
42 main3d = do
43 (s:_) <- getArgs
44 let scale = read s :: Int
45 let zoom_factor = (scale, scale, scale)
46 let out_file = "output.bin"
47 arr <- read_word16s in_file
48 let arr' = swap_bytes arr
49 -- let arrInv = flip_x $ flip_y arr'
50 let arrMRI = R.reshape mri_shape arr'
51 let dbl_data = R.force $ R.map fromIntegral arrMRI
52 let g = make_grid 1 dbl_data
53 let output = zoom g zoom_factor
54 let word16_output = bracket_array output
55 write_word16s out_file word16_output
56
57 main2d :: IO ()
58 main2d = do
59 (s:_) <- getArgs
60 let scale = read s :: Int
61 let zoom_factor = (1, scale, scale)
62 let out_file = "output.bmp"
63 arr <- read_word16s in_file
64 let arr' = swap_bytes arr
65 let arrInv = flip_x $ flip_y arr'
66 let arrSlice = z_slice 50 arrInv
67 let arrSlice' = R.reshape mri_slice3d arrSlice
68 let dbl_data = R.map fromIntegral arrSlice'
69 let g = make_grid 1 dbl_data
70 let output = zoom g zoom_factor
71 let arrBrack = bracket_array output
72 let mri_slice2d = drop_z $ zoom_shape zoom_factor mri_slice3d
73 let colors = values_to_colors $ R.reshape mri_slice2d
74 $ R.map fromIntegral arrBrack
75 let routput = R.map (\(red, _, _) -> red) colors
76 let goutput = R.map (\(_, green, _) -> green) colors
77 let boutput = R.map (\(_, _, blue) -> blue) colors
78 R.writeComponentsToBMP out_file routput goutput boutput