How to find min X and Y of pixel

Hello,

I want to make a program that finds the object in the picture.
I decided that it would be easiest to recognize it by color, because the background under the object could have any other color.

So far I managed to do it, but I don’t know what to do next …

The program filters pixels from the palette I have defined and the rest is changed to black.

Now I need to find the corners of the object that remained. To this end, I thought that the program should find X and Y of the remaining pixels (excluding black).

Respectively:
min X, min Y
max X, min Y

min X, max Y
max X, max Y

I add photos of what I stood on and I can’t handle it.

the effect I wants to get

My code:

PImage zdj;


void setup(){
 size(1024, 768);
 zdj = loadImage("t7.png");
 colorMode(HSB);
}


void draw() {
  loadPixels();
  zdj.loadPixels();
  

  for (int x = 0; x < width; x++) {
    
    for (int y = 0; y < height; y++) {
      

      int loc = x+y*width;
      
     
      color c = (zdj.pixels[loc]);
      float h = hue(c);
      float s = saturation(c);
      float b1 = brightness(c);
      
      pixels[loc] = zdj.pixels[loc];
      //pixels[loc] = color(test, g, b);
      
      boolean q = h < 30;
      
       int mx = 0;
       int my = 0;
       
       int minX = pixels[loc];
       
       int pix2 = color(0);

     
      if (h > 70){
       
        pixels[loc] = color(0);

        
      }
      
      if (h < 0){
       
        pixels[loc] = color(0);
        
        
      }
      
      if (b1 < 5){
        
        pixels[loc] = color(0);
        
      }
     
     if (s < 0){
        
        pixels[loc] = color(0);
        
      }

      if (pixels[loc] != 0){



      }

       color black = color(0);

       if (pixels[loc] != black){

       }
    }
  }
  updatePixels();
}

Please help.

Hi @Morzin,

I have few questions regarding your project:

  • Do you want the “corners” to be the one of the lightest part of your object or also including the darker part
  • What other kind of object do you have to do that for?
  • Are all your object convex?
  • What do you want to do with it after?

Answering those questions can help us guiding you on how to do it.

Thanks for interest.

Ideally, the corners should be on the border of light pixels with dark ones as in the picture:

Its just a wood

In real it just looked that:

Finally, I would like the points to connect two vertical lines indicating the edges (the bright ones) of the object.

Something like that:

Do you have other example of images you want to post process? Do they all have dark and light areas splited with straight lines like in your example? And what do you want to do with it afterwards?

All objects look very similar.

I have to do exactly what I wrote above

that’s my new code:


IntList inventoryX;
IntList inventoryY;

PImage zdj;



void setup(){
  
  
  
 size(1024, 768);
 zdj = loadImage("i7.jpg");
 colorMode(HSB);
 
 
 
}


void draw() {
 

  
  //stroke(255,200,200);
  //      strokeWeight(200);
  //      point(350,500);
        
        
  loadPixels();
  zdj.loadPixels();
  




  for (int x = 0; x < width; x++) {
    
    for (int y = 0; y < height; y++) {
      

      int loc = x+y*width;
      
   
     
     
      color c = (zdj.pixels[loc]);
      float h = hue(c);
      float s = saturation(c);
      float b1 = brightness(c);
      
      pixels[loc] = zdj.pixels[loc];
      //pixels[loc] = color(test, g, b);
     
 
 
      if (h > 70){
       
        pixels[loc] = color(0);
   
   
 
        
      }
      
      if (h < 0){
       
        pixels[loc] = color(0);
        
        
      }
      
      if (b1 < 5){
        
        pixels[loc] = color(0);
        
      }
     
     if (s < 0){
        
        pixels[loc] = color(0);
        
      }

      
      
      
   
       color black = color(0);
       float newX = 0;
       float newY = 0;

       
       if (pixels[loc] != black){
         
        
       
         if (mousePressed) {
           
           
           
           inventoryX = new IntList();
           inventoryY = new IntList();
           inventoryX.append(min(x,x));
           inventoryY.append(min(y,y));
           
        //println(inventoryX);
        //  println(inventoryY);
           

   
        println(min(x,x), min(y,y));
        //println(max(x,x), min(y,y));
        //println(min(x,x), max(y,y));
        //println(max(x,x), max(y,y);
          
           //newX += x;
           //newY += y;

         }

       }
 
    }
  }
  
  updatePixels();

}


still not working but i don’t know why …

maybe someone can help me ;c

Hi @Morzin,

What you can do is used an hough line detector or a corner detector.

I did some quick test and manage to find those points of interests:

As you can see, your 4 points appears in but option I tried but the tricky part is now to actualy extract them from that set of options.

Now, once again the process to really extract those points will greatly depends on how similar your shapes are.

You say they are similar but what does it means? Are they all sheared rectangles? Are they all sheared to the right? Is the background always the same? Is there always a dark edge?

Without seeing more of the pictures you want to extract it will be quite hard to help you exracting those 4 corner points.