Skip to main content
. 2025 Jun 5;25(11):3572. doi: 10.3390/s25113572
Algorithm A3 Calculates the predominant color in a masked region
  •   1:

    function predominant_color( image , mask , label_to_segment )

  •   2:

        if  label_to_segmentmask  then

  •   3:

            raise ValueError

  •   4:

        end if

  •   5:

         mask_segment(mask==label_to_segment)

  •   6:

         masked_imageimage[mask_segment]

  •   7:

         masked_image_reduced(masked_image//32)32

  •   8:

         (colors,count)np.unique(masked_image_reduced.reshape(1,3),axis=0,return_counts=True)

  •   9:

         predominant_color_rgbcolors[count.argmax()]

  • 10:

        return get_color_name( tuple(predominant_color_rgb) )

  • 11:

    end function