How do I exclude white from this scenario

The code im working with is https://pastebin.com/3tgBn4bp
Which is currently taking 3 mini images and applying them to a larger image (a picture of a hand)
https://imgur.com/a/0Y5s9
(the 3 test mini images are transparent, so drag them from imgur, they are currently black)
My output currently looks like: http://imgur.com/a/rmLQc
The background of the hand picture is white, and I dont want my mini images to be assigned to it. How do I exclude white in this scenario? (Or just assign the mini-images to the hand)
Thankyou for the help. Im very new at processing.

Answers

  • Consider the following code:

      float pixelBrightness = brightness(pixelValue); 
      float imgPicked=constrain(pixelBrightness/thresh, 0, n-1);
      image(imgContainer.get((int)imgPicked),x,y);
    

    where n is the number of images. A modification of this code to identify and ignore white is instead:

    color rgb = pixelValue;
    int r = (rgb >> 16) & 0xFF;  // Faster way of getting red(argb)
    int g = (rgb >> 8) & 0xFF;   // Faster way of getting green(argb)
    int b = rgb & 0xFF;  
    
    //How far is the current color from white
    dista=dist(r,g,b,255,255,255);
    
    //50 is a threshold value allowing close to white being identified as white
    //This value needs to be adjusted based on your actual background color
    //Next block is processed only if the pixel not white
    if(dista>50){    
          float pixelBrightness = brightness(pixelValue); 
          float imgPicked=constrain(pixelBrightness/thresh, 0, n-1);
          image(imgContainer.get((int)imgPicked),x,y);
    }
    

    Notice I have to work with directly with the color values as brightness is not an indicative of how white something is. Brightness is better interpreted in the HSB color scale and only when considering the hue and saturation values together.

    Kf

  • Hey thanks for getting back to me. I couldnt get past the error on your other answer. This looks far simpler. Im getting "dista cannot be resolved to a variable" ?

  • Right, my code is just a partial solution that needs to be implemented in your code. In the reference, dist() is described: https://processing.org/reference/dist_.html

    You can see it returns a float. So to solve the problem, you need to provide a definition to dista:

    float dista=dist(r,g,b,255,255,255);

    Regarding the other post, you were working two different questions in the same post. You need to figure out the python code first, and sorting the files into the different folders, before addressing the second question. When you have your mini-images destination folder all sorted out, then you can create a second post to address that question. Sorry I didn't follow your post, but it become too long and I can't follow it as I don't use python yet. I can see you have something going with GoToloop and I am looking forward to see the end result if possible.

    Kf

  • edited July 2017

    Well hot damn, it works!! http://imgur.com/a/AOfGI
    with different segments, different image: http://imgur.com/a/xNTR2
    different values: http://imgur.com/a/Vri2f

    Yeah it got pretty long there, and youre right for sure I definitly should have started with this sketch before trying to combine it with the python image segmentation...got a bit ahead of myself.

    Yes, it would be cool to compile it on github for anyone thats interested in this kind of thing.

    A full update with both sketches: https://pastebin.com/ELkYDbhF
    and a video:
    -need to change PImage to accept the most recent test_segments folder created
    -need to change sketch 2's PImage path to accept only the first 50 of the test segments (the segmentation seems to get smaller the more segments there are, which wont look as aesthetic)
    -need to combine sketch 2 with sketch 1 to share the same data folder

  • @Kfrajer Im wondering, is there a way I can select only the first 50 segments from the test_segments folder that is created within my sketch's data folder? Right now it creates more than 100 each time.

  • Hi @daddydean It is possible and it should be easy to implement to load only 50 if there are more than 50 available. I am looking at this code of yours: https://pastebin.com/7UiPUxZ6

    Is that your latest version? Is that the one you want to modify?

    Kf

  • edited July 2017

    Yes thats the one. The weird thing is that right now even though I have 3 segments in PImage, it is only using 1 of them. So its not applying all 3. I've tried alot but I cant figure it out. But yes, the first 50 would be ideal. Right now its only choosing 1. Here is the hand and the first 3 segments: http://imgur.com/a/FmIxv (they are black because they are transparent, so you can drag em from imgur)

  • Ok, I suggest we move any further discussion to https://forum.processing.org/two/discussion/23607/using-pimage-to-pick-a-random-image-from-a-folder-of-images#latest as you are asking the same question. We advise not to create duplicate posts as it creates confusion.

    Kf

  • Sorry about that. Either picking the first 50, or picking at random...whichever works better...it'd be cool to try both.

Sign In or Register to comment.