@@ -434,10 +434,29 @@ def _render_images(
434
434
if render_params .cmap_params [i ].norm is not None :
435
435
layers [c ] = render_params .cmap_params [i ].norm (layers [c ])
436
436
437
- # 2A) Image has 3 channels, no palette/cmap info -> use RGB
438
- if n_channels == 3 and render_params .palette is None and not got_multiple_cmaps :
437
+ # 2A) Image has 3 channels, no palette info, and no/only one cmap was given
438
+ if n_channels == 3 and render_params .palette is None and not isinstance (render_params .cmap_params , list ):
439
+ if render_params .cmap_params .is_default : # -> use RGB
440
+ stacked = np .stack ([layers [c ] for c in channels ], axis = - 1 )
441
+ else : # -> use given cmap for each channel
442
+ channel_cmaps = [render_params .cmap_params .cmap ] * n_channels
443
+ # Apply cmaps to each channel, add up and normalize to [0, 1]
444
+ stacked = (
445
+ np .stack ([channel_cmaps [i ](layers [c ]) for i , c in enumerate (channels )], 0 ).sum (0 ) / n_channels
446
+ )
447
+ # Remove alpha channel so we can overwrite it from render_params.alpha
448
+ stacked = stacked [:, :, :3 ]
449
+ logger .warning (
450
+ "One cmap was given for multiple channels and is now used for each channel. "
451
+ "You're blending multiple cmaps. "
452
+ "If the plot doesn't look like you expect, it might be because your "
453
+ "cmaps go from a given color to 'white', and not to 'transparent'. "
454
+ "Therefore, the 'white' of higher layers will overlay the lower layers. "
455
+ "Consider using 'palette' instead."
456
+ )
457
+
439
458
im = ax .imshow (
440
- np . stack ([ layers [ c ] for c in channels ], axis = - 1 ) ,
459
+ stacked ,
441
460
alpha = render_params .alpha ,
442
461
)
443
462
im .set_transform (trans_data )
0 commit comments