3737 QWidget ,
3838)
3939from skimage .measure import block_reduce
40+ from matplotlib .colors import Colormap
4041
4142from cardiotensor .analysis .analysis_functions import (
4243 calculate_intensities ,
4546 save_intensity ,
4647)
4748from cardiotensor .utils .DataReader import DataReader
49+ from cardiotensor .colormaps .helix_angle import helix_angle_cmap
4850
4951
5052def np2pixmap (np_img : np .ndarray ) -> QPixmap :
@@ -63,6 +65,7 @@ def __init__(
6365 N_line : int = 5 ,
6466 angle_range : float = 20 ,
6567 image_mode : str = "HA" ,
68+ cmap : Colormap | str | None = None ,
6669 ) -> None :
6770 super ().__init__ ()
6871
@@ -114,6 +117,18 @@ def __init__(
114117 sys .exit (
115118 f"Invalid output mode: { self .image_mode } . Must be 'HA', 'IA', or 'FA'."
116119 )
120+
121+ # choose a default by mode
122+ if cmap is None :
123+ if image_mode in ("HA" , "IA" ):
124+ self .cmap = helix_angle_cmap # custom HA colormap (callable)
125+ else : # FA
126+ self .cmap = plt .get_cmap ("inferno" )
127+ elif isinstance (cmap , str ):
128+ self .cmap = plt .get_cmap (cmap )
129+ else :
130+ self .cmap = cmap
131+
117132
118133 if self .N_slice > self .data_reader .shape [0 ]:
119134 raise IndexError (
@@ -396,8 +411,8 @@ def load_image_to_gui(self, current_img: np.ndarray) -> None:
396411 current_img_bin = (current_img_bin + np .abs (minimum )) * (
397412 1 / (maximum - minimum )
398413 )
399- cmap = plt . get_cmap ( "hsv" )
400- current_img_rgb = cmap (current_img_bin )
414+
415+ current_img_rgb = self . cmap (current_img_bin )
401416 current_img_rgb = (current_img_rgb [:, :, :3 ] * 255 ).astype (np .uint8 )
402417
403418 gray_color = [128 , 128 , 128 ]
0 commit comments