OpenBI Docs Buy

Image.Colors OpenBI

The dominant colours of a picture, as a table: rank, colour, name, how many pixels and their share.

Group: Images and colours. OpenBI’s own: Power Query M has no function of this name.

Syntax

Image.Colors(image as any, optional options as nullable record) as table
ParameterTypeDescription
imageanyThe image's bytes (File.Contents, Web.Contents), or text: an http:// or https:// address, a data: URI or base 64.
optionsnullable record
optional
Count (how many colours, 1 to 50; 9), ExcludeWhite and ExcludeBlack (leave near-white and near-black pixels out; both true), WhiteTolerance and BlackTolerance (how near, 0 to 255; 20).

Returns

table. A row per colour, the most pixels first: Rank, Color (written #RRGGBB), its Name, its Red, Green and Blue, Pixels and Share; null for a null image.

Remarks

  • The pixels are grouped by k-means into as many colours as Count asks for (fewer when the picture has fewer), and each group's average colour gets the name of the closest colour in a list of named colours (CSS's and more, wine colours among them). Transparent pixels never count.
  • Share is of the pixels counted: those left out as white or black don't count.
  • JPEG, PNG, GIF and BMP pictures are read.
  • In Table.AddColumn over a table of picture addresses, the pictures are fetched and their colours found several at a time, then each row reads its own. Table.ExpandTableColumn makes a row per colour.

Compared with Power Query

An OpenBI function: Power Query has none like it, so a query that uses it runs in OpenBI only, not in Power BI Desktop or the Power BI service.

Examples

A swatch's colours

The picture is 10 by 10 pixels: 60 wine red, 30 gold and 10 white.

Image.Colors(File.Contents("C:\Data\swatch.png"))
RankColorNameRedGreenBluePixelsShare
1#7B2D3Bwine1234559600.6666666666666666
2#D4A017goldenrod21216023300.3333333333333333

The white pixels are left out, so the two colours share what is left: two thirds and one third.

White counted too

Image.Colors(File.Contents("C:\Data\swatch.png"), [ExcludeWhite = false, Count = 3])
RankColorNameRedGreenBluePixelsShare
1#7B2D3Bwine1234559600.6
2#D4A017goldenrod21216023300.3
3#FFFFFFwhite255255255100.1

Image.Color, Color.Name, File.Contents, Table.ExpandTableColumn.

Last updated · OpenBI Studio 0.3.79