Edge detection

edited June 2014 in Questions about Code

Hello everyone

I need to add a button to a picture, so when i press it, it does edge detection on the image. I tried using convolution matrix but i could not get it to work..! Right now this is what i have for the first two buttons, and they work just fine:

PImage billed;
int aktueltFilter = -1;

void setup() {
  billed = loadImage("påfugl.jpg");
  size(billed.width, billed.height+50);
}

void draw() {  
    knap(0,"Stoej");
    knap(1,"Pixelering"); 
    knap(2, "EdgeDetection");
    if(aktueltFilter == 0){
      stoej();
    }else if(aktueltFilter == 1){
      pixelering();
    }else if(aktueltFilter == 2){
      EdgeDetection();
    }else{
      image(billed, 0, 0);
    }
}

void mouseClicked() {
      if(aktueltFilter == 0){
      stoej();
    }else if(aktueltFilter == 1){
      pixelering();
    }else if(aktueltFilter == 2){
      EdgeDetection();
    }else{
      image(billed, 0, 0);
    }
}    

void knap(int nr, String tekst){
  int knapBredde=100;
  int knapHoejde=20;
  int knapY=billed.height+10;

   fill(50);
   rect(nr * knapBredde+5, knapY, knapBredde, knapHoejde); 

   fill(255);
   text(tekst, nr * knapBredde+10, knapY+15);

   if(mousePressed == true
      && nr * knapBredde < mouseX 
      && mouseX < (nr+1) * knapBredde 
      && knapY < mouseY           
      && mouseY < knapY+knapHoejde)
   { 
     aktueltFilter = nr; 
   }
}


void stoej(){
  for(int y = 0; y < billed.height; y = y + 1){
    for(int x = 0; x < billed.width; x = x + 1){
      int nyX = x + int(random(10));
      color hentFarve = billed.get(nyX, y);
      set(x, y, hentFarve);
    }
  }
}

//Ændring af form
void pixelering(){
  int stoerrelse = 10;
  for(int y = 0; y < billed.height; y = y + stoerrelse){
    for(int x = 0; x < billed.width; x = x + stoerrelse){
      fill(billed.get(x, y));
      stroke(billed.get(x, y));
      rect(x, y, stoerrelse, stoerrelse);      
    }
  }
}

It looks like this:

processing question

Would really appreciate any help with adding this feature, since i have no idea what i am doing at this point..

Thanks - Iaften

Answers

Sign In or Register to comment.