1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
public courbure(){
try {
File input = new File("d:/CC.JPG");
monImage = ImageIO.read(input);
int width = monImage.getWidth();
int height = monImage.getHeight();
BufferedImage outImg = new BufferedImage(width, height, monImage.getType());
for (int i = 1; i < width-1; i++) {
for (int j = 1; j < height-1; j++) {
float[] currenthsv = getHSB(monImage.getRGB(i,j));
float bo = currenthsv[0]*360;
float courb = 0f;
if (bo<32 || bo>224)
courb = Math.abs(getHSB(monImage.getRGB(i-1,j))[0]-getHSB(monImage.getRGB(i+1,j))[0]);
else if (bo>=32 || bo<96)
courb = Math.abs(getHSB(monImage.getRGB(i-1,j+1))[0]-getHSB(monImage.getRGB(i+1,j-1))[0]);
else if (bo>=96 || bo<160)
courb = Math.abs(getHSB(monImage.getRGB(i,j-1))[0]-getHSB(monImage.getRGB(i,j+1))[0]);
else if (bo>=160 || bo<224)
courb = Math.abs(getHSB(monImage.getRGB(i-1,j-1))[0]-getHSB(monImage.getRGB(i+1,j+1))[0]);
outImg.setRGB(i,j, Color.getHSBColor(courb, currenthsv[1], currenthsv[2]).getRGB());
}
}
File ouptut = new File("d:/courbure.jpg");
ImageIO.write(outImg, "jpg", ouptut);
}
catch (Exception e) {
e.printStackTrace();
}}
public float[] getHSB(int color)
{
float hsv[] = new float[3];
Color c = new Color(color);
Color.RGBtoHSB(c.getRed(),c.getGreen(),c.getBlue(), hsv);
return hsv;
}
static public void main(String args[]) throws Exception {
courbure obj = new courbure();
}
} |
Partager