2013-02-08 3 views
2

간단한 가장자리 감지를 수행하기 위해 Java의 메소드로 작업 중입니다. 나는 한 픽셀에 두 개의 컬러 강도 차이를 가져오고 그 바로 아래 픽셀에 다른 색 농도를 적용하고 싶습니다. 내가 사용하고있는 그림은 검정색으로 검정색으로 칠해져 있습니다. 나는 현재의 방법이 내가 필요한 것을 계산하지 않고 있지만, 문제를 찾기 위해 무엇을 추적해야 하는지를 놓치고 있는지 확실하지 않다.간단한 가장자리 감지 방법 Java

public void edgeDetection(double threshold) 
{ 

    Color white = new Color(1,1,1); 
    Color black = new Color(0,0,0); 

    Pixel topPixel = null; 
    Pixel lowerPixel = null; 

    double topIntensity; 
    double lowerIntensity; 

    for(int y = 0; y < this.getHeight()-1; y++){ 
    for(int x = 0; x < this.getWidth(); x++){ 

     topPixel = this.getPixel(x,y); 
     lowerPixel = this.getPixel(x,y+1); 

     topIntensity = (topPixel.getRed() + topPixel.getGreen() + topPixel.getBlue())/3; 
     lowerIntensity = (lowerPixel.getRed() + lowerPixel.getGreen() + lowerPixel.getBlue())/3; 

     if(Math.abs(topIntensity - lowerIntensity) < threshold) 
     topPixel.setColor(white); 
     else 
     topPixel.setColor(black); 
    } 
    } 
} 

답변

4

new Color(1,1,1)가 잘 (0에서 255 사이의 값을 사용 ColorColor(int,int,int) 생성자 그래서 Color white 여전히 기본적으로 검은 색 호출 매우 어두운 회색,하지만 충분하지 : 여기

내 지금까지의 방법이다 고지).

Color white = new Color(1.0f,1.0f,1.0f); 
+0

가 나는 생성자의 설명서를 읽어보고 싶어요, 감사 : 당신이 Color(float,float,float) 생성자를 사용하려면

, 당신은 부동 소수점 리터럴이 필요합니다. –

0
public void edgeDetection(int edgeDist) 
    { 
Pixel leftPixel = null; 
Pixel rightPixel = null; 
Pixel bottomPixel=null; 
Pixel[][] pixels = this.getPixels2D(); 
Color rightColor = null; 
boolean black; 
for (int row = 0; row < pixels.length; row++) 
{ 
    for (int col = 0; 
     col < pixels[0].length; col++) 
    { 
    black=false; 
    leftPixel = pixels[row][col]; 
    if (col<pixels[0].length-1) 
    { 
     rightPixel = pixels[row][col+1]; 
     rightColor = rightPixel.getColor(); 
     if (leftPixel.colorDistance(rightColor) > 
      edgeDist) 
     black=true; 
    } 
    if (row<pixels.length-1) 
    { 
     bottomPixel =pixels[row+1][col]; 
     if (leftPixel.colorDistance(bottomPixel.getColor())>edgeDist) 
     black=true; 

    } 
    if (black) 
     leftPixel.setColor(Color.BLACK); 
    else 
     leftPixel.setColor(Color.WHITE); 
    } 
} 

}

관련 문제