I am missing some commands, so if you can help me - that would be awesome.
I want to creat a dynamic array, that stores the keypressed, and how many times each one pressed
for example, let’s say the user pressed the key L
if the user pressed the L key for the first time, I want add L,0 to the array
if the user pressed the L key for the third time, I want to change the objects from L,2 to L,3
You can use an IntList container for that: final IntList keyPressCount = new IntList();
Use its method increment() to increase the count of desired index which represents your pressed key: keyPressCount.increment('L'); // increase count to index L keyPressCount.increment(keyCode); // increase count to last pressed key
Call method get() in order to read current count for a specific key index: println(keyPressCount.get('L')); // read count for index L println(keyPressCount.get(keyCode)); // read count for last key pressed
Here’s a sample sketch using IntList and its methods increment() & get():
You can also use a HashMap. HashMaps can store things in pairs, like the key being pressed and the count. Here is the syntax:
HashMap<String, Integer> letters = new HashMap<String, Integer>();
You can loop through the HashMap to check whether the key being pressed matches one of the keys in the HashMap, and if it does, use the replace() method in the HashMap to alter the count of the number of times the key was pressed. You can check this by looping through the keySet in the HashMap by using the keySet() method. If the key pressed doesn’t match any of the items in the HashMap, then you can use the put() method to add a new value and count.
next step is to check for similar colors, means - if you find a color that is similar to another exist color (for example 100 distance) - refer it as it already existed (As I work on photograph and… Unique colors found: 141642 from: 663000
A color pixel in Processing is a 32-bit integer (24-bit if we disregard the alpha component):
Maybe you should consider converting from 24-bit to just 8-bit.
This way you’d have 256 colors instead of 16,777,216!
Red & green components would be converted from 8-bit (255 max) to a 3-bit (7 max) value.
While the blue component would be converted from 8-bit (255 max) to a 2-bit (3 max) value.
There are many tools and libraries focused on counting groups of colors in an image. In general, counting many colors as one color is called “color quantization”:
Related past discussion:
If you want to group colors using a strategy that maintains visual qualities of the original color space, perhaps start with Median Cut – we had a past conversation pointing to the Java implementation of Median Cut available from ImageJ. javax also has a ColorQuantizer.
OpenCV also has some quantization built-in via k-means clustering. There is a good discussion of approaches using OpenCV here:
I’m guessing that is what you mean – rather than using a stock palette, you want to adaptively choose a small number of colors that best approximate the appearance of your original image. Is that right?
I want to reduce the number of the colors, in order to change it style.
if I need to reduce from 110K to 50K, or any change below 80K will spoil the image? I don’t know yet.
Maybe I can reduce it to 30K or even to 12K and it still look similar to the original ? I don’t know yet
Will have to run some tests, to find the right number