- let out_file = "output.bin"
- arr <- read_word16s in_file
- let arr' = swap_bytes arr
- let arrMRI = R.reshape mri_shape arr'
- let dbl_data = R.force $ R.map fromIntegral arrMRI
- let output = zoom dbl_data zoom_factor
- let word16_output = round_array output
- write_word16s out_file word16_output
-
-
-main2d :: IO ()
-main2d = do
- (s:_) <- getArgs
- let scale = read s :: Int
- let zoom_factor = (1, scale, scale)
- let out_file = "output.bmp"
- arr <- read_word16s in_file
- let arr' = swap_bytes arr
- let arrInv = flip_x $ flip_y arr'
- let arrSlice = z_slice 50 arrInv
- let arrSlice' = R.reshape mri_slice3d arrSlice
- let dbl_data = R.map fromIntegral arrSlice'
- let output = zoom dbl_data zoom_factor
- write_values_slice_to_bitmap (z_slice 0 output) out_file
+ arr <- read_word16s input shape
+ let arr_swapped = swap_bytes arr
+ let arr_shaped = R.reshape shape arr_swapped
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arr_shaped
+ raw_output <- zoom dbl_data zoom_factor
+ let word16_output = round_array raw_output
+ -- Switch the bytes order back to what it was. This lets us use the
+ -- same program to view the input/output data.
+ swapped_output <- R.computeUnboxedP $ swap_bytes word16_output
+ write_word16s output swapped_output
+
+
+main2d :: Args -> R.DIM3 -> IO ()
+main2d Args{..} shape = do
+ let zoom_factor = (1 :: Int, scale, scale)
+ arr <- read_word16s input shape
+ arrSlice <- R.computeUnboxedP
+ $ z_slice (fromJust slice)
+ $ flip_x width
+ $ flip_y height
+ $ swap_bytes arr
+ let arrSlice' = R.reshape slice3d arrSlice
+
+ -- If zoom isn't being inlined we need to extract the slice before hand,
+ -- and convert it to the require formed.
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrSlice'
+ raw_output <- zoom dbl_data zoom_factor
+ arrSlice0 <- R.computeUnboxedP $ z_slice 0 raw_output
+
+ -- Make doubles from the thresholds which are given as Ints.
+ let lt = fromIntegral lower_threshold :: Double
+ let ut = fromIntegral upper_threshold :: Double
+
+ let arr_bracketed = bracket_array lt ut arrSlice0
+ values <- R.computeUnboxedP $ R.map fromIntegral arr_bracketed
+ write_values_to_bmp output values
+
+ where
+ slice3d :: R.DIM3
+ slice3d = (R.Z R.:. 1 R.:. height R.:. width)