FrancescoLR commited on
Commit
f5d2b82
·
verified ·
1 Parent(s): 887ad93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -167,10 +167,14 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180, center=
167
 
168
  # Choose colormap
169
  if label_components:
170
- # Build a modified Pastel colormap with 0 = black
171
- pastel = plt.cm.Pastel2(np.linspace(0, 1, 256))
172
- pastel[0] = np.array([0, 0, 0, 1]) # Set the first color (label 0) to black (RGBA)
173
- custom_cmap = mpl.colors.ListedColormap(pastel)
 
 
 
 
174
  cmap = custom_cmap # Colorful
175
  vmin = 0
176
  vmax = num_features
 
167
 
168
  # Choose colormap
169
  if label_components:
170
+ # Create 256 pastel colors
171
+ pastel = plt.cm.Pastel1(np.linspace(0, 1, 256))
172
+ np.random.seed(42) # For reproducibility
173
+ shuffled_colors = pastel[1:].copy()
174
+ np.random.shuffle(shuffled_colors)
175
+ final_colors = np.vstack([np.array([0, 0, 0, 1]), shuffled_colors])
176
+
177
+ custom_cmap = mpl.colors.ListedColormap(final_colors)
178
  cmap = custom_cmap # Colorful
179
  vmin = 0
180
  vmax = num_features