why does it not pick the green
in
Programming Questions
•
4 months ago
I try to get all the green from the image at the bottom of this post.
For some reason i can't get the inner colors of the ellipse.
If i check the color in photoshop then there around r=37, g=249, b=20.
I have 2 colors for the range, g_bright and g_dark, look in setup.
The color described above is in this range.
I checked my code multiple times but i don't get it.
Can someone take a look.
If you uncomment the last line in setup then you can see black and white what colors where accepted.
- PImage img;
- int[] preparePixelBuffer;
- void setup() {
- img = loadImage("blobTestImage_dark_139.png");
- size(img.width, img.height);
- preparePixelBuffer = new int[width*height];
- color g_bright = color(0, 255, 0);
- color g_dark = color(50, 100, 50);
- findBlobsWithColorRange(img.pixels, g_bright, g_dark);
- //img.pixels = preparePixelBuffer;
- }
- void draw() {
- image(img, 0, 0);
- }
- void findBlobsWithColorRange(int[] pix_array, int color1, int color2) {
- System.arraycopy(pix_array, 0, preparePixelBuffer, 0, pix_array.length);
- float r1 = red(color1);
- float r2 = red(color2);
- float g1 = green(color1);
- float g2 = green(color2);
- float b1 = blue(color1);
- float b2 = blue(color2);
- float minR = min(r1, r2);
- float maxR = max(r1, r2);
- float minG = min(g1, g2);
- float maxG = max(g1, g2);
- float minB = min(b1, b2);
- float maxB = max(b1, b2);
- float r, g, b;
- for (int i = 0; i < pix_array.length; i++) {
- r = red(pix_array[i]);
- g = green(pix_array[i]);
- b = blue(pix_array[i]);
- if (r >= minR && r <= maxR && g >= minG && g <= maxG && b >= minB && b <= maxB) {
- preparePixelBuffer[i] = MAX_INT;
- } else {
- preparePixelBuffer[i] = 0;
- }
- }
- //findBlobs(preparePixelBuffer, w, this.h);
- }
1