Skip to content

Commit e38023b

Browse files
committed
Guess if image is mask
1 parent 37bf37d commit e38023b

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/app.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::error;
2-
3-
use crate::{utils, widgets};
41
use crate::utils::argminmax2::MinMax2;
2+
use crate::{utils, widgets};
3+
use std::error;
54

65
/// Application result type.
76
pub type AppResult<T> = std::result::Result<T, Box<dyn error::Error>>;
@@ -41,6 +40,18 @@ impl App {
4140
let increment = volume.world_bounds.size().minmax2().0 / 24.0;
4241
let metadata = utils::metadata::make_metadata_key_value_list(&volume.header);
4342
let duration = start.elapsed();
43+
44+
// Guess whether image is a mask or not
45+
let color_map = if utils::metadata::nifti_type_is_integer(
46+
volume.header.data_type().unwrap_or(nifti::NiftiType::Uint8),
47+
) && intensity_range.0 < 1.0e-7
48+
&& (intensity_range.1 - 1.0).abs() < 1.0e-7
49+
{
50+
utils::colors::ColorMap::Greys
51+
} else {
52+
utils::colors::ColorMap::Inferno
53+
};
54+
4455
println!("Data loaded in: {:?}", duration);
4556

4657
Self {
@@ -52,7 +63,7 @@ impl App {
5263
slice_position: middle_slice,
5364
increment: increment,
5465
mode: AppMode::Xyz,
55-
color_map: utils::colors::ColorMap::Greys,
66+
color_map: color_map,
5667
color_mode: color_mode,
5768
metadata: metadata,
5869
metadata_index: 0,

src/utils/metadata.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,19 @@ pub fn make_metadata_key_value_list(
8989
format!("{},{},{}", header.quatern_x, header.quatern_y, header.quatern_z),
9090
),
9191
]
92+
}
93+
94+
95+
pub fn nifti_type_is_integer(t: nifti::NiftiType) -> bool {
96+
match t {
97+
nifti::NiftiType::Int8 => true,
98+
nifti::NiftiType::Int16 => true,
99+
nifti::NiftiType::Int32 => true,
100+
nifti::NiftiType::Int64 => true,
101+
nifti::NiftiType::Uint8 => true,
102+
nifti::NiftiType::Uint16 => true,
103+
nifti::NiftiType::Uint32 => true,
104+
nifti::NiftiType::Uint64 => true,
105+
_ => false,
106+
}
92107
}

0 commit comments

Comments
 (0)