2014-09-04 4 views
0

BufferedImage를로드하고 HSB 색상 공간으로 전환하여 색상 보정을 한 다음 RGB 색상 공간으로 돌아가 결과를 표시합니다. HSB 색상 공간으로 만든 장방형이 효과가없는 것 같습니다. 나는 이클립스를 사용하고 있는데이 오류를 제공하지 않습니다Color.HSBtoRGB가 HSB 색상 공간을 변경하지 않습니다.

import java.awt.Color; 
import java.awt.image.BufferedImage; 

public class ImageOperations { 

    public static BufferedImage Threshold(BufferedImage img,int requiredThresholdValue) { 

     int height = img.getHeight(); 
     int width = img.getWidth(); 
     BufferedImage finalThresholdImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB) ; 

     int red = 0; 
     int green = 0; 
     int blue = 0; 

     float hue = 0; 
     float sat = 0; 
     float bri = 0; 

     int r = 0; 
     int b = 0; 
     int g = 0; 



     for (int x = 0; x < width; x++) { 
//   System.out.println("Row: " + x); 
      try { 

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

        //Get RGB values of pixels 
        int color = img.getRGB(x, y); 
        red = ImageOperations.getRed(color); 
        green = ImageOperations.getGreen(color); 
        blue = ImageOperations.getBlue(color); 

        //Convert to HSV color space 
        float[] hsb = new float[3]; 
        Color.RGBtoHSB((color>>16)&0xff, (color>>8)&0xff, color&0xff, hsb); 
        hue = hsb[0]; 
        sat = hsb[1]; 
        bri = hsb[2]; 

        //apply changes based on threshold value 
        if ((hue+sat+bri)/3 < (int) (requiredThresholdValue)){ 
         sat = sat -(50); 
         bri = bri +100; 

         int rgb = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]); 
         r = ImageOperations.getRed(rgb); 
         g = ImageOperations.getGreen(rgb); 
         b = ImageOperations.getBlue(rgb); 
         finalThresholdImage.setRGB(x,y,ImageOperations.mixColor(r,g,b)); 
        } 
        else { 
         finalThresholdImage.setRGB(x,y,ImageOperations.mixColor(255, 255,255)); 
        } 


       } 
      } catch (Exception e) { 
       e.getMessage(); 
      } 
     } 

     return finalThresholdImage; 
    } 

    private static int mixColor(int r, int g, int b) { 
     return r<<16|g<<8|b; 
    } 

    public static int getRed(int rgb) { 
     return (rgb & 0x00ff0000) >> 16; 
    } 

    public static int getGreen(int rgb) { 
     return (rgb & 0x0000ff00) >> 8; 
    } 

    public static int getBlue(int rgb) { 
     return (rgb & 0x000000ff) >> 0; 

    } 

} 

, 거기에 아마 의미 론적 오류입니다,하지만 난 그것을 알아낼 수 없습니다 : 여기 내 코드입니다.

답변

0

먼저 수행 다음

sat = hsb[1]; 

:

sat = sat -(50); 

그런 : 당신이 기대하는 것처럼 당신이 토를 업데이트 할 때

int rgb = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]); 

거의 HSB [1] 업데이트 할 것 ? 결론 : do :

int rgb = Color.HSBtoRGB(hue, sat, bri); 
+0

감사합니다. – leonardo

+0

사실 다른 문제가 있습니다. 변화가 지금은 효과가 있지만 그들은 내가 기대했던 것이 아닙니다. "if"조건에서 임계 값보다 낮은 모든 픽셀의 채도를 떨어 뜨리겠다고 말하고 있지만 이미지의 모든 픽셀에 영향을 미치고 있으며, 실제로는 그 반대의 채도가 없습니다. 내 색상 공간 변환간에 문제가 있습니까? – leonardo

+0

단서가 아닙니다. HSB에 대해 처음 들어 본 적이 있습니다. – nablex