Comments (6)
@pducks32 I was thinking about it the same way that the android material library implements it. It's the swatch with the highest pixel population.
I am sorry, i don't understand enough about how the algorithm works to offer a suggestion as to how best to go about it. If it helps, what I'm doing right now to get it is this:
Pailead.extractTop(12, from: image) { swatches in
let sortedSwatches = swatches.sorted(by: { (swatchA, swatchB) -> Bool in
swatchA.count > swatchB.count
})
let topSwatch = sortedSwatches.first!
let color = topSwatch.color
}
from pailead.
The problem is what is a dominant color. If you mean the most common color we’ll then you need to choose a dithing size. If you mean the average color well that depends on how many V boxes you use. If you use 1 the average color is most likely a slightly blueish grey based on statistics.
How ever if you say well I want 10 boxes but I just want the top color can I save some computation time? The answer there is no you need to find all 10 boxes first so only pulling out the top color versus pulling up the top 10 colors and calling .first
is a minimal if zero performance gain.
Do you see a usecase I can help find the most performant way of doing it? Maybe explain the exact thing you want to do and what you don’t want to do?
Sent with GitHawk
from pailead.
Android uses a default bucket size of 16. I could provide a dominant color extension but the top level API would be similar to what you have. Let me write it down.
Sent with GitHawk
from pailead.
So basically imagine 9 squares and each square is a different color. Then if you set the bucket size to 1 then you’re average color is grey. If you set it to 9 you’re average color does not exist. You have 9 buckets all of equal population. On one hand I do not want to gloss over this to a user but on the other hand I want the API to work well and I think the usecase you mention is a very popular one.
Pailead.extractTop(12, from: image).dominantColor
extension Collection where Element == Swatch {
var dominantColor : Color? {
return max(by: { $0.count })?.color
}
}
Now I do some things by default. For example I remove all colors of the form rgb(X, X, X) | x ∈ 0...255
so whites and blacks and greys but that does not prevent the average color from being grey (though it is hard to get from a real picture). (This is ostensibly one reason Apple Music stopped using these for their font and background color)
If you have any experience with HSL colors then I would recommend you take out the swatch with a high luminance. Knowing your usecase this may be better than just pulling out the dominant color. Humans do not notice the dominant color they notice the most adjacent color.
Sent with GitHawk
from pailead.
Thanks for the info - yeah an extension like that makes sense. So you're suggesting getting the most dominant swatch as long as its not the most luminant? Would you provide that in the library?
from pailead.
I just wrote some documentation on how to do this with examples and will publish it. What I would do is probably use the vibrant swatch for your use case. But it depends on what your images are if there are many colors it may be useful to use more buckets which the API supports and then find that with the highest saturation and a medium luminance. Again I will publish this and am more than happy to look at any examples you have to help you find what you need
from pailead.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pailead.