ibezkrovnyi / image-quantization

Image Quantization Library with alpha support (based on https://github.com/leeoniya/RgbQuant.js, https://github.com/timoxley/neuquant and http://www.ece.mcmaster.ca/~xwu/cq.c)
137 stars 10 forks source link

some notes on naming #1

Closed leeoniya closed 2 years ago

leeoniya commented 9 years ago

@igor-bezkrovny, Here is some input on your naming conventions and possible renaming:

in readme sample:

paletteQuantizer -> paletteBuilder paletteQuantizer.quantize() -> paletteBuilder.build()

NearestNeighbour is a scaling method, so this name is not correct for this application, you should use another name. I was thinking maybe NearestColor, but even dithering methods use nearest color distance, maybe NoDither. I would also move all reducers to a Reducer namespace, so:

imageDitherer -> imageReducer (or imageQuantizer), because not all reduction strategies use dithering imageQuantizer.quantize -> imageReducer.quantize(pointContainer, palette) (or imageReducer.reduce(...))

new IQ.Image.NearestNeighbour(distanceCalculator) -> new IQ.Reducer.NearestColor(distanceCalculator)

for dithering you can use similar:

new IQ.Reducer.DitherDiffusion(distanceCalculator, kernel, strength,..) new IQ.Reducer.DitherOrdered(distanceCalculator, kernel,..) new IQ.Reducer.DitherPattern(distanceCalculator, kernel,..)

ibezkrovnyi commented 9 years ago

Hi Leon,

Thanks for your suggestions. It seems a global problem to name methods/classes in such way that user is able to use them intuitively.

I'm dreaming for web site where I can describe problem or insert piece of source code and take intuitive names :)

in readme sample: paletteQuantizer -> paletteBuilder paletteQuantizer.quantize() -> paletteBuilder.build()

Some additional research: 1) nQuant project: https://nquant.codeplex.com/ uses WuQuantizer class name for palette builder and palette-to-image applier.

However I think It is incorrect to say "Quantize Image" because image is not quantized by ditherers/palette appliers. Only palette (color) can be quantized. It is possible to say Quantize Image Colors, but in case of our libraries we have two separate processes (A. palette building, B. applying palette to image), so Quantize Image Colors is not useful for us.

2) ImageMagik: http://www.imagemagick.org/Usage/quantize/#dither color quantization, and what is used internally for all automatic color reduction

so, color quantization/color reduction phrases are used

3) Google A. Phrase "palette builder": It looks like this phrase most often used for color scheme builders

B. Phrases "palette quantizer" / "color quantizer" / "image quantizer" looks more appropriate.

So, I prefer to stay with "paletteQuantizer" naming

new IQ.Image.NearestNeighbour(distanceCalculator) -> new IQ.Reducer.NearestColor(distanceCalculator)

You are right! (for example, http://docs.gimp.org/en/glossary.html, Quantization paragraph)

imageDitherer -> imageReducer (or imageQuantizer), because not all reduction strategies use dithering imageQuantizer.quantize -> imageReducer.quantize(pointContainer, palette) (or imageReducer.reduce(...))

Good catch about ditherer! However imageReducer sounds for me like image dimensions reducer. For imageQuantizer please see above.

So I see some options here: imageDither -> imageColorReducer imageDither -> paletteToImageApplier imageDither -> paletteApplier

But both options looks ugly for me, may be you can suggest something better

What do you think?

Many Thanks

ibezkrovnyi commented 6 years ago

Hey Leon,

1st - thanks again for RgbQuant, without it Image-Quantization library was not possible I think :) Also thanks for beautiful picture I took for my README.md and for your support at times when github allowed to write personal private messages :)

Answering on https://github.com/ibezkrovnyi/image-quantization/pull/11#issuecomment-366856348: Personally I don't like Builder for reasons in book https://www.amazon.com/dp/0132350882.

Some research

neuquant

all variations use the same function names of original implementation

while class or entry function is always NeuQuant

wuquant

Here quantization/quantizer/quantized words are used everywhere. Class is named as WuQuantizer and function is GetQuantizedPalette.

Btw, re using colormap instead of palette: color map is just palette

In both 2 cases above:

  1. the have word "quant" shortening for "quantizer" or more general "quantization" is ok to use
  2. wikipedia: "Popular modern color quantization algorithms include the nearest color algorithm (for fixed palettes), the median cut algorithm, and an algorithm based on octrees."

I hope I get your point right.

p.s. still confused that guide styles say me to rename: NeuQuant (not changed) - Neu is in Pascal Case RGBQuant (from RgbQuant) - Because RGB is initialism

p.p.s. may be you have more ideas on project? What do you think about progress notification?

leeoniya commented 6 years ago

p.p.s. may be you have more ideas on project? What do you think about progress notification?

i think this project (as all image processing) is ripe for asm.js, WASM or something like http://evanw.github.io/thinscript/, http://gpu.rocks/, https://github.com/turbo/js rather than progress notifications (which would be unnecessary if perf was suddenly 10x ;)

ibezkrovnyi commented 6 years ago

@leeoniya for me it is possibility to finally use ES6 generators, ha-ha)

Re tools you mentioned, there is also https://github.com/AssemblyScript/assemblyscript (which is modified TypeScript which (with some assumptions) will generate WebAssembly (because of types presence)

Re asm.js and wasm:

But main reason is:

performance is not so important if we are using library not in real time, but as automated tool to reduce colors in our image assets for example, or e.g. we are using it in another tool (like https://github.com/ibezkrovnyi/texturer)

ibezkrovnyi commented 6 years ago

@leeoniya hm, need to investigate turbo.js and gpu.js :) Thanks!

ibezkrovnyi commented 6 years ago

Regarding Rust or WASM: Maybe you don't need Rust and WASM to speed up your JS