Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

17
LINES

< > BotCompany Repo | #1027256 // dominant332colorsWithPercentage

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5388L/35K).

1  
// returns pairs (col332 [0-255], percentage of image)
2  
static LPair<Int, Double> dominant332colorsWithPercentage(RGBImage img) {
3  
  int[] array = histogram332_array(img);
4  
  new MultiSet<Int> ms;
5  
  int total = 0;
6  
  for i over array: {
7  
    int x = array[i];
8  
    ms.add(i, x); 
9  
    total += x;
10  
  }
11  
  double total2 = total /= 100;
12  
  ret map(ms.highestFirst(), col -> pair(col, doubleRatio(ms.get(col), total2)));
13  
}
14  
15  
static LPair<Int, Double> dominant332colorsWithPercentage(BufferedImage img) {
16  
  ret dominant332colorsWithPercentage(RGBImage(img));
17  
}

Author comment

Began life as a copy of #1024902

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027256
Snippet name: dominant332colorsWithPercentage
Eternal ID of this version: #1027256/3
Text MD5: 260d65e42a44927cc51b47a4e8196ead
Transpilation MD5: 4ed799ac441ae008707f425ec7169a10
Author: stefan
Category: javax / image analysis
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-26 20:53:46
Source code size: 561 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 101 / 158
Version history: 2 change(s)
Referenced in: [show references]