@@ -84,6 +84,8 @@ def sdh_analysis(
8484 load_cellpose ,
8585 load_sdh_model ,
8686 run_cellpose ,
87+ label2rgb ,
88+ blend_image_with_label ,
8789 )
8890 from .SDH_analysis import run_sdh_analysis
8991 import numpy as np
@@ -183,6 +185,13 @@ def sdh_analysis(
183185 result_df , full_label_map , df_cellpose_details = run_sdh_analysis (
184186 image_ndarray_sdh , model_SDH , mask_cellpose
185187 )
188+ if export_map :
189+ console .print ("Blending label and original image together ! " , style = "blue" )
190+ labelRGB_map = label2rgb (image_ndarray_sdh , full_label_map )
191+ overlay_img = blend_image_with_label (image_ndarray_sdh , labelRGB_map )
192+ overlay_filename = image_path .stem + "_label_blend.tiff"
193+ overlay_img .save (output_path / overlay_filename )
194+
186195 console .print ("Analysis completed ! " , style = "green" )
187196 table .add_column ("Feature" , justify = "left" , style = "cyan" )
188197 table .add_column ("Raw Count" , justify = "center" , style = "magenta" )
@@ -217,7 +226,6 @@ def sdh_analysis(
217226 console .print (
218227 f"Labelled image saved as { output_path / label_map_name } " , style = "green"
219228 )
220- painted_img_name = image_path .stem + "_painted.tiff"
221229 console .print ("--- %s seconds ---" % (time .time () - start_time ))
222230
223231
@@ -308,6 +316,8 @@ def he_analysis(
308316 load_stardist ,
309317 run_cellpose ,
310318 run_stardist ,
319+ label2rgb ,
320+ blend_image_with_label ,
311321 )
312322 from .HE_analysis import run_he_analysis
313323 import numpy as np
@@ -358,6 +368,7 @@ def he_analysis(
358368 console .print ("Reading image..." , style = "blue" )
359369
360370 image_ndarray = imread (image_path )
371+
361372 if fluo_nuc is not None :
362373 fluo_nuc_ndarray = imread (fluo_nuc )
363374
@@ -379,6 +390,9 @@ def he_analysis(
379390 image_ndarray = image_ndarray * mask_ndarray
380391 if fluo_nuc is not None :
381392 fluo_nuc_ndarray = fluo_nuc_ndarray * mask_ndarray
393+ if fluo_nuc is not None :
394+ mix_cyto_nuc = np .maximum (image_ndarray , fluo_nuc_ndarray )
395+
382396 console .print (f"Masking done." , style = "blue" )
383397 console .print ("Image loaded." , style = "blue" )
384398 console .print ("Starting the Analysis. This may take a while..." , style = "blue" )
@@ -425,6 +439,17 @@ def he_analysis(
425439 result_df , full_label_map , df_nuc_analysis , all_nuc_df_stats = run_he_analysis (
426440 image_ndarray , mask_cellpose , mask_stardist , eccentricity_thresh
427441 )
442+ if export_map :
443+ console .print ("Blending label and original image together ! " , style = "blue" )
444+ if fluo_nuc is not None :
445+ labelRGB_map = label2rgb (mix_cyto_nuc , full_label_map )
446+ overlay_img = blend_image_with_label (mix_cyto_nuc , labelRGB_map , fluo = True )
447+ else :
448+ labelRGB_map = label2rgb (image_ndarray , full_label_map )
449+ overlay_img = blend_image_with_label (image_ndarray , labelRGB_map )
450+ overlay_filename = image_path .stem + "_label_blend.tiff"
451+ overlay_img .save (output_path / overlay_filename )
452+
428453 console .print ("Analysis completed ! " , style = "green" )
429454 table .add_column ("Feature" , justify = "left" , style = "cyan" )
430455 table .add_column ("Raw Count" , justify = "center" , style = "magenta" )
@@ -447,6 +472,11 @@ def he_analysis(
447472 f"Summary Table saved as a .csv file named { output_path / csv_name } " ,
448473 style = "green" ,
449474 )
475+ if export_map :
476+ console .print (
477+ f"Overlay image saved as a .tiff file named { output_path / overlay_filename } " ,
478+ style = "green" ,
479+ )
450480 if export_stats :
451481 df_nuc_analysis .drop ("image" , axis = 1 ).to_csv (
452482 output_path / cell_details_name ,
@@ -469,7 +499,6 @@ def he_analysis(
469499 console .print (
470500 f"Labelled image saved as { output_path / label_map_name } " , style = "green"
471501 )
472- painted_img_name = image_path .stem + "_painted.tiff"
473502 console .print ("--- %s seconds ---" % (time .time () - start_time ))
474503
475504
0 commit comments