IMAGECOLORS OpenBI
The colours of a picture at an address or a data: URI, the most used first, with their names and shares.
Group: Images and colours. OpenBI’s own: DAX has no function of this name.
Syntax
IMAGECOLORS ( <image> [, <count>] [, <skip_white>] [, <skip_black>] [, <white_tolerance>] [, <black_tolerance>] )
| Parameter | Type | Description |
|---|---|---|
image | Text | The picture: a data: URI (data:image/png;base64,...), its base64 text alone, or its address on the web (http:// or https://). |
count | Whole number optional | How many colours to look for, from 1 to 50; 9 when left out. |
skip_white | Boolean optional | TRUE, or left out, to leave near-white pixels out; FALSE to count them. |
skip_black | Boolean optional | TRUE, or left out, to leave near-black pixels out; FALSE to count them. |
white_tolerance | Whole number optional | How near to white a pixel must be to be left out as white, from 0 to 255; 20 when left out. |
black_tolerance | Whole number optional | How near to black a pixel must be to be left out as black, from 0 to 255; 20 when left out. |
Returns
Table. A row for each colour found, the one with the most pixels first. Its columns: Rank; the colour as Color (#RRGGBB) and its Name; its three parts as Red, Green and Blue; and how many of the pixels it stands for, as Pixels and as Share.
Remarks
- Pixels of similar colour are put together in as many groups as count says, and each group is shown by its average colour. With a small count that can be a colour no pixel has (example 3). A picture with fewer different colours gives fewer rows.
- Share is the group's part of the pixels that were counted, so leaving white or black out changes the shares (examples 1 and 2). Pixels that are mostly transparent are never counted.
- A pixel is left out as white when its red, green and blue are all above 255 minus the white tolerance: 236 or more with 20. It is left out as black when all three are below the black tolerance: 19 or less with 20. A tolerance of 0 leaves nothing out.
- Pictures in PNG, JPEG, GIF and BMP are read; WebP and SVG are errors. Files on the computer's disk are not read, only data: URIs, base64 text and web addresses.
- A blank or empty image gives an empty table. A text that is not a picture, or a picture with no pixel left to count, is an error.
- The same picture with the same options gives the same colours every time.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
The colours of a small picture
Four by two pixels: five fire brick, two gold and one white. White is left out, so the shares are of seven pixels. All eight columns, with Red, Green and Blue moved to the end.
EVALUATE
SELECTCOLUMNS (
IMAGECOLORS ( "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAAF0lEQVR42mPYpKQEQf+vMzDAWf///wcAfmYLeNgtE+UAAAAASUVORK5CYII=" ),
"Rank", [Rank],
"Color", [Color],
"Name", [Name],
"Pixels", [Pixels],
"Share", [Share],
"Red", [Red],
"Green", [Green],
"Blue", [Blue]
)
ORDER BY [Rank]
| Rank | Color | Name | Pixels | Share | Red | Green | Blue |
|---|---|---|---|---|---|---|---|
| 1 | #B22222 | fire brick | 5 | 0.714285714285714 | 178 | 34 | 34 |
| 2 | #FFD700 | gold | 2 | 0.285714285714286 | 255 | 215 | 0 |
White counted too
Only some of the columns are shown here.
EVALUATE
SELECTCOLUMNS (
IMAGECOLORS ( "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAAF0lEQVR42mPYpKQEQf+vMzDAWf///wcAfmYLeNgtE+UAAAAASUVORK5CYII=", 9, FALSE ),
"Rank", [Rank],
"Color", [Color],
"Name", [Name],
"Share", [Share]
)
ORDER BY [Rank]
| Rank | Color | Name | Share |
|---|---|---|---|
| 1 | #B22222 | fire brick | 0.625 |
| 2 | #FFD700 | gold | 0.25 |
| 3 | #FFFFFF | white | 0.125 |
One colour only
With a count of 1, all seven pixels make one group: its average is a colour no pixel has.
EVALUATE
SELECTCOLUMNS (
IMAGECOLORS ( "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAAF0lEQVR42mPYpKQEQf+vMzDAWf///wcAfmYLeNgtE+UAAAAASUVORK5CYII=", 1 ),
"Color", [Color],
"Name", [Name],
"Pixels", [Pixels]
)
| Color | Name | Pixels |
|---|---|---|
| #C85618 | burnt orange | 7 |